DhcpRequestParams in AutoIt umsetzen

  • Hallo zusammen,
    ich brauche mal wieder eure Unterstützung, speziell von den Leuten, die auch C++ fit sind.
    Ich möchte die Funktion DhcpRequestParams aus der DHCP Client API in AutoIt portieren.
    Die Beschreibung der Funktion gibt es hier:

    http://msdn.microsoft.com/en-us/library/…v=vs.85%29.aspx

    und ein Beispiel zu der Funktion hier:

    http://msdn.microsoft.com/en-us/library/…v=vs.85%29.aspx

    Wäre echt super wenn jemand mit C++ Erfahrung das in AutoIt übersetzen könnte.
    Vielen Dank schon mal.

    Einmal editiert, zuletzt von edmann (17. Juli 2012 um 18:59)

  • Habe noch etwas gegoogelt und folgendes gefunden
    Die funtion kann man aus der dhcpcsvc.dll mit einem DllCall befehl ausführen.
    Es gibt auch einige VB beispiele dazu
    http://www.windows-api.com/microsoft/VB-W…hcpcsvcdll.aspx
    Leider habe ich keine Ahnung wie ich in AutoIt die benötigren Strukturen und Pointer aufbauen kann.
    Ich weiss das hier einige im Forum mit DllCall und DllStructCreate ziemlich fit sind.
    Könnt ihr hier bitte unterstützen.
    Vielen Dank

  • Anhand meiner bisherigen Suchergebnise habe ich folgenden Code erstellt.

    [autoit]


    Global Const $DHCPCAPI_REQUEST_PERSISTENT = 0x01
    Global Const $DHCPCAPI_REQUEST_SYNCHRONOUS = 0x02
    Global Const $DHCPCAPI_REQUEST_ASYNCHRONOUS = 0x04
    Global Const $DHCPCAPI_REQUEST_CANCEL = 0x08
    Global Const $DHCPCAPI_REQUEST_MASK = 0x0F

    [/autoit][autoit][/autoit][autoit]

    Global $OPTION_NAME = 66
    Global $DHCPAPI_PARAMS = "ULONG Flags;ULONG OptionId;BOOL IsVendor;BYTE* Data;DWORD nBytesData"
    Global $DHCPCAPI_PARAMS_ARRAY = "ULONG nParams;ptr Params"
    Global $DHCPAPI_CLASSID = "ULONG Flags;BYTE* Data;ULONG nBytesData"
    Global $sDhcpClassId = "test"

    [/autoit][autoit][/autoit][autoit][/autoit][autoit]

    Main()

    [/autoit][autoit][/autoit][autoit]

    Func Main()
    Local $Data = DllStructCreate("BYTE")
    Local $iError

    [/autoit][autoit][/autoit][autoit]

    $RequestParams = DllStructCreate($DHCPAPI_PARAMS)
    DllStructSetData($RequestParams, "Flags", 0)
    DllStructSetData($RequestParams, "OptionId", $OPTION_NAME)
    DllStructSetData($RequestParams, "IsVendor", False)
    DllStructSetData($RequestParams, "Data", DllStructGetPtr($Data))
    DllStructSetData($RequestParams, "nBytesData", 0)

    [/autoit][autoit][/autoit][autoit]

    $SendParamsArray = DllStructCreate($DHCPCAPI_PARAMS_ARRAY)
    DllStructSetData($SendParamsArray, "nParams", 0)
    DllStructSetData($SendParamsArray, "Params", -1)

    [/autoit][autoit][/autoit][autoit]

    $RequestParamsArray = DllStructCreate($DHCPCAPI_PARAMS_ARRAY)
    DllStructSetData($RequestParamsArray, "nParams", 1)
    DllStructSetData($RequestParamsArray, "Params", DllStructGetPtr($RequestParams))

    [/autoit][autoit][/autoit][autoit]

    $Version = DllStructCreate("DWORD")
    $sAdapterName = "{C9714EC9-6259-44B8-B7BC-DB77174E115C}"

    [/autoit][autoit][/autoit][autoit]

    $Buffer = DllStructCreate("CHAR Buffer[1000]")
    DllStructSetData($Buffer, "Buffer", "")

    [/autoit][autoit][/autoit][autoit]

    $Size = DllStructCreate("DWORD Size")
    DllStructSetData($Size, "Size", DllStructGetSize($Buffer))

    [/autoit][autoit][/autoit][autoit]

    $RequestIdStr = DllStructCreate("WSTR RequestId")
    DllStructSetData($RequestIdStr, "RequestId", "")

    [/autoit][autoit][/autoit][autoit]

    DhcpCApiInitialize($Version)
    $iError = DhcpRequestParams($DHCPCAPI_REQUEST_SYNCHRONOUS, $sAdapterName, -1, $SendParamsArray, $RequestParamsArray, DllStructGetPtr($Buffer), DllStructGetPtr($Size), -1)
    EndFunc

    [/autoit][autoit][/autoit][autoit]

    Func DhcpCApiInitialize(ByRef $Version)
    $hDll = DllOpen("dhcpcsvc.dll")
    $iRetVal = DllCall($hDll,"DWORD", "DhcpCApiInitialize", "DWORD*", DllStructGetPtr($Version))
    DllClose($hDll)
    Return $iRetVal
    EndFunc

    [/autoit][autoit][/autoit][autoit]

    Func DhcpCApiCleanup()
    $hDll = DllOpen("dhcpcsvc.dll")
    $iRetVal = DllCall($hDll,"none", "DhcpCApiCleanup")
    DllClose($hDll)
    Return $iRetVal
    EndFunc

    [/autoit][autoit][/autoit][autoit]

    Func DhcpRequestParams($iFlags, $sAdapterName, $ClassId, $SendParams, ByRef $RecdParams, $pBuffer, $pSize, $pRequestIdStr)
    $hDll = DllOpen("dhcpcsvc.dll")
    $iRetVal = DllCall($hDll,"DWORD", "DhcpRequestParams", "DWORD", $iFlags, "ptr", -1, "wstr", $sAdapterName, "struct", $ClassId, "struct", $SendParams, "struct", $RecdParams, "BYTE*", $pBuffer, "DWORD*", $pSize, "wstr", $pRequestIdStr)
    DllClose($hDll)
    Return $iRetVal
    EndFunc

    [/autoit]

    Leider funktioniert es nicht und ich habe auch keine Idee wie ich die gewünschten Daten aus dem Ergebnis rausholen kann ;(

  • Hallo
    ein letzter Versuch. Ich denke jetzt habe ich den Code genau so umgesetzt wie es in der MSDN vorgegeben wird

    [autoit]


    Global Const $DHCPCAPI_REQUEST_PERSISTENT = 0x01
    Global Const $DHCPCAPI_REQUEST_SYNCHRONOUS = 0x02
    Global Const $DHCPCAPI_REQUEST_ASYNCHRONOUS = 0x04
    Global Const $DHCPCAPI_REQUEST_CANCEL = 0x08
    Global Const $DHCPCAPI_REQUEST_MASK = 0x0F

    [/autoit][autoit][/autoit][autoit]

    Global $OPTION_HOST_NAME = 12
    Global $DHCPAPI_PARAMS = "ULONG Flags;ULONG OptionId;BOOL IsVendor;BYTE* Data;DWORD nBytesData"
    Global $DHCPCAPI_PARAMS_ARRAY = "ULONG nParams;ptr Params"
    Global $DHCPAPI_CLASSID = "ULONG Flags;BYTE* Data;ULONG nBytesData"

    [/autoit][autoit][/autoit][autoit][/autoit][autoit]

    Main()

    [/autoit][autoit][/autoit][autoit]

    Func Main()
    Local $iError

    [/autoit][autoit][/autoit][autoit]

    $RequestParams = DllStructCreate($DHCPAPI_PARAMS)
    DllStructSetData($RequestParams, "Flags", 0)
    DllStructSetData($RequestParams, "OptionId", $OPTION_HOST_NAME)
    DllStructSetData($RequestParams, "IsVendor", False)
    DllStructSetData($RequestParams, "Data", -1)
    DllStructSetData($RequestParams, "nBytesData", 0)

    [/autoit][autoit][/autoit][autoit]

    $SendParamsArray = DllStructCreate($DHCPCAPI_PARAMS_ARRAY)
    DllStructSetData($SendParamsArray, "nParams", 0)
    DllStructSetData($SendParamsArray, "Params", -1)

    [/autoit][autoit][/autoit][autoit]

    $RequestParamsArray = DllStructCreate($DHCPCAPI_PARAMS_ARRAY)
    DllStructSetData($RequestParamsArray, "nParams", 1)
    DllStructSetData($RequestParamsArray, "Params", DllStructGetPtr($RequestParams))

    [/autoit][autoit][/autoit][autoit]

    $Version = DllStructCreate("DWORD Version")
    $sAdapterName = "{71F897D7-EB7C-4D8D-89DB-AC80D9DD2270}"
    $Buffer = DllStructCreate("CHAR Buffer[1000]")
    $Size = DllStructCreate("DWORD Size")
    DllStructSetData($Size, "Size", DllStructGetSize($Buffer))
    $pSize = DllStructGetPtr($Size)
    $pBuffer = DllStructGetPtr($Buffer)

    [/autoit][autoit][/autoit][autoit]

    DhcpCApiInitialize($Version)
    ConsoleWrite("$Version: " & DllStructGetData($Version, "Version") & @CRLF)
    $aError = DhcpRequestParams($DHCPCAPI_REQUEST_SYNCHRONOUS, $sAdapterName, -1, $SendParamsArray, $RequestParamsArray, $pBuffer, $pSize, -1)
    EndFunc

    [/autoit][autoit][/autoit][autoit]

    Func DhcpCApiInitialize(ByRef $Version)
    Local $iError = 0

    [/autoit][autoit][/autoit][autoit]

    $aRetVal = DllCall("dhcpcsvc.dll","DWORD", "DhcpCApiInitialize", "DWORD*", DllStructGetPtr($Version))
    If @error Then
    $iError = @error
    ConsoleWrite("Error DhcpCApiInitialize" & $iError & @CRLF)
    EndIf
    SetError($iError)
    Return $aRetVal
    EndFunc

    [/autoit][autoit][/autoit][autoit]

    Func DhcpRequestParams($Flags, $AdapterName, $ClassId, $SendParams, ByRef $RecdParams, $Buffer, ByRef $pSize, $RequestIdStr)
    Local $iError = 0

    [/autoit][autoit][/autoit][autoit]

    $aRetVal = DllCall("dhcpcsvc.dll","DWORD", "DhcpRequestParams", "DWORD", $Flags, "ptr", -1, "wstr", $AdapterName, "struct*", $ClassId, "struct", $SendParams, "struct", $RecdParams, "BYTE*", $Buffer, "DWORD*", $pSize, "wstr", $RequestIdStr)
    If @error Then
    $iError = @error
    ConsoleWrite("Error DhcpRequestParams" & $iError & @CRLF)
    EndIf
    SetError($iError)
    Return $aRetVal
    EndFunc

    [/autoit]

    Leider verabschiedet sich Autoit mit dem Fehler AutoIT3.exe ended.rc:-1073741819
    Was auch immer das bedeutet. Ein Punkt ist mir noch nicht ganz klar und da habe ich auch keine eindeutige Aussagen dazu gefunden.
    In dem C++ Code wird an einigen Stellen ein NULL Wert gesetzt. Gibt es in AutoIt ein Äquivalent zu NULL. In einigen Beiträgen habe ich gelesen das man -1 verwenden soll, aber sicher ist es auch nicht. Weiss jemand von euch ob es sowas wie NULL in Autoit gibt?
    An sonsten bin ich mit meinem Latein am Ende. Wäre echt cool wenn jemand, der mit der DLL Aufruferei mehr Erfahrung hat, hier mal drüber schaut.
    Vielen Dank...