How to call from a C# applicaiton a C++ function taking a pointer to void?

痴心易碎 提交于 2019-12-07 06:42:58

问题


I have a dynamic library (.dll) written in C++ exporting a function I'd like to use in my C# applicaiton:

int SendText(void* pControl, char* sText);

How can I, given it takes a pointer to void?


回答1:


for void* you can just use IntPtr ,
strings will work with the MarshalAs attribute:

[DllImport("MyDll.dll", CharSet = CharSet.Ansi)]
public static extern int SendText(IntPtr pControl, [MarshalAs(UnmanagedType.LPStr)] string sText);


来源:https://stackoverflow.com/questions/10630419/how-to-call-from-a-c-sharp-applicaiton-a-c-function-taking-a-pointer-to-void

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