Passing pointer from managed C++/CLI to ActiveX C++ component

一笑奈何 提交于 2019-12-08 20:58:26

The function signature is not valid for ActiveX automation, arrays must be passed as a SAFEARRAY. As is, the function cannot be called by any code other than native C/C++. The type library converter has the same problem, the function signature is identical to one where the argument is passed by reference. It has no way to guess that it is actually an array. Which is why you got the short% type.

If you can't change the native component then you will have to edit the interop library that's generated by Tlbimp.exe. That requires running ildasm.exe to decompile the DLL to IL. Edit the IL declaration of the function. Put humpty-dumpty back together with ilasm.exe. Look at the disassembly of a little test function that has the signature you need to know how to edit the IL. You'll need to pass the argument as an IntPtr and pass the pinned array. Use pin_ptr<> to get that pointer.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!