I'm trying to change the cursor of my mouse with a .cur file in a resource file.
When I'm try my code, I get this error:
Exception raised at 0x77EB7392 (ntdll.dll) in CleanResourceFiles.exe: 0xC0000005: Access Violation while reading location 0x00000066.
Here is the code:
HCURSOR curs = (HCURSOR)LoadImage(NULL, MAKEINTRESOURCE(IDC_CURSOR1), 2, 0, 0, LR_LOADFROMFILE);
SetSystemCursor(curs, 32512);
Note : IDC_CURSOR1 is my cursor and 32512 is the ID of the classic arrow cursor. I also included <Windows.h> and my resource.h.
I'm using Visual Studio Community 2017, with Win10.
I tried other functions, like LoadCursor(). The code above is from "VineMemz".
Finally, when I tried to change my cursor with LoadFromFile() using the path to my .cur file, it works.
When calling
LoadImage(), you are specifying theLR_LOADFROMFILEflag, so thelpszNameparameter will be interpreted as a pointer to a null-terminated string containing the path to the.curfile to load. But, you are passing in a resource ID number instead of a file path string (I'm assumingIDC_CURSOR1is 102 (0x66), which would be consistent with the memory address reported in the error message). You need to get rid of theLR_LOADFROMFILEflag when loading an image from resources.Also, you need to pass in the EXE's actual module handle in the
hinstparameter, not NULL (NULL can only be used with loading OEM-defined images).Also. you should not be using "magic numbers". The
2onLoadImage()should be replaced with theIMAGE_CURSORconstant, and the32512onSetSystemCursor()should be replaced with theOCR_NORMALconstant.Try this: