Results 1 to 4 of 4

Thread: Convert c++ to vb.net

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    8

    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:
    1. Public Structure LPNET_DVR_DEVICEINFO
    2.  Public sSerialNumber() As Byte  'serial number
    3.         Public byAlarmInPortNum As Byte
    4.         Public byAlarmOutPortNum As Byte
    5.         Public byDiskNum As Byte        
    6.         Public byDVRType As Byte      
    7.         Public byChanNum As Byte    
    8.         Public byStartChan As Byte    
    9.     End Structure
    10.  
    11.   <DllImport("HCNetSDK.dll")> Public Function NET_DVR_Login( _
    12.    ByVal IPAddress() As Char, _
    13.    ByVal DVRPort As UInt16, _
    14.    ByVal UserName() As Char, _
    15.    ByVal Password() As Char, _
    16.    ByRef lpDeviceInfo As LPNET_DVR_DEVICEINFO) As <MarshalAs(I8)> Long
    17.     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.

  2. #2
    New Member
    Join Date
    Oct 2006
    Posts
    5

    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)

  3. #3
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    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?
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  4. #4

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    8

    Re: Convert c++ to vb.net

    Thanks everyone
    I find the soultion already.
    VB Code:
    1. <StructLayout(LayoutKind.Sequential)> _
    2.    Structure NET_DVR_DEVICEINFO
    3.         <MarshalAs(UnmanagedType.ByValArray, SizeConst:=48)> _
    4.         Dim sSerialNumber() As Byte
    5.         Dim byAlarmInPortNum As Byte
    6.         Dim byAlarmOutPortNum As Byte
    7.         Dim byDiskNum As Byte
    8.         Dim byDVRType As Byte
    9.         Dim byChanNum As Byte
    10.         Dim byStartChan As Byte
    11.     End Structure
    12.  
    13.  
    14.     <DllImport("HCNetSDK.dll", CharSet:=CharSet.Ansi)> _
    15.         Public Shared Function NET_DVR_Login(ByVal sDVRIP As String, _
    16.        ByVal wDVRPort As Short, ByVal sUserName As String _
    17.     , ByVal sPassword As String, ByRef deviceinfo As NET_DVR_DEVICEINFO) As Integer
    18.     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
  •  



Click Here to Expand Forum to Full Width