С++编译错误:“从WCHAR *'转换为'WORD'失去精度” [英] С++ compilation error: "cast from 'WCHAR*' to 'WORD' loses precision"

查看:162
本文介绍了С++编译错误:“从WCHAR *'转换为'WORD'失去精度”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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/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 WNDCLASSX? [Cpp] . Thanks to him - it disappeared.

Thanks beforehand.

解决方案

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.

这篇关于С++编译错误:“从WCHAR *'转换为'WORD'失去精度”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆