• Welcome to Theos PowerBasic Museum 2017.

News:

Attachments are only available to registered users.
Please register using your full, real name.

Main Menu

VARPTR function ... how to use ???

Started by Guy Fournier, November 02, 2012, 02:09:11 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Guy Fournier

Hi,

I'm not familiar with varptr with type/end type, someone have the kindness to explain how to print the result of that structure ? I never had to use this function before, sorry for that question but I would like to understand how to do that !

Thank you for your answer.

Guy

ex:
EnumDhcpServers.Version
EnumDhcpServers.ServerName
etc...


#COMPILE EXE
#DIM ALL

#INCLUDE "f:\dns\dhcpsapi.inc"
FUNCTION PBMAIN () AS LONG

' // Serie = 28 bytes
'TYPE DHCPDS_SERVER DWORD
'   Version       AS DWORD          ' DWORD // version of this structure -- currently zero
'   ServerName    AS WSTRINGZ PTR   ' LPWSTR // [DNS?] unique name for server
'   ServerAddress AS DWORD          ' DWORD // ip address of server
'   Flags         AS DWORD          ' DWORD // additional info -- state
'   State         AS DWORD          ' DWORD // not used ...
'   DsLocation    AS WSTRINGZ PTR   ' LPWSTR // ADsPath to server object
'   DsLocType     AS DWORD          ' DWORD // path relative? absolute? diff srvr?
'END TYPE

'MACRO DHCP_SERVER_INFO = DHCPDS_SERVER

' // Serie = 12 bytes
'TYPE DHCPDS_SERVERS DWORD
'   Flags       AS DWORD               ' DWORD // not used currently.
'   NumElements AS DWORD               '  DWORD // # of elements in array
'   Servers     AS DHCPDS_SERVER PTR   ' LPDHCPDS_SERVER // array of server info
'END TYPE

'MACRO DHCP_SERVER_INFO_ARRAY = DHCPDS_SERVERS

'//DOC DhcpEnumServers enumerates the list of servers found in the DS.  If the DS
'//DOC is not accessible, it returns an error. The only currently used parameter
'//DOC is the out parameter Servers.  This is a SLOW call.
'DECLARE FUNCTION DhcpEnumServers IMPORT "Dhcpsapi.dll" ALIAS "DhcpEnumServers" ( _
'   BYVAL Flags AS DWORD _                               ' __in  DWORD Flags // must be zero
' , BYVAL IdInfo AS DWORD _                              ' __in  LPVOID IdInfo // must be NULL
' , BYREF Servers AS DHCP_SERVER_INFO_ARRAY _            ' __out LPDHCP_SERVER_INFO_ARRAY *Servers // output servers list
' , BYVAL CallbackFn AS DWORD _                          ' __in  LPVOID CallbackFn // must be NULL
' , BYVAL CallbackData AS DWORD _                        ' __in  LPVOID CallbackData // must be NULL
' ) AS DWORD                                             ' DWORD


DIM EnumDhcpServers AS DHCP_SERVER_INFO_ARRAY
LOCAL nresult, nr AS DWORD
nr=0

nresult = DhcpEnumServers(nr,nr, EnumDhcpServers,nr,nr)

MSGBOX  "nresult " + STR$(nresult)

END FUNCTION


José Roca

It must be something like


FOR i = 0 TO EnumDhcpServers.NumElements - 1
   ? EnumDhcpServers.@Servers[i].@ServerName
NEXT


Guy Fournier

#2
Hi José,

I test many things ... I understand the structure, but I'm sorry I dont understand the pointers. I used your code and I'm not lucky ....

I tried with DhcpEnumSubnetClients it's the same logical but now I see nrusult = 0 and the ClientInfo.NumElements = 9580192 after that general fault with pb10.

Rainy day = bad day ! I continue the work

Thank you for your help


#COMPILE EXE
#DIM ALL

#INCLUDE "d:\dns\dhcpsapi.inc"

FUNCTION PBMAIN () AS LONG

'   DECLARE FUNCTION DhcpEnumSubnetClients IMPORT "Dhcpsapi.dll" ALIAS "DhcpEnumSubnetClients" ( _
'   BYREF ServerIpAddress AS WSTRINGZ _                  ' __in DHCP_CONST WCHAR *ServerIpAddress
' , BYVAL SubnetAddress AS DWORD _                       ' __in DHCP_IP_ADDRESS SubnetAddress
' , BYREF ResumeHandle AS DWORD _                        ' __in_out DHCP_RESUME_HANDLE *ResumeHandle
' , BYVAL PreferredMaximum AS DWORD _                    ' __in DWORD PreferredMaximum
' , BYREF ClientInfo AS DHCP_CLIENT_INFO_ARRAY _         ' __out LPDHCP_CLIENT_INFO_ARRAY *ClientInfo
' , BYREF ClientsRead AS DWORD _                         ' __out DWORD *ClientsRead
' , BYREF ClientsTotal AS DWORD _                        ' __out DWORD *ClientsTotal
' ) AS DWORD                                             ' DWORD

LOCAL ServerIpAddress AS STRINGZ * 64
LOCAL SubnetAddress AS DWORD
LOCAL ResumeHandle AS DWORD
LOCAL PreferredMaximum AS DWORD
LOCAL ClientInfo AS DHCP_CLIENT_INFO_ARRAY
LOCAL ClientsRead AS DWORD
LOCAL ClientsTotal AS DWORD
LOCAL nresult  AS DWORD
LOCAL i AS DWORD

SubnetAddress = &H0a349400 '10.52.148.0 vlan
ResumeHandle=0
ClientsRead=0
ClientsTotal=0

nresult=DhcpEnumSubnetClients("10.52.45.125",SubnetAddress,ResumeHandle,65536, ClientInfo,ClientsRead,ClientsTotal)

MSGBOX  "nresult " + STR$(nresult) + ": " + STR$(ClientInfo.NumElements)

FOR i = 0 TO ClientInfo.NumElements  - 1
   MSGBOX [email]ClientInfo.@Clients[i].@ClientName[/i][/email]   
[i]NEXT


END FUNCTION       [/i]