【发布时间】:2015-03-21 19:33:08
【问题描述】:
我已经对如何正确调用包含 char 指针的非托管 C DLL 函数进行了大量研究,以将其作为字符串传递给 VB.NET,但我仍然遇到以下代码的访问冲突异常
<DllImport("Sdk.dll")> _
Public Function Get_FileNameAt(ByVal pointer As IntPtr, ByVal index As UInt32, <MarshalAs(UnmanagedType.LPWStr)> ByVal name As StringBuilder, ByVal capacity As UInt32) As Integer
End Function
Dim StrName As New StringBuilder(256)
Dim pointer As IntPtr = IntPtr.Zero
Get_FileNameAt(pointer, 1, StrName, 256)
我尝试过使用和不使用 Pinvoke
C 函数声明
GoSensor_FileNameAt(void* pointer, unsigned __int32 index, char* name, unsigned __int32 capacity);
提前致谢。
【问题讨论】:
-
对于
char*,它应该是LPStr,因为它不是Unicode。
标签: c vb.net char marshalling