I'm trying to do some DHCP enumerations in VB6.  I'm trying to do a DhcpEnumSubnets call as per MSDN:

I'm apparently having problems porting this over to VB.  Currently with the code below I get bad DLL calling convention.
Any ideas where I'm going wrong?

Here's my code:

Public Const NERR_Success = 0&
Public Const NERR_Access_Denied = 5&
Public Const NERR_MoreData = 234&

Public Declare Sub CopyMem Lib "kernel32" Alias "RtlMoveMemory" _
        (pTo As Any, _
         uFrom As Any, _
         ByVal lSize As Long)
'  DHCP_CONST WCHAR* ServerIpAddress,
'  DHCP_RESUME_HANDLE* ResumeHandle,
'  DWORD PreferredMaximum,
'  DWORD* ElementsRead,
'  DWORD* ElementsTotal

Declare Function DhcpEnumSubnets Lib "dhcpsapi" _
      (ServerIP As Any, lpResumeHandle As Long, _
      ByVal prefmaxlen As Long, Enuminfo As Long, _
      EntriesRead As Long, TotalEntries As Long)

'typedef struct _DHCP_IP_ARRAY { _
'DWORD NumElements; _


   NumElements As Long
   IPaddress As Long
End Type

Public Function DHCPEnum(Server As String)
   Dim yServer() As Byte, lRetCode As Long
   Dim nRead As Long, nTotal As Long
   Dim nret As Long, nResume As Long
   Dim prefmaxlen As Long
   Dim i As Long, x As Long
   Dim lDHCPInfo As Long
   Dim lDHCPInfoPtr As Long
   yServer = MakeServerName(ByVal Server)
   prefmaxlen = 65536
   nResume = 0

   nret = NERR_MoreData
   Do While (nret = NERR_MoreData)

      nret = DhcpEnumSubnets(yServer(0), nResume, prefmaxlen, _
                      lDHCPInfo, nRead, nTotal)

      If (nret <> NERR_Success And _
       nret <> NERR_MoreData) Then
         'NetError nret
         Debug.Print "Error:" & nret
         Exit Do
      End If

      lDHCPInfoPtr = lDHCPInfo
      Do While x <= nRead
         CopyMem DHCPInfo, ByVal lDHCPInfoPtr, Len(DHCPInfo)
         Debug.Print DHCPInfo.NumElements
         Debug.Print DHCPInfo.IPaddress
         lDHCPInfoPtr = lDHCPInfoPtr + Len(DHCPInfo)
End Function

Public Function MakeServerName(ByVal ServerName As String)
    Dim yServer() As Byte
    If ServerName <> "" Then
        If InStr(1, ServerName, "\\") = 0 Then
            ServerName = "\\" & ServerName
        End If
    End If
    yServer = ServerName & vbNullChar
    MakeServerName = yServer

End Function
LVL 27
PberSolutions ArchitectAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Richie_SimonettiIT OperationsCommented:
PberSolutions ArchitectAuthor Commented:
Do you know what I'm doing wrong converting the API for VB?
Richie_SimonettiIT OperationsCommented:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.