LoadCursor Not Working in 64-bit – Win32API_PtrSafe is Wrong

I’ll Keep this post short and sweet.

I’ve been working with the LoadCursor API:

Private Declare Function LoadCursor Lib "user32" Alias "LoadCursorA" (ByVal hInstance As Long, ByVal lpCursorName As Long) As Long

for a while in 32-bit. Recently, I needed to convert it for use in 64-bit version of Office and turned to Microsoft’s Win32API_PtrSafe.txt (which is the Bible for API declarations if you weren’t already aware) and quickly got the code:

Public Declare PtrSafe Function LoadCursor Lib "user32" Alias "LoadCursorA" (ByVal hInstance As LongPtr, ByVal lpCursorName As String) As LongPtr

, but it wouldn’t work?

Normal troubleshooting got me nowhere and after a couple days of frustration I posted a question on Experts-Exchange. Thankfully Bill Prew came to my rescue and Identified that the declaration provided by Microsoft was wrong! He offer 2 alternatives that worked:

Public Declare PtrSafe Function LoadCursor Lib "user32" Alias "LoadCursorA" (ByVal hInstance As LongPtr, ByVal id As Long) As LongPtr

OR

Public Declare PtrSafe Function LoadCursor Lib "user32" Alias "LoadCursorA" (ByVal hInstance As LongPtr, ByVal id As LongPtr) As LongPtr

So now you know.

Also note, I did forward this information to Microsoft, but who knows if it will be acted on, and this is exactly why I made this posting to ensure that the correct version is available.

3 responses on “LoadCursor Not Working in 64-bit – Win32API_PtrSafe is Wrong

  1. TheSmileyCoder

    Thank you! Like you, I was trying to troubleshoot this and got nowhere. Your post was a big help.