Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ compilation error: "cast from 'WCHAR*' to 'WORD' loses precision"

Tags:

c++

mingw

winapi

MyGUI library.

There's a line in its sources:

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

mHandle is 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.

There was error cast from 'CHAR*' to 'WORD' loses precision and selbie gave an advice to add macro here: Create window with WNDCLASSEX? [Cpp] . Thanks to him - it disappeared.

like image 465
Ben Usman Avatar asked Jul 26 '11 19:07

Ben Usman


1 Answers

The problem is actually at MAKEINTRESOURCE(IDC_ARROW) and isn't related to the type of mHandle. [Aside: I agree that mHandle should not be size_t but I think that is not your current problem.]

Since IDC_ARROW is defined to be MAKEINTRESOURCE(32512), the code should in fact read

LoadCursor(NULL, IDC_ARROW)

rather than

LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW))

The latter code fails because IDC_ARROW is LPTSTR but MAKEINTRESOURCE() expects WORD. That explains the error message you see. In fact IDC_ARROW is already a resource type and needs no further processing.

Likewise, all the other calls to LoadCursor() are in error.

like image 63
David Heffernan Avatar answered Oct 06 '22 01:10

David Heffernan