[Solved] ERROR_INVALID_DLL when Dllcalling httpapi.dll

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
DeadLock
Posts: 3
Joined: 30 Nov 2013, 02:08

[Solved] ERROR_INVALID_DLL when Dllcalling httpapi.dll

07 Jan 2014, 01:09

i'm trying to call HttpInitialize in httpapi.dll
and i always get the Error: ERROR_INVALID_DLL := 1154 (0x482)
which indicates that: One of the library files needed to run this application is damaged.
But that's most likely not the case:
DllExportViewer can read the dll just fine.
And i downloaded some other versions of httpapi.dll, the Error is always the same.

I have no clue what could be wrong.
Any insights would be welcome.

And could someone test this script, to see if it's just on my system or everywhere:

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn  ; Recommended for catching common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

; load the httpapi.dll
hModule := DllCall("LoadLibrary", "Str", "httpapi.dll", "Ptr") 

ListVars
MsgBox % hModule


; The HttpInitialize function initializes the HTTP Server API driver, 
;  starts it, if it has not already been started, and allocates data structures 
;  for the calling application to support response-queue creation and other operations. 
;  Call this function before calling any other functions in the HTTP Server API.

;dwRes := DllCall("HttpInitialize", "UInt", Version, "UInt", Flags, "UInt", &pReserved)

; Version [in]
;  HTTP version. This parameter is an HTTPAPI_VERSION structure. 
;  For the current version, declare an instance of the structure and set it to 
;  the pre-defined value HTTPAPI_VERSION_1 before passing it to HttpInitialize.
; Flags [in]
;  Initialization options, which can include one or both of the following values.
;  HTTP_INITIALIZE_CONFIG : Perform initialization for applications that use the HTTP configuration functions, HttpSetServiceConfiguration, HttpQueryServiceConfiguration and HttpDeleteServiceConfiguration.
;  HTTP_INITIALIZE_SERVER : Perform initialization for applications that use the HTTP Server API.     
; pReserved [in, out]
;  This parameter is reserved and must be NULL.

;"#define HTTPAPI_VERSION_1 {1, 0}"
HTTPAPI_VERSION_HttpApiMajorVersion := 1
HTTPAPI_VERSION_HttpApiMinorVersion := 0
; typedef struct _HTTPAPI_VERSION {
VarSetCapacity(HTTPAPI_VERSION, 4, 0)
NumPut(HTTPAPI_VERSION_HttpApiMajorVersion, HTTPAPI_VERSION, 0, "UShort")
NumPut(HTTPAPI_VERSION_HttpApiMinorVersion, HTTPAPI_VERSION, 2, "UShort")
; }

HTTP_INITIALIZE_SERVER := 0x00000001
HTTP_INITIALIZE_CONFIG := 0x00000002

pReserved := 0

dwRes := DllCall("httpapi.dll\HttpInitialize", "UInt", HTTPAPI_VERSION, "UInt", HTTP_INITIALIZE_SERVER, "UInt", &pReserved)



;Transform Error-Message to match SKAN's diction. see Error values below
VarSetCapacity(swapRes, 4, 0)
NumPut(dwRes, swapRes, 0, "Int")
gdwRes := NumGet(swapRes,,"UInt")
SetFormat, IntegerFast, hex
gdwRes += 0  
gdwRes .= ""  ; Necessary due to the "fast" mode.
SetFormat, IntegerFast, d



ListVars
MsgBox % gdwRes . " - " . ErrorLevel

; ERROR_INVALID_DLL := 1154 (0x482)
; One of the library files needed to run this application is damaged.
Last edited by DeadLock on 07 Jan 2014, 14:53, edited 2 times in total.
Therobotmd
Posts: 7
Joined: 06 Jan 2014, 03:50

Re: ERROR_INVALID_DLL when Dllcalling httpapi.dll

07 Jan 2014, 02:17

Same error here in win7 x64 with AHK_L. Sadly, I can't help you more then that. I know nothing of that particular DLL's usage. Though I don't see any obvious mistakes based on a quick glance. (Not that I would recognize one of there were...)
User avatar
LinearSpoon
Posts: 156
Joined: 29 Sep 2013, 22:55

Re: ERROR_INVALID_DLL when Dllcalling httpapi.dll

07 Jan 2014, 05:33

Two things.
1. HTTPAPI_VERSION can't be passed like this. Specifying uint type will make AHK try to read its binary data as a string. Use NumGet to extract the integer it represents, and pass that instead.
2. "pReserved -This parameter is reserved and must be NULL." It wants you to actually pass NULL, not the address of a NULL value. Also, PVOID is pointer type, but it shouldn't make a difference here.

Code: Select all

dwRes := DllCall("httpapi.dll\HttpInitialize", "UInt", NumGet(HTTPAPI_VERSION), "UInt", HTTP_INITIALIZE_SERVER, "ptr", 0)
Edit:
This would also have the same effect..

Code: Select all

dwRes := DllCall("httpapi.dll\HttpInitialize", "UInt", 1, "UInt", HTTP_INITIALIZE_SERVER, "ptr", 0)
User avatar
DeadLock
Posts: 3
Joined: 30 Nov 2013, 02:08

Re: ERROR_INVALID_DLL when Dllcalling httpapi.dll

07 Jan 2014, 14:36

Thank you, Therobotmd and especially LinearSpoon.
That saved my day. The "damaged-file"-error send me in the completely wrong direction.

So, Solved!
Thanks again.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot] and 296 guests