天天看點

Delphi的參數修飾const/var/output 與C++的對應關系

delphi的const/input和預設的沒有修飾, C++都是一樣的

delphi的var,對應C++那邊是指針,  調用方需要管理記憶體(負責配置設定記憶體及銷毀)

        delphi的output , 對應c++那邊也是指針 , 如果是 C++調用Delphi DLL, 而Delphi有個形參是out修飾的話, C++調用方傳入的指針可以不需要初始化, 因為初始化已經在dll那邊完成了. 

       比如delphi的dll:

  1. function _PLCReadHoldingRegister(const RegNo: word; out Value: word): boolean; stdcall;
  2. begin
  3. Result := False;
  4. if not checkClient then
  5. exit;
  6. g_lock.Enter;
  7. try
  8. Result := g_client.ReadHoldingRegister(RegNo, Value);
  9. SendDebugFmt('_PLCReadHoldingRegister, regNr:%d,val:%d',[RegNo,Value]);
  10. finally
  11. g_lock.Leave;
  12. end;

C++那邊應該這樣定義

  1. typedef bool(__stdcall* _msrPLCReadHoldingRegister) (WORD,WORD&);
  2. ...
  3. WORD lvVal = 0;
  4. if (mRoutines->PLCReadHoldingRegister(30, lvVal)) {
  5. printf(lvVal ...);
  6. }

版權聲明:本文為部落客原創文章,未經部落客允許不得轉載。 https://blog.csdn.net/rocklee/article/details/72356555