当前位置: 代码迷 >> 综合 >> Delphi的参数修饰const/var/output 与C++的对应关系
  详细解决方案

Delphi的参数修饰const/var/output 与C++的对应关系

热度:52   发布时间:2023-12-15 20:11:50.0

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;
beginResult := False;if not checkClient thenexit;g_lock.Enter;tryResult := g_client.ReadHoldingRegister(RegNo, Value);SendDebugFmt('_PLCReadHoldingRegister, regNr:%d,val:%d',[RegNo,Value]);finallyg_lock.Leave;end;
end;

C++那边应该这样定义

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


  相关解决方案