-->

VB.NET – Native VC++ DLL

15 2018

VC++ Data Type – VB.NET Implementation :

1. LPBYTE – ByRef results As Byte,
2. INT – ByVal a as Int32
3. DWORD – ByVal statusSize As Int32
4. LPDWORD – ByRef len As Long

Sample 1:

<DllImport(DLL_FILENAME, CallingConvention:=CallingConvention.Cdecl)> _
Public Shared Function Function1 _
(ByVal bool_valueAs Boolean,
ByRef longpointer_byte_valueAs Byte,
ByVal dword_valueAs Int32,
ByRef longpointer_dword_valueAs Int32) As Int32
End Function

Sample 2:

VC++

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
<Serializable()> Public Structure ErrorLog
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=2, ArraySubType:=UnmanagedType.U1)> _
Public Param1() As Byte ' 2 Byte
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=5, ArraySubType:=UnmanagedType.U1)> _
Public Param2() As Byte ' 5 Byte
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=8, ArraySubType:=UnmanagedType.U1)> _
Public Param3() As Byte ' 8 Byte
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=2, ArraySubType:=UnmanagedType.U1)> _
Public Param4() As Byte ' 2 Byte
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=22, ArraySubType:=UnmanagedType.U1)> _
Public Param5() As Byte ' 22 Byte
Public Param6 As Byte</code>

<MarshalAs(UnmanagedType.ByValArray, SizeConst:=28, ArraySubType:=UnmanagedType.U1)> _
Public dummy() As Byte ' 28 Byte
End Structure
typedef struct _fullLog {
ERRORLOG errLog[5];
} FULLLOG;

VB.NET

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
<Serializable()> Public Structure ReadData
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=512, ArraySubType:=UnmanagedType.AsAny)> _
Public Error_Log() As ErrorLog
End Structure

'EXTERN_C_DLL_EXPORT INT SampleAPI(FULLLOG *fullLog);
<DllImport(DLL_FILENAME, CallingConvention:=CallingConvention.Cdecl)> _
Public Shared Function SampleAPI(ByRef FullLog1 As ErrorLog, ByVal Length As UInt32, ByRef lpLen As UInt32, <MarshalAs(UnmanagedType.LPWStr)> Optional lpPathName As String = "") As Int32
End Function

Leave a Reply