C/C++ 端的函數指標為 :
typedef void (* pCBFunc)(int, char**);
對應的 C# 端的函數為 :
public static void callback(int nArrsz, IntPtr pStringArray)
{
string[] data = new string[nArrsz];
IntPtr tmpPtr = pStringArray;
for (int i = 0; i < nArrsz; ++i)
{
IntPtr strPtr =
(IntPtr)Marshal.PtrToStructure(tmpPtr, typeof(IntPtr));
data[i] = Marshal.PtrToStringAuto(strPtr);
tmpPtr = new IntPtr(tmpPtr.ToInt64() + IntPtr.Size);
}
}
其中的 int nArrsz 為字串數目,IntPtr pStringArray 為字串陣列 ( 對應至 C 的 char** ) ,string[] data 是轉型後的資料。
0 意見 :
張貼留言