使用VB.NET调用带有字符指针的非托管C DLL
我对如何正确调用非托管C DLL函数做了大量研究,该函数包含一个字符指针,可以作为字符串传递到VB.NET,但我仍然遇到访问冲突异常,代码如下使用VB.NET调用带有字符指针的非托管C DLL,c,vb.net,char,marshalling,C,Vb.net,Char,Marshalling,我对如何正确调用非托管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,
<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)
提前感谢。For
char*
的可能副本应该是LPStr
,因为它不是Unicode。
Public Declare Function Get_FileNameAt Lib "Sdk.dll" (Byref pointer As IntPtr, ByVal index As UInt32, ByVal name As StringBuilder, ByVal capacity As UInt32) As Integer
End Function
Dim StrName As StringBuilder = New StringBuilder(256)
'Dim pointer As IntPtr = IntPtr.Zero (IntPtr.Zero should pass directly because it's read-only)
Get_FileNameAt(IntPtr.Zero, 1, StrName, 256)
Public Declare Function Get_FileNameAt Lib "Sdk.dll" (Byref pointer As IntPtr, ByVal index As UInt32, ByVal name As StringBuilder, ByVal capacity As UInt32) As Integer
End Function
Dim StrName As StringBuilder = New StringBuilder(256)
'Dim pointer As IntPtr = IntPtr.Zero (IntPtr.Zero should pass directly because it's read-only)
Get_FileNameAt(IntPtr.Zero, 1, StrName, 256)