C ++ compilation error: "different from" WCHAR * "to" WORD "loses accuracy"

MyGUI library.

There is a line in its sources:

mHandle = (size_t)::LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW)); 

mHandle - size_t

LoadCursor returns HCURSOR .

Error:

 D:\Dev\MyGUI_3.2.0_RC1\Common\Input\Win32\ResourceW32Pointer.cpp:48: error: cast from 'WCHAR*' to 'WORD' loses precision 

Here's the full source:
www.pastebin.com/gzqLBFh9

MinGW compiler.

Error cast from 'CHAR*' to 'WORD' loses precision lost cast from 'CHAR*' to 'WORD' loses precision and selbie gave advice to add a macro here: Create a window with WNDCLASSEX? [Cpp] . Thanks to him, he disappeared.

+4
source share
2 answers

The problem is actually located in MAKEINTRESOURCE(IDC_ARROW) and is not related to the mHandle type. [Also: I agree that mHandle should not be size_t , but I think this is not your current problem.]

Since IDC_ARROW defined as MAKEINTRESOURCE(32512) , the code should really read

 LoadCursor(NULL, IDC_ARROW) 

but not

 LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW)) 

The last code crashes because IDC_ARROW LPTSTR , but MAKEINTRESOURCE() expects a WORD . This explains the error message you see. In fact, IDC_ARROW already a resource type and does not need further processing.

Similarly, all other calls to LoadCursor() erroneous.

+11
source

mHandle should not be WORD - this is completely wrong. A WORD is 16 bits, and size_t usually 32 or 64 bits, depending on the parameters of the compiler, the same size as a pointer with the same parameters. Since 32 and 64 are greater than 16, the compiler complains and does it right.

It seems you have a definition for size_t that is wrong, you should fix it. Then you must redefine mHandle so that it is truly a descriptor, not size_t .

+3
source

All Articles