DllCall: handles and pointers

Get help with using AutoHotkey and its commands and hotkeys
john_c
Posts: 474
Joined: 05 May 2017, 13:19

DllCall: handles and pointers

26 Apr 2020, 13:11

I'm trying to understand:

a) what is handles (in the context of the DllCall function)
b) what is pointers (in the context of the DllCall function)
c) what is the difference between them.

Here is "get screen DPI" code by jeeswg:

Code: Select all

; https://www.autohotkey.com/boards/viewtopic.php?p=174176#p174176
LOGPIXELSX := 88
hDC := DllCall("user32\GetDC", "Ptr",0, "Ptr")
vScreenDPI := DllCall("gdi32\GetDeviceCaps", "Ptr",hDC, "Int",LOGPIXELSX)
DllCall("user32\ReleaseDC", "Ptr",0, "Ptr",hDC)
MsgBox, % vScreenDPI
return
You can see that he use hDC variable to store DllCall("user32\GetDC", "Ptr",0, "Ptr") as its value. It seems it answers the "handles" part of my question. If you need a variable to store DllCall, this variable is a handle, right?

Code: Select all

hVar := DllCall(...)
Still, I don't understand what the pointers are. In one of his posts, jeeswg mentioned handles and pointers as something very closely related, here is a quote:

Code: Select all

Hungarian notation for handles/pointers:
hBitmap
pBitmap
Thus, it seems that under some circumstances we can see a code like the following one:

Code: Select all

DllCall("user32\ReleaseDC", "Ptr",0, "Ptr",pDC)
What does pDC mean? I mean, p stands for pointer, but for what the "pointer" stands for?

@jeeswg
Last edited by john_c on 27 Apr 2020, 04:46, edited 3 times in total.
User avatar
boiler
Posts: 6592
Joined: 21 Dec 2014, 02:44

Re: DllCall: handles and pointers

26 Apr 2020, 13:25

Not all return values of DLL calls are handles. It can be any of a number of data types, as is true for the return value of any function. It just depends on what the purpose of the function is.

A handle is a unique identifier that is used to refer to something like a window or what Microsoft calls a Device Context (DC). A pointer is special data type that contains a memory address that can be to a variable or something else stored in memory like a bitmap.

FYI - Your mention of jeeswg will not get a reply as he is no longer a member of the forum.
john_c
Posts: 474
Joined: 05 May 2017, 13:19

Re: DllCall: handles and pointers

26 Apr 2020, 13:42

@boiler Thanks for explanation.

Yeah, I checked his profile. Interesting what is happened.

Probably you could show a short example to demonstrate a use of a pointer?
Last edited by john_c on 26 Apr 2020, 19:26, edited 1 time in total.
User avatar
boiler
Posts: 6592
Joined: 21 Dec 2014, 02:44

Re: DllCall: handles and pointers

26 Apr 2020, 14:05

Here's a short example. It might not seem that practical, but it shows directly accessing locations in memory using a pointer.

Code: Select all

String := "abcdefghijklmnopqrstuvwxyz"
pChar := &String ; set the pointer to the start of the string
loop, 26 {
	MsgBox, % Chr(*pChar)
	pChar += 2 ; incrment pointer (2 bytes per char)
}
User avatar
Cuadrix
Posts: 224
Joined: 07 May 2017, 08:26

Re: DllCall: handles and pointers

26 Apr 2020, 16:00

Regarding pointers, I'm just gonna say this;
The best way to understand pointers is by learning C or C++
Once you've got the basic knowledge of them, everything becomes clear, even your understanding of DllCalls in Autohotkey
----
john_c
Posts: 474
Joined: 05 May 2017, 13:19

Re: DllCall: handles and pointers

26 Apr 2020, 19:02

@boiler, thanks for example.

Cuadrix, yeah, I believe this is true.
just me
Posts: 7403
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: DllCall: handles and pointers

27 Apr 2020, 03:40

MSDN wrote:
HANDLE

A handle to an object.

This type is declared in WinNT.h as follows:

typedef PVOID HANDLE;

Source: Windows Data Types

Return to “Ask For Help”

Who is online

Users browsing this forum: Google [Bot], JAutohotkey, laulau, mikeyww, RayB, TXShooter, yawikflame and 45 guests