【发布时间】:2011-05-22 02:38:21
【问题描述】:
我被困在 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());
}
非常感谢任何形式的帮助...
【问题讨论】: