如何从C#应用程序调用带有指向void的指针的C ++函数? [英] How to call from a C# applicaiton a C++ function taking a pointer to void?
本文介绍了如何从C#应用程序调用带有指向void的指针的C ++函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个用C ++编写的动态库( .dll
),导出了我想在我的C#应用程序中使用的函数:
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?
推荐答案
对于无效*
,您只需使用 IntPtr
,
字符串将与 MarshalAs
属性一起使用:
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);
这篇关于如何从C#应用程序调用带有指向void的指针的C ++函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文