如果在c#代码

时间:2018-01-27 10:40:09

标签: c# c++ dll

我正在调用C#dll中定义的以下函数:

public class Master:IMaster
{
...
public void WriteSingleCoils(ushort id, byte unit, ushort startAddress, bool OnOff, ref byte[] result)
{
byte[] data;
data = CreateWriteHeader(id, unit, startAddress, 1, 1, fctWriteSingleCoil);
if (OnOff == true) data[10] = 255;
else data[10] = 0;
result = WriteSyncData(data, id);
}
...
}

来自以下c ++应用程序代码:

pIMast = new IMasterPtr(__uuidof(Master));
unsigned char* ptr = 0;
pIMast->WriteSingleCoils(1, 0, 144, true, (SAFEARRAY**)ptr);

dll以及应用程序编译正常。但是应用程序运行不正常。我只关心最后一个参数ref byte[] result。我正确地称它为好吗?如果在c#代码中定义为ref param,如何传递数组变量?

1 个答案:

答案 0 :(得分:0)

我会尝试将PTR作为C ++中的参考传递

sin_time_seconds
  

https://www.ibm.com/support/knowledgecenter/en/SSLTBW_2.3.0/com.ibm.zos.v2r3.cbclx01/cplr233.htm

希望这有帮助