(35 pts) CopyCursor API missing - User32.dll

I want to use the CopyCursor Windows API which is documented in the WinSDK and Microsoft MSDN to change an Icon to a Cursor.  I found the declaration for this API in the VB 5 and VB 6 API Viewer.  It's declared as follows:

Public Declare Function CopyCursor Lib "user32" Alias "CopyCursor" (ByVal hcur As Long) As Long

I put it into my code and it came back with the following error:

Error Number = 453
Error Description = Can't find DLL entry point CopyCursor in user32

After getting this error, I looked in the WINUSER.H header file for the Windows API and it's there.  I looked at the exported functions in the USER32.DLL by using Dependency Walker and it did not show that the CopyCursor API was exported.  It did have the CopyIcon API exported, but that's now what I need.

The version of USER32.DLL that I'm using is : 4.00.950


Can anyone tell me why that function is documented, and can be found in the API Viewer but can't be used because USER32.DLL doesn't export it?

Is there another API I can use to do this?

Is there another way to do this without the Windows API?



Who is Participating?
HATCHET1Connect With a Mentor Commented:
I'm going to close this question because I found the answer on my own and keeping it open is going nowhere.

The answer is either use the "OleIconToCursor" function from OLEPRO32.DLL, or get an up-to-date version of the USER32.DLL to have access to the "CopyCursor" function... which IS there, but for some reason is not included in early versions of the USER32.DLL.    I can confidently assume that Micorsoft GOOFED UP on that one.

HATCHETAuthor Commented:
I found an alternate Windows API that does the same thing.  Here's the Visual Basic declaration for it (not found in the API Viewer), and the documentation on it from the MSDN Online Library:

Public Declare Function OleIconToCursor Lib "OLEPRO32.DLL" (ByVal hinstExe As Long, ByVal hIcon As Long) As Long



Converts an icon to a cursor. For Win32 applications, this function calls the Win32 function CopyCursor(hIcon).

STDAPI OleIconToCursor(
  HINSTANCE hinstExe,  //Ignored in Win32
  HICON hIcon          //Handle to the icon


     [in] Ignored in Win32.
     [in] Handle to the icon to be converted to a cursor.


The return value is an HCURSOR for the new cursor object. The caller is responsible for deleting this cursor with the Win32
function DestroyCursor. If the conversion could not be completed, the return value is NULL.


  Windows NT/2000: Requires Windows NT 4.0 or later.
  Windows 95/98: Requires Windows 95 or later.
  Windows CE: Unsupported.
  Header: Declared in olectl.h.
  Library: Included as a resource in olepro32.dll.
Looking at the DLL database at Microsoft, VB5 uses version 4.0.1381.3, which is several versions newer than the one you have on the system. I checked the MSDN, and you are right, it should be in there. However, it would not surprise me if they assume the end user will have the more recent version. I looked at the Dan Appleman book for VB4, and it is not a documented API call there, but that doesn't necessarily mean anything since he only documents a very small portion.

My guess is that the version of user32 required is actually 4.0.1381.3, the minimum for VB5 to run (obviously VB6 would need this or more recent), or one of the service packs. The highest version now is 5.0.2180.1.
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

About your first question - CopyIcon can be used to copy cursors on Win32, thus Win32 does not support the Win16 CopyCursor function. So user32 hasn't CopyCursor function, but user has.

Nothing like backwards compatibility eh?

Use CopyIcon, it works the same on cursors.

Private Declare Function CopyIcon Lib "user32" (ByVal hIcon As Long) As Long
Hi, monteh
Welcome to EE
Take a look at my previous comment - is there any difference with your proposed answer?
HATCHET, it seems that it's one more MS error. I also check user C header, and on-line SDK - and find this function in both places. But user32.dll hasn't this function (though user.exe has) - this is 16-bit function. But I can not understand, what exatly do you want to do?  Why do you need to duplicate cursor? If you already have hCur, use selectobject API to select this cursor into DC and then play with this DC.
HATCHETAuthor Commented:

Can you send me your USER32.DLL?  Mine is obviously very outdated.  I'm using Windows 95B.  Is that your operating system?  If not, don't bother sending it... I need the same to match the OS.  Is there a web site that I can get that DLL from?

I took a look at my KERNEL32.DLL too and it's outdated as well : v4.00.1111

I took a look at my GDI32.DLL too... it's also outdated : v4.00.950

There's got to be a way to update these DLL's... either from Microsoft, or some site out there that has them.  If anyone has Windows 95B and has newer files, send them to HATCHET1998@hotmail.com



I tried using CopyIcon, but I want to change an Icon to a Cursor... READ THE QUESTION.

Thanks for posting though.



Read the question and don't take other people's comments and post them as the answer (especially when those comments are wrong).



As the question states... I want to change an ICON to a CURSOR... CopyIcon doesn't work... though the Windows API does use a C++ implementation of the CopyIcon function to change it somehow to a Cursor.  Any idea HOW?   =)


Ark: looks the same. That's what happens when you sit on your browser for 1/2 hr.

sorry for the mispost...

But you have already answered to your question yourself. Use OleIconToCursor function to convert hIcon to hCursor. But for Win32 icon and cursor are almost the same things with only difference -cursor has info about hotspot but icon has. You can use icon instead cursor in any win32 app (including VB), hotspot will be at the center of icon.
One more question: what do you have as start point (*.ico file, hIcon from one of ExtractIcon... functions) and what do you want to get at the end point (hCursor or *.cur file)?

HATCHETAuthor Commented:
Answer accepted
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.