Passing char pointer from C# to c++ function

时光怂恿深爱的人放手 提交于 2019-11-29 14:55:41

Try using a StringBuilder

[DllImport("MyNativeC++DLL.dll")]
private static extern int GetInstalledSoftwares(StringBuilder pchInstalledSoftwares);


static void Main(string[] args)
{
.........
.........
        StringBuilder b = new StringBuilder(255);
        GetInstalledSoftwares(0, b);
        MessageBox.Show(b.ToString());
}
Supernova009

My mistake... remove 0 in call to GetInstalledSoftwares(0, b);.

Try to change the prototype line to:

private static extern int GetInstalledSoftwares(ref string pchInstalledSoftwares); 

(Send the string by reference).

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