DllCall msdn datatypes?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Bruttosozialprodukt
Posts: 463
Joined: 24 Jan 2014, 22:28

DllCall msdn datatypes?

27 Apr 2014, 02:08

How can I call functions like this one? http://msdn.microsoft.com/en-us/library ... 85%29.aspx

The DllCall documentation says that there are only very few datatypes available. Like int, short, char, float...
But what about the msdn types like LPCWSTR, DWORD, HANDLE etc?
Does it even matter or could I jsut go like this?

Code: Select all

hSession := DllCall("WinHttpOpen","Str","testagent","uInt",1,"Str","","uInt",0,"uInt",0)


(I need the winhttp functions to send binary post data, in case you are wondering.)
User avatar
Menixator
Posts: 69
Joined: 30 Sep 2013, 04:10

Re: DllCall msdn datatypes?

27 Apr 2014, 02:19

Code: Select all

LPCWSTR --> Ptr
DWORD --> UInt
HANDLE --> Ptr
Here. This will help you a lot if you use the winApi frequently. WinApi DataTypes.htm
Bruttosozialprodukt
Posts: 463
Joined: 24 Jan 2014, 22:28

Re: DllCall msdn datatypes?

27 Apr 2014, 02:29

Thanks that helps indeed.
So when a function returns HANDLE, does it would return the address to the variable or how does the Ptr work?
And does Ptr as parameter generally mean, that I can't directly pass values and that I have to pass the address of an existing variable?
RHCP
Posts: 202
Joined: 30 Sep 2013, 10:59

Re: DllCall msdn datatypes?

27 Apr 2014, 02:54

http://www.autohotkey.com/board/topic/7 ... t-scripts/

Read lexiko's third post, it will shed some light on this.

The ptr type will just pass whatever the associated argument evaluates to. If you are trying to pass the address of some AHk varriable, then you should use &var.
Bruttosozialprodukt
Posts: 463
Joined: 24 Jan 2014, 22:28

Re: DllCall msdn datatypes?

27 Apr 2014, 16:18

http://www.autohotkey.com/board/topic/7 ... _id_469487
This post pretty much cleared it all up. It seems to be like I thought. Ptr simply is an address to a variable.

But I'm unsure if the list from Menixator is correct. The post I already mentioned and the following one are suggesting that eg LPCTSTR has to be a uPTR and not a PTR: http://www.autohotkey.com/board/topic/7 ... _id_469449
User avatar
LinearSpoon
Posts: 156
Joined: 29 Sep 2013, 22:55

Re: DllCall msdn datatypes?

27 Apr 2014, 18:26

Well you don't have negative memory addresses, so I guess it's technically unsigned, but it won't make a difference in the majority of scripts. It's also not supported in 64 bit AHK.
http://ahkscript.org/docs/commands/DllCall.htm#ptr

I would suggest "str" type for LPCTSTR and "wstr" for LPCWSTR, however it is still possible to use ptr.
Bruttosozialprodukt
Posts: 463
Joined: 24 Jan 2014, 22:28

Re: DllCall msdn datatypes?

27 Apr 2014, 18:46

However, I can't really get it to work. :(
Is the parameter "Winhttp.dll\WinHttpOpen" even valid?
When I try it hSession is empty and ErrorLevel is -2. Any idea how I could fix that?

Here is my code:

Code: Select all

LPCWSTR:=UPTR
DWORD:=UInt
LPCVOID:=UPTR
LPDWORD:=UPTR
HINTERNET:=UPTR ;LPCVOID
INTERNET_PORT:=UShort ;WORD

userAgent := "AHK TestAgent"
proxy := "" ;localhost:8888
;proxyType := (proxy) ? 3 : 1
asynch := False
bypassProxyHostList := "localhost;127.0.0.1"

hSession := DllCall("Winhttp.dll\WinHttpOpen",LPCWSTR,&userAgent,DWORD,(proxy)?3:1,LPCWSTR,&proxy,LPCWSTR,&bypassProxyHostList,DWORD,asynch)

If (hSession)
     ;...
Else
    Msgbox % "hSession error: " ErrorLevel
User avatar
LinearSpoon
Posts: 156
Joined: 29 Sep 2013, 22:55

Re: DllCall msdn datatypes?

27 Apr 2014, 18:58

UPTR, UInt, etc were never given values, so you're essentially passing a blank string for each type parameter, which explains Errorlevel = -2.

Use the = operator to assign or use quotes to make them strings.
Bruttosozialprodukt
Posts: 463
Joined: 24 Jan 2014, 22:28

Re: DllCall msdn datatypes?

27 Apr 2014, 19:11

Are you sure?
I mean in the second example in the docs you can see that it you can directly pass UInt as variable.
http://www.autohotkey.com/docs/commands/DllCall.htm
But okay I will give it a try.

edit: okay you were right. thanks. :)
Bruttosozialprodukt
Posts: 463
Joined: 24 Jan 2014, 22:28

Re: DllCall msdn datatypes?

27 Apr 2014, 19:41

I'm still having a problem with the HINTERNET handle.
I just checked it in visual studio, it should be the same as LPVOID. "typedef LPVOID HINTERNET;"
And LPVOID should be UPTR in AHK. But when I use the returned handle of WinHttpOpen in WinHttpConnect A_LastError contains 6, which means the handle is invalid.

Code: Select all

LPCWSTR:="UPTR"
DWORD:="UInt"
LPCVOID:="UPTR"
LPDWORD:="UPTR"
HINTERNET:="UPTR" ;LPVOID
INTERNET_PORT:="UShort" ;WORD

userAgent := "AHK TestAgent"
proxy := "" ;localhost:8888
;proxyType := (proxy) ? 3 : 1
asynch := False
bypassProxyHostList := "localhost;127.0.0.1"

hSession := DllCall("Winhttp.dll\WinHttpOpen",LPCWSTR,&userAgent,DWORD,(proxy)?3:1,LPCWSTR,&proxy,LPCWSTR,&bypassProxyHostList,DWORD,asynch)

hostName := "www.google.com"
https := False

If (hSession)
    hConnect := DllCall("Winhttp.dll\WinHttpConnect",HINTERNET,&hSession,LPCWSTR,&hostName,INTERNET_PORT,(https)?443:80,DWORD,0)
Else
    Msgbox % "hSession error: " A_LastError

;...

If (hConnect)
    ;...
Else
    Msgbox % "hConnect error: " A_LastError

eidt:
Ahhh, hold up, my mistake. I passed the address of the handle. But since the handle already is a pointer I had to pass it directly.

Great, it seems to work!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 353 guests