I noticed in my programs that putting "handle:" at the top of the program works for almost all scenarios i need for handles. But apparently it seems that for those cases it just needs a unique ID. My theory was that handles are mearly pointers to the program itself. That would ensure the program got a unique ID and one could just add the pointer to the program to all the pointers in the program file and it would be easy. Welp, i never did printf the handle method i used till now. It turns out that the variable gets the value of 0. So, i came up with a way to check if i'm right (beause if you declare it after the format part, it adds 4kb to it). But i'm assuming that if we all ran it on our computers it would ensure that it works, because it could just end up being one wacky coincidence on my computer.
use32
format PE GUI 4.0
handlecalcvar:
handle = handlecalcvar-4096
entry main
include '%fasminc%\win32ax.inc'
section '.code' readable writeable executable
good du "Please post that it worked.", 10, "Kohlrak found how to get a handle without calling GetModuleHandle.", 0
bad du "Please post that it didn't work.", 0
main:
invoke GetModuleHandle, 0
cmp eax, handle
jne DARN
invoke MessageBox, HWND_DESKTOP, good, 0, MB_OK
jmp YAY
DARN:
invoke MessageBox, HWND_DESKTOP, bad, 0, MB_OK
YAY:
invoke ExitProcess, 0
section '.idata' readable writeable import
library kernel, 'kernel32.dll',\
user, 'user32.dll'
import kernel, GetModuleHandle, 'GetModuleHandleA',\
ExitProcess, 'ExitProcess'
import user, MessageBox, 'MessageBoxW'
I know, no error checking, but personally i think that since this is a restricted test, if anything goes wrong you can fix it.
I hope this works. That way, i'm not only right about something for once, but I will also have a way to get away from the GetModuleHandle and perhaps some other goodies will follow, as well.