Sign in to follow this  
Followers 0
ajscomp372

WinHTTP DllCall fails

10 posts in this topic

I'm having a problem initializing WinHTTP in my script. Right now it won't even do _WinHttpOpen(). I've already searched the forums, and was unable to find anyone else with this exact problem. I've narrowed it down to the DllCall for _WinHttpOpen() in the actual include. The DllCall fails, but I don't know why. Here is the code I'm using:

#include "WinHTTP.au3"

Global $hHttpOpen = _WinHttpOpen()
If @error Then
    MsgBox(48, "Error", "Error initializing the usage of WinHTTP functions.")
    Exit
EndIf

Thanks in advance!

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Which version of Windows do you use? At least Win2000 SP3 is required.

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

Which version of Windows do you use? At least Win2000 SP3 is required.

I'm running Windows XP Pro SP2

Share this post


Link to post
Share on other sites

Use _WinHttpCheckPlatform() function to see if WinHTTP can be run with you.

If Not _WinHttpCheckPlatform() Then
    MsgBox(48, "Caution", "WinHTTP not available on your system!")
    Exit 1
EndIf

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

The message box says "WinHTTP not available on your system!"

I took it a step further, though, and looked at @error. It was set to 1, which would indicate that the DllCall to check the platform failed all by itself, before the DLL could even think about actually checking the platform.

Share this post


Link to post
Share on other sites

Just to be sure: You have the include-line before the actual command, right?

Please post the output of this script:

$a = DllOpen("winhttp.dll")
ConsoleWrite("error: " & @error & @CRLF)
ConsoleWrite("handle: " & $a & @CRLF)

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

I do have the include line before the command.

I updated AutoIt from 3.3.0.0 to 3.3.6.1, and the problem appears to be solved -- interesting.

Regardless, thanks to both of you for your help.

Share this post


Link to post
Share on other sites

I do have the include line before the command.

I updated AutoIt from 3.3.0.0 to 3.3.6.1, and the problem appears to be solved -- interesting.

Regardless, thanks to both of you for your help.

What's interesting? You not seeing this inside the UDF:

; #INDEX# ===================================================================================
; Title ...............: WinHttp
; File Name............: WinHttp.au3
; File Version.........: 1.6.2.2
; Min. AutoIt Version..: v3.3.2.0
; Description .........: AutoIt wrapper for WinHttp functions
; Author... ...........: trancexx, ProgAndy
; Dll .................: winhttp.dll, kernel32.dll
; ===========================================================================================

Emphasizing Min. AutoIt Version.

...AutoIt uses some new datatypes since.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Hi there,

I'm reanimating this thread, because I have the same problem as the threadstarter, just without a solution jet. I use AutoIT v3.3.8.1, I compile my scripts on a Windows 7 Ultimate 32 Bit and they run on another machine, which is a Windows 7 Professional 64 Bit. Both Windows are fully patched. I use WinHttp v1.6.3.7. In the directory of my compiled exe of this script are also the files:WinHttp.au3 and WinHttpConstants.au3. My Script uses this library to make a HTTP Request and looks into the header and works with these information. The following doesn't trigger @error: #include <WinHttp.au3>, _WinHttpOpen(), _WinHttpConnect(), _WinHttpOpenRequest(), _WinHttpSendRequest(). The following functions trigger @error: _WinHttpReceiveResponse(), _WinHttpQueryHeaders() both with @error 1. The documentation says this "1 - DllCall failed".

Here is the relevant snip of my script:

#Region                                                                     ; **** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Compression=0
#EndRegion
#include <Misc.au3>
#include <File.au3>
#include <WinHttp.au3>
_Singleton( StringReplace(@ScriptName, ".exe", "") )                            ; prevents multiple starts of this script
;#NoEnv                                                                         ; recommended for performance and compatibility with future AutoHotkey releases
;#Warn                                                                          ; enable warnings to assist with detecting common errors
Opt("WinTitleMatchMode", 1)                                                         ; 1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=force lower case match according to other type of match.
Opt("MustDeclareVars", 1)
Global $HttpStatus = 0                                                          ; _MakeHttpRequest() will fill this variable.
Global $FilenameWithExtension = StringReplace(@ScriptName, ".exe", "") & ".log"


Func _MakeHttpRequest ()
    ;If Not _WinHttpCheckPlatform() Then                                                         ; was tested the messagebox didn't show up.
    ;   MsgBox(48, "Caution", "WinHTTP not available on your system!")
    ;   Exit 1
    ;EndIf
    Local $hOpen = _WinHttpOpen()                                                                   ; Open needed handles
    _WinHttpSetOption($hOpen, $WINHTTP_OPTION_USER_AGENT, "Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko")              ; Set User-Agent string
    Local $hConnect = _WinHttpConnect($hOpen, "google.com")                                         ; Open needed handles
    If @error Then
        _WriteLogLine(" --> Error Nr. " & @error & ": using _WinHttpConnect().")
    EndIf
    Local $hRequest = _WinHttpOpenRequest($hConnect, Default, "index.html")                         ; Specify the reguest
    If @error Then
        _WriteLogLine("--> Error Nr. " & @error & ": using _WinHttpOpenRequest().")
    EndIf
    $HttpStatus = 0
    _WinHttpSendRequest($hRequest)                                                                  ; Send request
    If @error Then
        _WriteLogLine("--> Error Nr. " & @error & ": using _WinHttpSendRequest().")
    EndIf
    _WinHttpReceiveResponse($hRequest)                                                              ; Wait for the response
    If @error Then
        _WriteLogLine("--> Error Nr. " & @error & ": using _WinHttpReceiveResponse().")
    EndIf
    Local $sHeader = _WinHttpQueryHeaders($hRequest)                                                ; ...get full header
    If @error Then
        _WriteLogLine("--> Error Nr. " & @error & ": using _WinHttpQueryHeaders().")
    EndIf
    Sleep(150)
    If StringLen($sHeader) < 10 Then
        $HttpStatus = 200
        _WriteLogLine("--> Error Nr. " & @error & ": in _MakeHttpRequest(), $sHeader contains: >>" & $sHeader & "<<")
    Else
        Local $aHeaderPart = StringSplit($sHeader," ")                                              ; extract HTTP Statuscode from full header
        $HttpStatus = $aHeaderPart[2]                                                               ; 2nd Array Element is the HTTP Status.
    EndIf
    _WinHttpCloseHandle($hRequest)                                                                  ; Clean
    _WinHttpCloseHandle($hConnect)                                                                  ; Clean
    _WinHttpCloseHandle($hOpen)                                                                     ; Clean
EndFunc


Func _WriteLogLine($StringToLog=Default)
    Local $hFile = FileOpen(@ScriptDir & "\" & $FilenameWithExtension, 257)                     ; Open logfile in the same directory named like the exe, but with log extension. Create logfile, if necessary.
                                                                                                ;   129 = Verwende Unicode-UTF8 Kodierung im Lese- und Schreib- Anhängmodus. Lesen überschreibt ein existierendes BOM nicht.
                                                                                                ;   256 = Verwende Unicode-UTF8 (ohne BOM) im Lese- und Schreib- Anhängmodus.
    _FileWriteLog($hFile, $StringToLog)                                                         ; Write string to logfile.
    Sleep(1000)                                                                                 ; Wait 1 second.
    FileClose($hFile)                                                                           ; Close logfile.
EndFunc


While True
    _MakeHttpRequest ()
    Sleep(600000)                                                                                   ; Wait 10 minutes.
Wend

My logfile contains multiple entries like this ones:

2014-06-27 14:11:22 : --> Error Nr. 1: using _WinHttpReceiveResponse().
2014-06-27 14:11:23 : --> Error Nr. 1: using _WinHttpQueryHeaders().
2014-06-27 14:11:24 : --> Error Nr. 0: in _MakeHttpRequest(), $sHeader contains: >><<

Help to solve this error is most appreciated. Currently I'm requesting a HTTP request, how can I request via HTTPS?  :)

Edited by AnotherNamePlease

Share this post


Link to post
Share on other sites

Any new solution ideas for this?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0