4
是否可以使用P-Invoke將託管C#中的字符串數組傳遞給非託管函數?將託管C#中的字符串數組傳遞給使用P-Invoke的非託管函數
這工作得很好:
[DllImport("LibraryName.dll")]
private static extern void Function_Name(string message);
這枚:
[DllImport("LibraryName.dll")]
private static extern void Function_Name(string[] message);
失敗
未處理的異常:System.NotSupportedException:NotSupportedException異常
我已經嘗試使用MarshalAs
沒有運氣([MarshalAs(UnmanagedType.LPArray, ArraySubType=UnmanagedType.LPWStr)] String[] dataToLoadArr)
是否有可能通過這種方式傳遞字符串數組?
異常信息是什麼?另外,非託管函數的聲明是什麼? – casperOne
是[this](http://www.dotnetmonster.com/Uwe/Forum.aspx/dotnet-csharp/15480/P-Invoke-and-string-array)有幫助嗎? – mtijn
謝謝,mtijn,幫助。通過使用表示要編組的字符串的IntPtr結構來解決。 – Luuseens