【发布时间】:2014-02-03 11:27:17
【问题描述】:
我正在从我的 C# 程序调用 C++ dll。 DLL 由几个函数组成,除了这个之外,我可以调用其中的大部分函数。
C++函数如下:
__declspec(dllexport) uint8_t* myHash(const char *filename)
{
uint8_t *hash = (unsigned char*)malloc(72*sizeof(uint8_t));
//some processing on hash
return hash;
}
从上面的代码可以看出,hash函数存储了一个字符数组。我想在我的 C# 程序中接收值,但我做不到。
我的 C# 代码如下:
[DllImport("myHash.dll", CharSet = CharSet.Ansi)]
public static extern IntPtr myHash(string filename);
IntPtr ptr = myHash(fileA);
char[] result = new char[72];
Marshal.Copy(ptr, result, 0, 72);
【问题讨论】: