С++编译错误:“从WCHAR *'转换为'WORD'失去精度” [英] С++ compilation error: "cast from 'WCHAR*' to 'WORD' loses precision"
问题描述
MyGUI库。
其来源中有一行:
mHandle =(size_t):: LoadCursor(NULL,MAKEINTRESOURCE(IDC_ARROW));
mHandle is
size_t
LoadCursor 返回
HCURSOR
。
错误:
D:\Dev\MyGUI_3.2.0_RC1\Common\Input\\ \\ Win32 \ResourceW32Pointer.cpp:48:error:cast
从'WCHAR *'到'WORD'失去精确度
以下是完整来源:
www.pastebin.com/gzqLBFh9
MinGW编译器。
'到'WORD'丢失精确和 selbie 提供了一个建议,在这里添加宏:使用WNDCLASSX创建窗口? [Cpp] 。
解决方案感谢他 - 问题实际上在
MAKEINTRESOURCE(IDC_ARROW)
,与mHandle
的类型无关。 [Aside:我同意mHandle
不应该是size_t
但我认为这不是你当前的问题。 p>
由于
IDC_ARROW
定义为MAKEINTRESOURCE(32512)
代码应该实际上读取LoadCursor(NULL,IDC_ARROW)
而不是
LoadCursor(NULL,MAKEINTRESOURCE(IDC_ARROW))
后面的代码失败,因为IDC_ARROW
LPTSTR
但MAKEINTRESOURCE()
预期WORD
。这解释了您看到的错误消息。事实上IDC_ARROW
已经是资源类型,不需要进一步处理。
同样, code> LoadCursor()有错误。
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/gzqLBFh9MinGW compiler.
There was error
cast from 'CHAR*' to 'WORD' loses precision
and selbie gave an advice to add macro here: Create window with WNDCLASSX? [Cpp] . Thanks to him - it disappeared.Thanks beforehand.
解决方案The problem is actually at
MAKEINTRESOURCE(IDC_ARROW)
and isn't related to the type ofmHandle
. [Aside: I agree thatmHandle
should not besize_t
but I think that is not your current problem.]Since
IDC_ARROW
is defined to beMAKEINTRESOURCE(32512)
, the code should in fact readLoadCursor(NULL, IDC_ARROW)
rather than
LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW))
The latter code fails because IDC_ARROW is
LPTSTR
butMAKEINTRESOURCE()
expectsWORD
. That explains the error message you see. In factIDC_ARROW
is already a resource type and needs no further processing.Likewise, all the other calls to
LoadCursor()
are in error.这篇关于С++编译错误:“从WCHAR *'转换为'WORD'失去精度”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!