Problème de déclaration pour un Call API (DHCPRequestParams)

yvansautin Messages postés 1 Date d'inscription mardi 9 mai 2006 Statut Membre Dernière intervention 17 juin 2008 - 17 juin 2008 à 15:03
NHenry Messages postés 15114 Date d'inscription vendredi 14 mars 2003 Statut Modérateur Dernière intervention 4 mai 2024 - 17 juin 2008 à 15:30
Bonjour,

J'essaie de récupérer le nom du serveur TFTP (PXEBoot server name option 66) du DHCP serveur en utilisant l'API DHCPRequestParams de la DLL DHCPCSVC.dll.
Quelqu'un pourrait il m'aider car je n'arrive pas à écrire la déclaration correcte du call, je reçois l'erreur Runtime 49 "Bad DLL Calling convention"
Merci d'avance
Yvan
Ci-dessous le Code VB ainsi qu'en commentaires les déclarations en C et l'adresse URL de l'exemple en C

************* Start Code *****************
Option Explicit

'************* Start of C Declarations ************
'typedef struct _DHCPAPI_CLASSID {
' ULONG Flags;
' LPBYTE Data;
' ULONG nBytesData;
'} DHCPCAPI_CLASSID, *PDHCPCAPI_CLASSID, *LPDHCPCAPI_CLASSID;
' Members
'flags Reserved. Must be set to zero.
'data Class ID binary data.
'nBytesData Size of Data, in bytes.

'typedef struct _DHCPAPI_PARAMS {
' ULONG Flags;
' ULONG OptionId;
' BOOL IsVendor;
' LPBYTE Data;
' DWORD nBytesData;
'} DHCPAPI_PARAMS, DHCPCAPI_PARAMS, *PDHCPAPI_PARAMS, *LPDHCPAPI_PARAMS, *PDHCPCAPI_PARAMS, *LPDHCPCAPI_PARAMS;
'Members
'flags Reserved. Must be set to zero.
'optionid Identifier for the DHCP parameter being requested.
'isvendor Specifies whether the DHCP parameter is vendor-specific. Set to TRUE if the parameter is vendor-specific.
'data Pointer to the parameter data.
'nBytesData Size of the data pointed to by Data, in bytes.

'typedef struct _DHCPCAPI_PARAMS_ARRAY {
' ULONG nParams;
' LPDHCPAPI_PARAMS Params;
'} DHCPCAPI_PARAMS_ARRAY, *PDHCPCAPI_PARAMS_ARRAY, *LPDHCPCAPI_PARAMS_ARRAY;
'Members
'nParams Number of elements in the Params array.
'params Array of DHCPAPI_PARAMS structures.

'DWORD APIENTRY DhcpRequestParams(
' __in DWORD Flags,
' __in LPVOID Reserved,
' __in LPWSTR AdapterName,
' __in LPDHCPCAPI_CLASSID ClassId,
' __in DHCPCAPI_PARAMS_ARRAY SendParams,
' __inout DHCPCAPI_PARAMS_ARRAY RecdParams,
' __in LPBYTE Buffer,
' __inout LPDWORD pSize,
' __in LPWSTR RequestIdStr
');
'Parameters
'flags Flags that specify the data being requested. Must be set to DHCPCAPI_REQUEST_SYNCHRONOUS, and may optionally be set with the additional DHCPCAPI_REQUEST_PERSISTENT flag. This parameter is optional.
'Reserved Reserved for future use. Must be set to NULL.
'AdapterName Name of the adapter on which requested data is being made. Must be under 256 characters.
'ClassId Class identifier (ID) that should be used if DHCP INFORM messages are being transmitted onto the network. This parameter is optional.
'sendParams Optional data to be requested, in addition to the data requested in the RecdParams array. The SendParams parameter cannot contain any of the standard options that the DHCP client sends by default.
'RecdParams Array of DHCP data the caller is interested in receiving. This array must be empty prior to the DhcpRequestParams function call.
'buffer Buffer used for storing the data associated with requests made in RecdParams.
'pSize Size of Buffer. Required size of the buffer, if it is insufficiently sized to hold the data, otherwise indicates size of the buffer which was successfully filled.
'RequestIdStr Application identifier (ID) used to facilitate a persistent request. Must be a printable string with no special characters (commas, backslashes, colons, or other illegal characters may not be used). The specified application identifier (ID) is used in a subsequent DhcpUndoRequestParams function call to clear the persistent request, as necessary.
'Return Value Returns ERROR_SUCCESS upon successful completion.
'ex: http://msdn.microsoft.com/en-us/library/aa363345(VS.85).aspx

'*********** End of C Declarations *************************


Public Const OPTION_TFTPSERVERNAME = 66
Public Const DHCPCAPI_REQUEST_SYNCHRONOUS = &H2



Public Type DHCPAPI_PARAMS
flags As Long
optionid As Long
isvendor As Boolean
data As Byte
nbytes As Long
End Type



Public Type DHCPCAPI_CLASSID
flags As Long
data As Byte
nbytes As Long
End Type



Public Type DHCPCAPI_PARAMS_ARRAY
nParams As Long
params As DHCPAPI_PARAMS
End Type



Declare Function DhcpRequestParams Lib "dhcpcsvc.dll" ( _
ByVal flags As Long, _
Reserved As Any, _
ByVal AdapterName As Long, _
ByRef ClassId As DHCPCAPI_CLASSID, _
ByRef sendParams As DHCPCAPI_PARAMS_ARRAY, _
ByRef RecdParams As DHCPCAPI_PARAMS_ARRAY, _
ByVal buffer As String, _
ByRef pSize As Long, _
ByVal RequestIdStr As Long) As Long



Sub Main()



Dim dClsId As DHCPCAPI_CLASSID
Dim recParams As DHCPAPI_PARAMS
Dim sendParams As DHCPAPI_PARAMS
Dim sendParamsArray As DHCPCAPI_PARAMS_ARRAY
Dim recParamsArray As DHCPCAPI_PARAMS_ARRAY
Dim RetCode As Long
Dim sBuffer As String
Dim sMyNic As String
Dim sRequestId As String

'ex ex real Name comes from netinfo
sMyNic = "{45691A3A-8A5D-4E6E-A5A7-A018BDD69EDE}"
sRequestId = vbNullString


With dClsId
.data = 0&
.flags = 0&
.nbytes = 0&
End With

With sendParams
.flags = 0&
.optionid = 0&
.isvendor = False
.data = 0&
.nbytes = 0&
End With

With sendParamsArray
.nParams = 0
.params = sendParams
End With

With recParams
.flags = 0
.optionid = OPTION_TFTPSERVERNAME
.isvendor = vbFalse
.data = 0&
.nbytes = 0
End With

With recParamsArray
.nParams = 1
.params = recParams
End With

sBuffer = String(255, 0&)

RetCode = DhcpRequestParams( _
DHCPCAPI_REQUEST_SYNCHRONOUS, _
Null, _
StrPtr(sMyNic), _
dClsId, _
sendParamsArray, _
recParamsArray, _
sBuffer, _
256, _
StrPtr(sRequestId))


'always return 49 bad calling convention
MsgBox Trim("" & RetCode)
End Sub
******************** End Code *****************

1 réponse

NHenry Messages postés 15114 Date d'inscription vendredi 14 mars 2003 Statut Modérateur Dernière intervention 4 mai 2024 159
17 juin 2008 à 15:30
Bonjour

Je reprend la déclaration :

DWORD APIENTRY DhcpRequestParams(

  __in     DWORD Flags,

  __in     LPVOID Reserved,

  __in     LPWSTR AdapterName,

  __in     LPDHCPCAPI_CLASSID ClassId,

  __in     DHCPCAPI_PARAMS_ARRAY SendParams,

  __inout  DHCPCAPI_PARAMS_ARRAY RecdParams,

  __in     LPBYTE Buffer,

  __inout  LPDWORD pSize,

  __in     LPWSTR RequestIdStr

);

Flags : Long
Reserved : Long (mis à 0 lors de l'appel)
AdapterName : String
ClassId : Structure perso je pense
SendParams : Structure perso je pense
RecdParams : Structure perso je pense
Buffer : Byte()
pSize : Byref Long(ou Long, à voir)
RequestIdStr
: String

typedef struct _DHCPAPI_CLASSID {

    ULONG Flags;

    LPBYTE Data;

    ULONG nBytesData;

} DHCPCAPI_CLASSID,  *PDHCPCAPI_CLASSID,  *LPDHCPCAPI_CLASSID;

flags : Long (Attention, en VB c'est forcément signé)
data : Byte()
nBytesData : Long (Attention, en VB c'est forcément signé)

typedef struct _DHCPAPI_PARAMS {

    ULONG Flags;

    ULONG OptionId;

    BOOL IsVendor;

    LPBYTE Data;

    DWORD nBytesData;

} DHCPAPI_PARAMS,  DHCPCAPI_PARAMS,  *PDHCPAPI_PARAMS,  *LPDHCPAPI_PARAMS,  *PDHCPCAPI_PARAMS,  *LPDHCPCAPI_PARAMS; flags : Long (Attention, en VB c'est forcément signé)
optionid : Long (Attention, en VB c'est forcément signé)
isvendor : Boolean
data : byte()
nBytes : Long

typedef struct _DHCPCAPI_PARAMS_ARRAY {

    ULONG nParams;

    LPDHCPAPI_PARAMS Params;

} DHCPCAPI_PARAMS_ARRAY,  *PDHCPCAPI_PARAMS_ARRAY,  *LPDHCPCAPI_PARAMS_ARRAY;

nParams : Long (Attention, en VB c'est forcément signé)
Params : LPDHCPAPI_PARAMS

Voilà déjà pour t'aiguiller

Le fer à souder a besoin d'une panne pour fonctionner.
VB (6, .NET1&2), C++, C#.Net1
0
Rejoignez-nous