Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I had a bit of difficulty using LOADCURSOR function in my application. My application uses waring level 4 and treats warnings as errors. Unfortunately, for reasons stated below, visual studio gave compilation warnings. How can I resolve the situation?

The relevant codes and compilation errors are shown below:

C++
HCURSOR hCursor = LoadCursor(hInst, MAKEINTRESOURCE(IDC_WAIT));
        HCURSOR hOldCursor = SetCursor(hCursor);
//some codes loading codes

SetCursor(hOldCursor);




6:13:06:168 1>C:\Users\HP\source\repos\ResultSheets\ResultSheets.cpp(2038,45): warning C4302: 'type cast': truncation from 'LPWSTR' to 'WORD'
16:13:06:168 1>C:\Users\HP\source\repos\ResultSheets\ResultSheets.cpp(2167,53): warning C4302: 'type cast': truncation from 'LPWSTR' to 'WORD'

What I have tried:

I have been thinking about the compiltion error.
Posted
Comments
Graeme_Grant 17-Jan-24 18:42pm    
The message is quite clear. It may be the error is pointing elsewhere in your code. If you comment out those lines does the error go away?
Gbenbam 18-Jan-24 11:11am    
Thanks for your input. The problem was using MAKEINTRESOURCE macro. IDC_WAIT was already deine in terms of MAKEINTrESOURCE as explained below. Using it again amounted to unneccessary repeatition.

1 solution

The error message tells you where in your code the errors occur: line 2038, column 45; and line 2167, column 53 - but your code fragment only shows one of those (probably). Use the editor to go to that line (double click the message in the Errors panel and it'll jump there, or use CTRL+G to go to a specific line number).
Once you know which line which message is associated with you can identify which exact part of that line is being specified. If I had to guess, it would be the MAKEINTRESOURCE call because that macro does various casts which are probably irrelevant here - it's defined as
C++
#define MAKEINTRESOURCE(i) (LPTSTR) ((DWORD) ((WORD) (i)))
And IDC_WAIT is already defined as:
C++
#define IDC_WAIT            MAKEINTRESOURCE(32514)
so it's very likely that if you remove the MAKEINTRESOURCEcall in your code the error will go away.

I'd also guess that you grabbed the code from someone who isn't as fastidious as you: they might ignore warnings which you don't (and neither do I) so never saw it as a problem.
It's also possible to disable specific warnings for a specific chunk of code: warning #pragma | Microsoft Learn[^] if you can find no other way to deal with it.
 
Share this answer
 
Comments
Gbenbam 18-Jan-24 11:04am    
There were so many uses of the load cursor function in the app, but the error messages were all identical, so i copied the first two. Yes, the problem is the MAKEINTRESOURCE. The issue was resolve afterI removed it. Thanks a lot.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900