error with decalre function
-
Hello. I was successfully able to convert VB6 to VB.Net, however I get an error when calling a declare function. Part of the code looks like this:
Declare Function iRasEnumDevices Lib "rasapi32.dll" Alias "RasEnumDevicesA" (ByRef lpRasDevInfo As Integer, ByRef lpcb As Integer, ByRef lpcDevices As Integer) As Integer Declare Sub iCopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByRef hpvDest As Integer, ByRef hpvSource As RASDEVINFO, ByVal cbCopy As Integer) Declare Sub iCopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByRef hpvSource As RASDEVINFO, ByRef hpvDest As Integer, ByVal cbCopy As Integer) Public Structure RASIPADDR Dim a As Byte Dim b As Byte Dim c As Byte Dim d As Byte End Structure Dim lpRasDevInfo As New RASDEVINFO Dim lpcb As Integer = 0 Dim cDevices As Integer Dim t_Buff As Integer Dim nRet As Integer Dim t_ptr As Integer Dim i As Integer lpcb = 0 lpRasDevInfo.Initialize() lpRasDevInfo.dwSize = Len(lpRasDevInfo) + (Len(lpRasDevInfo) Mod 4) nRet = iRasEnumDevices(0, lpcb, cDevices) t_Buff = GlobalAlloc(GPTR, lpcb) iCopyMemory(t_Buff, lpRasDevInfo, Len(lpRasDevInfo)) nRet = iRasEnumDevices(t_Buff, lpcb, lpcb)
I get an error on the linenRet = iRasEnumDevices(t_Buff, lpcb, lpcb)
that says: "Object reference not set to an instance of an object". I ran the debugger and the only thing that gets set to Nothing is the parameter I pass in ByRef. I'm not really sure what is going on, but does anyone have an idea? Mike - I love to program! -
Hello. I was successfully able to convert VB6 to VB.Net, however I get an error when calling a declare function. Part of the code looks like this:
Declare Function iRasEnumDevices Lib "rasapi32.dll" Alias "RasEnumDevicesA" (ByRef lpRasDevInfo As Integer, ByRef lpcb As Integer, ByRef lpcDevices As Integer) As Integer Declare Sub iCopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByRef hpvDest As Integer, ByRef hpvSource As RASDEVINFO, ByVal cbCopy As Integer) Declare Sub iCopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByRef hpvSource As RASDEVINFO, ByRef hpvDest As Integer, ByVal cbCopy As Integer) Public Structure RASIPADDR Dim a As Byte Dim b As Byte Dim c As Byte Dim d As Byte End Structure Dim lpRasDevInfo As New RASDEVINFO Dim lpcb As Integer = 0 Dim cDevices As Integer Dim t_Buff As Integer Dim nRet As Integer Dim t_ptr As Integer Dim i As Integer lpcb = 0 lpRasDevInfo.Initialize() lpRasDevInfo.dwSize = Len(lpRasDevInfo) + (Len(lpRasDevInfo) Mod 4) nRet = iRasEnumDevices(0, lpcb, cDevices) t_Buff = GlobalAlloc(GPTR, lpcb) iCopyMemory(t_Buff, lpRasDevInfo, Len(lpRasDevInfo)) nRet = iRasEnumDevices(t_Buff, lpcb, lpcb)
I get an error on the linenRet = iRasEnumDevices(t_Buff, lpcb, lpcb)
that says: "Object reference not set to an instance of an object". I ran the debugger and the only thing that gets set to Nothing is the parameter I pass in ByRef. I'm not really sure what is going on, but does anyone have an idea? Mike - I love to program!Mike, I don't see your RASDEVINFO Stucture it should, at a minimum, look like this: Public Structure RASDEVINFO Dim dwSize As Long _ Dim szDeviceType() As Byte _ Dim szDeviceName() As Byte End Structure If you still have a problem with it, convert the stucture to a class structure, as you cannot pass a null value in VB.Net in a structure. Also you need to do a lot more marshaling of most of that code. There is an aritcle here on that, that may help you. http://www.codeproject.com/vb/net/netcopymemorysample.asp If you need anymore help feel free to email me and I'll see if I can help you work it out. progload