delphi的const/input和預設的沒有修飾, C++都是一樣的
delphi的var,對應C++那邊是指針, 調用方需要管理記憶體(負責配置設定記憶體及銷毀)
delphi的output , 對應c++那邊也是指針 , 如果是 C++調用Delphi DLL, 而Delphi有個形參是out修飾的話, C++調用方傳入的指針可以不需要初始化, 因為初始化已經在dll那邊完成了.
比如delphi的dll:
- function _PLCReadHoldingRegister(const RegNo: word; out Value: word): boolean; stdcall;
- begin
- Result := False;
- if not checkClient then
- exit;
- g_lock.Enter;
- try
- Result := g_client.ReadHoldingRegister(RegNo, Value);
- SendDebugFmt('_PLCReadHoldingRegister, regNr:%d,val:%d',[RegNo,Value]);
- finally
- g_lock.Leave;
- end;
C++那邊應該這樣定義
- typedef bool(__stdcall* _msrPLCReadHoldingRegister) (WORD,WORD&);
- ...
- WORD lvVal = 0;
- if (mRoutines->PLCReadHoldingRegister(30, lvVal)) {
- printf(lvVal ...);
- }
版權聲明:本文為部落客原創文章,未經部落客允許不得轉載。 https://blog.csdn.net/rocklee/article/details/72356555