[SOLVED] How to call SetClassLongPtr?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

[SOLVED] How to call SetClassLongPtr?

16 Oct 2013, 16:31

Code: Select all

Gui, Add, Edit, w300 h100 ReadOnly hwndhEdit
hCursor_NO := DllCall("LoadCursor","UInt",NULL,"Int",32648,"UInt") ; IDC_NO
DllCall("SetClassLong", "Uint", hEdit, "int", -12, "int", hCursor_NO)
Gui, Show
Return

GuiClose:
ExitApp
Above code works on my machine, but the MSDN said:
Note: This function has been superseded by the SetClassLongPtr function. To write code that is compatible with both 32-bit and 64-bit versions of Windows, use SetClassLongPtr.

Code: Select all

ULONG_PTR WINAPI SetClassLongPtr(
  _In_  HWND hWnd,
  _In_  int nIndex,
  _In_  LONG_PTR dwNewLong
);
I've tried this:

Code: Select all

DllCall("SetClassLongPtr", "Ptr", hEdit, "int", -12, "Ptr", hCursor_NO)
The SetClassLongPtr page: http://msdn.microsoft.com/en-us/library ... s.85).aspx
Thanks.
Last edited by tmplinshi on 17 Oct 2013, 05:13, edited 1 time in total.
Zelio
Posts: 278
Joined: 30 Sep 2013, 00:45
Location: France

Re: How to call SetClassLongPtr?

16 Oct 2013, 18:47

It seems the function doesn't exist in user32.dll, maybe only in windows SDK for compile

Code: Select all

Gui, Add, Edit, w300 h100 ReadOnly hwndhEdit
msgbox % hCursor_NO := DllCall("LoadCursor", uint, 0, int, 32648) ; IDC_NO
msgbox % DllCall("SetClassLongPtr", ptr, hEdit, int, -12, ptr, hCursor_NO)
msgbox % DllCall("GetLastError")
Gui, Show
Return

GuiClose:
ExitApp
I used the dependency walker on user32.dll, they are only SetClassLongA SetClassLongW and SetClassWord, AHK add a A or a W automaticly (a_isunicode) and autoload common dll as user32.
Therefore it will not work :( sorry, maybe check if this function can exist in an other dll...
http://en.wikipedia.org/wiki/Dependency_Walker

Out of my knowledge, but if you know how create a dll with windows sdk in C++ then you can define it inside, I guess.
lexikos
Posts: 9688
Joined: 30 Sep 2013, 04:07
Contact:

Re: How to call SetClassLongPtr?

17 Oct 2013, 02:38

When building 32-bit applications, SetClassLongPtr is just a macro for SetClassLong. SetClassLongPtr only exists as a function in the 64-bit dll, so you need to call one or the other depending on A_PtrSize.

(To be precise, SetClassLongPtrW and SetClassLongPtrA are the functions, but DllCall takes care of this.)
tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

Re: How to call SetClassLongPtr?

17 Oct 2013, 04:20

Thank you both.

Use dependency to check function whether exists is a good idea. Next time I will do this using DLL Export Viewer.

So the solution is:

Code: Select all

if A_Is64bitOS
	DllCall("SetClassLongPtr", "Ptr", hEdit, "int", -12, "Ptr", hCursor_NO)
else
	DllCall("SetClassLong", "Uint", hEdit, "int", -12, "int", hCursor_NO)
lexikos
Posts: 9688
Joined: 30 Sep 2013, 04:07
Contact:

Re: [SOLVED] How to call SetClassLongPtr?

17 Oct 2013, 17:10

That is not the solution. As I said, you need to call one or the other depending on A_PtrSize.

Code: Select all

if A_PtrSize = 8

Code: Select all

DllCall("SetClassLong" (A_PtrSize=8 ? "Ptr":""), "Ptr", hEdit, "int", -12, "Ptr", hCursor_NO)
It does not depend on whether your OS is 64-bit. It depends on whether the application is 32-bit or 64-bit. 32-bit applications, such as the 32-bit versions of AutoHotkey.exe, can run on a 64-bit OS. The 32-bit user32.dll (in \Windows\SysWow64) does not contain SetClassLongPtr.
tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

Re: [SOLVED] How to call SetClassLongPtr?

17 Oct 2013, 18:10

Thank you lexikos.

I'm confused...
A_PtrSize [AHK_L 42+]: Contains the size of a pointer, in bytes. This is either 4 (32-bit) or 8 (64-bit), depending on what type of executable (EXE) is running the script.
Is this means when using AutoHotkeyU64.exe, the A_PtrSize will be 8, and using AutoHotkeyA32.exe/AutoHotkeyU32.exe will be 4?
If right, when using AutoHotkeyU32.exe on 64-bit OS, "SetClassLong" (A_PtrSize=8 ? "Ptr":"") will be SetClassLong, but isn't we should use SetClassLongPtr?
Zelio
Posts: 278
Joined: 30 Sep 2013, 00:45
Location: France

Re: [SOLVED] How to call SetClassLongPtr?

17 Oct 2013, 19:26

Only Windows 64 bits can run both : it can manage memory like a x86 or a x64, if a 32 bit program run then that will use the 32 bit windows dynamic library.
AutoHotkeyU32.exe -> A_PtrSize=4
AutoHotkeyU64.exe -> A_PtrSize=8
User avatar
F4Jonatas
Posts: 45
Joined: 22 Oct 2015, 06:35
Contact:

Re: [SOLVED] How to call SetClassLongPtr?

07 Apr 2016, 07:08

Help!
Here is changing 3 controls.

Code: Select all

GUI, +LastFound +Resize
GUI, Font, S12, Segoe UI
GUI, Add, GroupBox, X10 Y5 W240 H80 HwndV01, Cursor Test:
GUI, Add, Text, X20 YP25 HwndV02, Normal cursor
GUI, Add, Text, X20 YP25 HwndV03, Normal cursor
GUI, Add, Button, X10 YP70 HwndThat, Pointer Cursor
GUI, Add, Button, XP125 YP, Normal Cursor
GUI, Add, Button, XP130 YP, Normal Cursor
GUI, Show, W480 H300, Test Cursor

Cursor := DllCall( "User32.dll\LoadCursor", "Int", 0, "Ptr", 32649, "UInt" )
DllCall( "User32.dll\SetClassLong" ( A_PtrSize = 8 ? "Ptr": "" ), "Ptr", That, "Int", -12, "Ptr", Cursor )
DllCall( "User32.dll\DestroyCursor", "Ptr", Cursor )
Return

GUIClose:
ExitApp

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], ShatterCoder, Skrell and 130 guests