T
Trisax via DotNetMonster.com
Hi
I want to import this function in my VB.Net program
Original C++ Function:
SetFilter(WORD pid,void* lpFunc, DWORD CallBackType, DWORD size, DWORD *lpfilter_num)
this function generates the follow Callback:
void __stdcall YourCallBack(BYTE *Buff, int lenBuff)
My code:
Public Delegate Function myCallBack(ByVal Buffer As String, ByVal size As Integer) As Boolean
<DllImport("mydll", EntryPoint:="SetFilter", _
SetLastError:=True, CharSet:=CharSet.Unicode, _
ExactSpelling:=True, _
CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function SetFilter(ByVal pid As Integer, ByVal lpFunc As myCallBack, ByVal CallBackType As Integer, ByVal size As Integer, ByVal lpfilter_num As Long) As Boolean
End Function
The function works but the Buffer retrieved from MyCallBack is incorrect and the lenght doesn't match to it
I have tried also to insert this structure:
<StructLayout(LayoutKind.Sequential)> _
Public Structure MyPoint
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=2)> Public buff() As Byte
'Public x As String
End Structure 'MyPoint
but after few seconds crashes maybe i have to use a GCHandle but I do't know how
I want to import this function in my VB.Net program
Original C++ Function:
SetFilter(WORD pid,void* lpFunc, DWORD CallBackType, DWORD size, DWORD *lpfilter_num)
this function generates the follow Callback:
void __stdcall YourCallBack(BYTE *Buff, int lenBuff)
My code:
Public Delegate Function myCallBack(ByVal Buffer As String, ByVal size As Integer) As Boolean
<DllImport("mydll", EntryPoint:="SetFilter", _
SetLastError:=True, CharSet:=CharSet.Unicode, _
ExactSpelling:=True, _
CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function SetFilter(ByVal pid As Integer, ByVal lpFunc As myCallBack, ByVal CallBackType As Integer, ByVal size As Integer, ByVal lpfilter_num As Long) As Boolean
End Function
The function works but the Buffer retrieved from MyCallBack is incorrect and the lenght doesn't match to it
I have tried also to insert this structure:
<StructLayout(LayoutKind.Sequential)> _
Public Structure MyPoint
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=2)> Public buff() As Byte
'Public x As String
End Structure 'MyPoint
but after few seconds crashes maybe i have to use a GCHandle but I do't know how