Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. error with decalre function

error with decalre function

Scheduled Pinned Locked Moved Visual Basic
questioncsharpdebugginghelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    allenmpcx
    wrote on last edited by
    #1

    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 line nRet = 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!

    P 1 Reply Last reply
    0
    • A allenmpcx

      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 line nRet = 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!

      P Offline
      P Offline
      progload
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups