C ++编译错误:“从'WCHAR *'到'WORD'的广播丢失精度" [英] C++ compilation error: "cast from 'WCHAR*' to 'WORD' loses precision"
问题描述
MyGUI库.
其来源中有一行:
mHandle = (size_t)::LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));
mHandle 是size_t
LoadCursor 返回HCURSOR
.
错误:
D:\Dev\MyGUI_3.2.0_RC1\Common\Input\Win32\ResourceW32Pointer.cpp:48: error: cast
from 'WCHAR*' to 'WORD' loses precision
这是完整资料来源:
www.pastebin.com/gzqLBFh9
Here's the full source:
www.pastebin.com/gzqLBFh9
MinGW编译器.
出现错误cast from 'CHAR*' to 'WORD' loses precision
,并且 selbie 提供了在此处添加宏的建议:
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.
推荐答案
问题实际上出在MAKEINTRESOURCE(IDC_ARROW)
上,与mHandle
的类型无关. [此外:我同意mHandle
不应为size_t
,但我认为这不是您当前的问题.]
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.]
由于IDC_ARROW
被定义为MAKEINTRESOURCE(32512)
,因此该代码实际上应读为
Since IDC_ARROW
is defined to be MAKEINTRESOURCE(32512)
, the code should in fact read
LoadCursor(NULL, IDC_ARROW)
而不是
LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW))
后面的代码失败,因为IDC_ARROW为LPTSTR
,但MAKEINTRESOURCE()
期望为WORD
.这就解释了您看到的错误消息.实际上,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.
同样,对LoadCursor()
的所有其他调用都出错.
Likewise, all the other calls to LoadCursor()
are in error.
这篇关于C ++编译错误:“从'WCHAR *'到'WORD'的广播丢失精度"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!