我被困在c#实现端,因为我对它很新颖。问题是,我想从c#代码传递一个'指针'(有内存),这样My C++应用程序就可以将pchListSoftwares缓冲区复制到pchInstalledSoftwares。我无法弄清楚如何从C#端传递指针。将C#中的字符指针传递给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());
}
任何形式的帮助非常感谢...
干得好(计算出来) – 2010-12-08 16:28:29