[WinApi] alternative to LoadImage (animated cursor)

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
kyuuuri
Posts: 340
Joined: 09 Jan 2016, 19:20

[WinApi] alternative to LoadImage (animated cursor)

31 Jan 2020, 21:32

Since one of the latest updates LoadImage broke and now I can't use it to load an Animated Cursor (this is confirmed by an employee of Microsoft).
I wonder what alternatives do I have.

This was my code (that worked until Microsoft broke it):

Code: Select all

gui, 1:add, text, x0 y0 w20 h20, test
gui, 1:-caption hwndH1
gui, 1:show, w500 h500
hModule   := DllCall("kernel32\GetModuleHandle", "ptr", "C:\Users\test\Desktop\test.exe", "ptr")
AniCursor := DllCall("LoadImage", "ptr", hModule, "Uint", 5234, "Uint", 0x2, "int", 0, "int", 0, "Uint", zero)
DllCall("SetClassLongPtrW", "ptr", H1, "int", "-12", "ptr", AniCursor)
This code was simple:
1_ Create a GUI with a hwnd
2_ Get a handle to the .exe that contains the resource.
3_ Load the animated cursor (resource name: 5234)
4_ Set the Animated cursor on the Gui.

Now I need an alternative to this, I've been playing around with FindResource LoadResource LockResource but I'm stuck.

This is the code:

Code: Select all

gui, 1:add, text, x0 y0 w20 h20, test
gui, 1:-caption hwndH1
gui, 1:show, w500 h500
ResourceLoad(5234)

; I stole this function, I don't remember where I found it.
ResourceLoad(resource)
{
	msgbox % hModule 	:= DllCall("kernel32\LoadLibrary", "str", "C:\Users\test\Desktop\test.exe", "ptr")
	msgbox % hResource 	:= DllCall("kernel32\FindResource", "ptr", hModule, "ptr", resource, "ptr", 21, "ptr")
	msgbox % nSize 		:= DllCall("kernel32\SizeofResource", "ptr", hModule, "ptr", hResource, "Uint")
	msgbox % hResData 	:= DllCall("kernel32\LoadResource", "ptr", hModule, "ptr", hResource, "ptr")
	msgbox % Buffer    	:= DllCall("kernel32\LockResource", "ptr", hResData, "ptr")
	msgbox % hData 		:= DllCall("GlobalAlloc", "uint", 2, "Ptr", nSize, "Ptr")
	msgbox % pData 		:= DllCall("GlobalLock", "Ptr", hData, "Ptr")
	DllCall("RtlMoveMemory", "Ptr", pData, "Ptr", Buffer, "Ptr", nSize)
	DllCall("kernel32\GlobalUnlock", "ptr", hData)
	DllCall("ole32\CreateStreamOnHGlobal", "ptr", hData, "int", 1, "UPtr*", pStream)
	DllCall("gdiplus\GdipCreateBitmapFromStream", "ptr", pStream, "UPtr*", hBitmap)
	return hBitmap
}
It finds the resource, it correctly loads it BUT it's not the "format" (idk how it is called) I need.

From https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-loadimagea
...the return value is the handle of the newly loaded image.
How do I get the same but with this alternative? Where should I stop, or what dllcall should I change?
I already tried with hResData but it doesn't work.

Thanks in advance.
just me
Posts: 9576
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [WinApi] alternative to LoadImage (animated cursor)

01 Feb 2020, 06:26

  • Code: Select all

    hModule   := DllCall("kernel32\GetModuleHandle", "ptr", "C:\Users\test\Desktop\test.exe", "ptr")
    The module must have been loaded by the calling process.
    Where and how do you do it?
  • Code: Select all

    DllCall("SetClassLongPtrW", "ptr", H1, "int", "-12", "ptr", AniCursor)
    Obviously your AHK is 64-bit. Is test.exe 64-bit too?
  • What about LR_LOADFROMFILE (0x00000010)?

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: apeironn, madensuyu1, peter_ahk and 335 guests