[Windows] Can not load SetWindowLongPtrW in user32.dll

711 views
Skip to first unread message

Archos

unread,
Sep 13, 2012, 3:29:39 PM9/13/12
to golan...@googlegroups.com
Windows can not load a procedure, but according to the documentation[1] it should be in user32.dll:

>go run foo.go
panic: Failed to find SetWindowLongPtrW procedure in user32.dll: The specified procedure could not be found.

[1]: http://msdn.microsoft.com/en-us/library/windows/desktop/ms644898%28v=vs.85%29.aspx
http://pastebin.com/thBriKhk

System: Windows XP

Harley Laue

unread,
Sep 13, 2012, 3:55:33 PM9/13/12
to golan...@googlegroups.com
Is it? My grep on a WinXP & wine box didn't find SetWindowLongPtr.
According to winuser.h for MinGW32, it's a define to
SetWindowLong{A,W} which means it's not in the user32.dll as
SetWindowLongPtr on 32 bit machines. The windows documentation also
notes this as:
> Note To write code that is compatible with both 32-bit and 64-bit versions of Windows, use SetWindowLongPtr. When compiling for 32-bit Windows, SetWindowLongPtr is defined as a call to the SetWindowLong function.
This leads me to believe that the Win32 user32.dll doesn't have
SetWindowLongPtr, instead it has SetWindowLong.

Archos

unread,
Sep 13, 2012, 4:17:24 PM9/13/12
to golan...@googlegroups.com
I've used SetWindowLongPtr to have compatibility with both architectures but it's a define like you say. It works using SetWindowLongW instead.

AllenDang

unread,
Sep 13, 2012, 10:11:06 PM9/13/12
to golan...@googlegroups.com
Try this package, it wraps lots of windows APIs.

JussiJ

unread,
Sep 14, 2012, 12:57:59 AM9/14/12
to golan...@googlegroups.com
On Friday, September 14, 2012 5:29:39 AM UTC+10, Archos wrote:
Windows can not load a procedure, but according to the documentation[1] it should be in user32.dll:

If you look inside the Microsoft SDK Winuser.h file you will see these 32 bit application defines:

    #define GetWindowLongPtrA   GetWindowLongA
    #define GetWindowLongPtrW   GetWindowLongW

In other words, for 32 bit applications GetWindowLongPtr maps exaclty to GetWindowLong and those functions are found in the user32.dll file.
 

Archos

unread,
Sep 14, 2012, 3:50:16 AM9/14/12
to golan...@googlegroups.com
Also, it is this package

https://github.com/lxn/go-winapi

but since I only need a few Windows' system calls I prefer to use go.mksyscall [1] to get them, although I have to translate the C++ types to Go but there is no problem with the help of this page [2].

[1]: https://github.com/kless/cutil
[2]: http://msdn.microsoft.com/en-us/library/windows/desktop/aa383751%28v=vs.85%29.aspx

Andy Balholm

unread,
Sep 14, 2012, 11:11:05 PM9/14/12
to golan...@googlegroups.com
You need to make two conditionally-compiled files, one for 32-bit Windows and one for 64-bit.

In the 32-bit one, load SetWindowLongW; in the 64-bit one, load SetWindowLongPtrW.

Archos

unread,
Sep 15, 2012, 2:14:32 PM9/15/12
to golan...@googlegroups.com
My Windows system is of 64 bits; I know it because when I compiled the source code it showed amd64.
But I installed MinGW from mingw.org where it is the version for x86 systems, so I'm supposed that SetWindowLongPtrW can not be found there.

Now, I just find that there is MinGW version for x86-64 systems:
http://mingw-w64.sourceforge.net/

(I'll have to install it and checking if it has SetWindowLongPtrW)


El jueves, 13 de septiembre de 2012 20:55:40 UTC+1, Harley Laue escribió:

Patrick Mylund Nielsen

unread,
Sep 15, 2012, 3:07:22 PM9/15/12
to Archos, golan...@googlegroups.com
http://tdm-gcc.tdragon.net/

--
 
 

Reply all
Reply to author
Forward
0 new messages