我在c#的实现方面遇到了困难,因为我是新手。问题是,我希望从c#代码中传递一个具有内存的“指针”,以便我的c++应用程序可以将pchListSoftwares缓冲区复制到pchInstalledSoftwares上。我无法弄清楚如何从c#端传递指针。
本地c++代码(MyNativeC++DLL.dll)
void GetInstalledSoftwares(char* pchInstalledSoftwares){
char* pchListSoftwares = NULL;
.....
.....
pchListSoftwares = (char*) malloc(255);
/* code to fill pchListSoftwares buffer*/
memcpy(pchInstalledSoftwares, pchListSoftwares, 255);
free(pchListSoftwares );
}
简单的“字符串”传递不起作用...
C# 实现
[DllImport("MyNativeC++DLL.dll")]
private static extern int GetInstalledSoftwares(string pchInstalledSoftwares);
static void Main(string[] args)
{
.........
.........
string b = "";
GetInstalledSoftwares(0, b);
MessageBox.Show(b.ToString());
}
非常感谢您提供的任何帮助...