Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用VB.NET调用带有字符指针的非托管C DLL_C_Vb.net_Char_Marshalling - Fatal编程技术网

使用VB.NET调用带有字符指针的非托管C DLL

使用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,

我对如何正确调用非托管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)

提前感谢。

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)