C
caviar
I'm trying to read in a ref parameter from a native dll, its working in vb
if i use the kernel32 functions below transforming the ref param to a vb
string:
Now, i want to skip this vb dll and use the native dll directly from c#
[DllImport("pafutw32.dll")] // CharSet = CharSet.Auto, CallingConvention
=CallingConvention.StdCall )]
public static extern short PAF_GetRecord(short listndx, short recno,
[MarshalAs(UnmanagedType.LPWStr)]ref string pafrec, ref short pafreclen );
But whatever i try i cant read this ref string pafrec out, it will keep
empty or it has the length but it doenst show anything.. So, the thrick
should be in the MultiByteToWidechar and MultiByteToUnicode function..
So does anyone have an idea how to declare the DLLImport statement so it
will succesfully Marshall this _ref string pafrec_, which seems to be a
MultiByte string.
Regards h
************original c from the .h file
PREFIX short PASFIX PAF_GetRecord(short listndx, long recno,char *pafrec,
short pafreclen );
********* the vb helper functions.
Private Declare Function MultiByteToWideChar Lib "kernel32" (ByVal CodePage
As Long, ByVal dwFlags As Long, ByVal lpMultiByteStr As Long, ByVal
cchMultiByte As Long, ByVal lpWideCharStr As Long, ByVal cchWideChar As
Long) As Long
Public Function MultiByteToUnicode(st As String, cpg As Long) As Variant
Dim stBuffer As String
Dim cwch As Long
Dim pwz As Long
Dim pwzBuffer As Long
Dim pwzBufferSize As Long
Dim b() As Byte
b = StrConv(st, vbFromUnicode)
pwz = VarPtr(b(0))
cwch = MultiByteToWideChar(cpg, 0, pwz, -1, ByVal 0&, ByVal 0&)
pwzBufferSize = cwch
stBuffer = String(pwzBufferSize, " ")
pwzBuffer = StrPtr(stBuffer)
cwch = MultiByteToWideChar(cpg, 0, pwz, -1, pwzBuffer,
pwzBufferSize)
MultiByteToUnicode = Left(stBuffer, cwch - 1)
End Function
if i use the kernel32 functions below transforming the ref param to a vb
string:
Now, i want to skip this vb dll and use the native dll directly from c#
[DllImport("pafutw32.dll")] // CharSet = CharSet.Auto, CallingConvention
=CallingConvention.StdCall )]
public static extern short PAF_GetRecord(short listndx, short recno,
[MarshalAs(UnmanagedType.LPWStr)]ref string pafrec, ref short pafreclen );
But whatever i try i cant read this ref string pafrec out, it will keep
empty or it has the length but it doenst show anything.. So, the thrick
should be in the MultiByteToWidechar and MultiByteToUnicode function..
So does anyone have an idea how to declare the DLLImport statement so it
will succesfully Marshall this _ref string pafrec_, which seems to be a
MultiByte string.
Regards h
************original c from the .h file
PREFIX short PASFIX PAF_GetRecord(short listndx, long recno,char *pafrec,
short pafreclen );
********* the vb helper functions.
Private Declare Function MultiByteToWideChar Lib "kernel32" (ByVal CodePage
As Long, ByVal dwFlags As Long, ByVal lpMultiByteStr As Long, ByVal
cchMultiByte As Long, ByVal lpWideCharStr As Long, ByVal cchWideChar As
Long) As Long
Public Function MultiByteToUnicode(st As String, cpg As Long) As Variant
Dim stBuffer As String
Dim cwch As Long
Dim pwz As Long
Dim pwzBuffer As Long
Dim pwzBufferSize As Long
Dim b() As Byte
b = StrConv(st, vbFromUnicode)
pwz = VarPtr(b(0))
cwch = MultiByteToWideChar(cpg, 0, pwz, -1, ByVal 0&, ByVal 0&)
pwzBufferSize = cwch
stBuffer = String(pwzBufferSize, " ")
pwzBuffer = StrPtr(stBuffer)
cwch = MultiByteToWideChar(cpg, 0, pwz, -1, pwzBuffer,
pwzBufferSize)
MultiByteToUnicode = Left(stBuffer, cwch - 1)
End Function