|
-
Jan 18th, 2007, 04:52 AM
#1
Thread Starter
New Member
Convert c++ to vb.net
Hi,
I covert following code to vb.net
typedef struct {
BYTE sSerialNumber[SERIALNO_LEN];
BYTE byAlarmInPortNum;
BYTE byAlarmOutPortNum;
BYTE byDiskNum;
BYTE byDVRType;
BYTE byChanNum;
BYTE byStartChan;
}NET_DVR_DEVICEINFO, *LPNET_DVR_DEVICEINFO;
LONG NET_DVR_Login(char *sDVRIP,WORD wDVRPort,char *sUserName,char *sPassword,LPNET_DVR_DEVICEINFO lpDeviceInfo);
VB Code:
Public Structure LPNET_DVR_DEVICEINFO
Public sSerialNumber() As Byte 'serial number
Public byAlarmInPortNum As Byte
Public byAlarmOutPortNum As Byte
Public byDiskNum As Byte
Public byDVRType As Byte
Public byChanNum As Byte
Public byStartChan As Byte
End Structure
<DllImport("HCNetSDK.dll")> Public Function NET_DVR_Login( _
ByVal IPAddress() As Char, _
ByVal DVRPort As UInt16, _
ByVal UserName() As Char, _
ByVal Password() As Char, _
ByRef lpDeviceInfo As LPNET_DVR_DEVICEINFO) As <MarshalAs(I8)> Long
End Function
When i call this function, always got error "Object reference not set to an instance of an object".
Anyone can help me. Thank you.
-
Jan 19th, 2007, 02:26 PM
#2
New Member
Re: Object reference error
Which object are you getting the error on?
Most likely the error occurs when trying to assign a value to the "sSerialNumber()" variable.
When declaring arrays in Structures, you can't assign an initial size to the array. As in:
Code:
Public sSerialNumber(4) as Btye
Before assigning a value to the "aSerialNumber()" variable, try ReDim-ing it.
As in:
Code:
Public LDD As New LPNET_DVR_DEVICEINFO
ReDim LDD.sSerialNumber(4)
NET_DVR_Login(IPAdress, DVRPort, UserName, Password, LDD)
-
Jan 19th, 2007, 03:08 PM
#3
Re: Convert c++ to vb.net
I suspect the error may lie in the code where you are calling the function. Could you show it?
-
Jan 20th, 2007, 10:13 AM
#4
Thread Starter
New Member
Re: Convert c++ to vb.net
Thanks everyone
I find the soultion already.
VB Code:
<StructLayout(LayoutKind.Sequential)> _
Structure NET_DVR_DEVICEINFO
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=48)> _
Dim sSerialNumber() As Byte
Dim byAlarmInPortNum As Byte
Dim byAlarmOutPortNum As Byte
Dim byDiskNum As Byte
Dim byDVRType As Byte
Dim byChanNum As Byte
Dim byStartChan As Byte
End Structure
<DllImport("HCNetSDK.dll", CharSet:=CharSet.Ansi)> _
Public Shared Function NET_DVR_Login(ByVal sDVRIP As String, _
ByVal wDVRPort As Short, ByVal sUserName As String _
, ByVal sPassword As String, ByRef deviceinfo As NET_DVR_DEVICEINFO) As Integer
End Function
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|