-->

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:

'EXTERN_C_DLL_EXPORT INT Function1(BOOL bool_value, LPBYTE longpointer_byte_value, DWORD dword_value, LPDWORD longpointer_dword_value);
<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 ucErrorID() As Byte ‘ 2 Byte
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=5, ArraySubType:=UnmanagedType.U1)> _
Public ucTime() As Byte ‘ 5 Byte
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=8, ArraySubType:=UnmanagedType.U1)> _
Public ucErrorCode() As Byte ‘ 8 Byte
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=2, ArraySubType:=UnmanagedType.U1)> _
Public ucStatusSts() As Byte ‘ 2 Byte
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=22, ArraySubType:=UnmanagedType.U1)> _
Public ucSensorSts() As Byte ‘ 22 Byte
Public ucCmdNo As Byte

<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 fulllog
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=512, ArraySubType:=UnmanagedType.AsAny)> _
Public Error_Log() As ErrorLog
End Structure

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

 

Leave a Reply