[英]C++: how to convert hexidecimal HANDLE to decimal?
In c++, I get an HANDLE type ID from another function, which appears to be a hexidecimal, and I want to convert it to decimal. 在c ++中,我从另一个函数获取了HANDLE类型ID,该函数似乎是十六进制的,我想将其转换为十进制。
HANDLE id = getCurrentID();
int decimalID = static_cast<int>( id );
But the second line gives out this error: 但是第二行给出了这个错误:
Cannot convert from 'HANDLE' to 'int'.
This is the first time I encountered HANDLE
type. 这是我第一次遇到HANDLE
类型。 Could someone help and explain? 有人可以帮助和解释吗? Thank you. 谢谢。
Update: 更新:
I am using Windows XP and Visual Studio 2010. 我正在使用Windows XP和Visual Studio 2010。
A HANDLE
on Windows is a void pointer. Windows上的HANDLE
是空指针。
To make an int
( unsigned long
etc.) out of it, you cannot use static_cast
, 要使它成为int
( unsigned long
等),您不能使用static_cast
,
you´ll need an reinterpret_cast
. 您将需要一个reinterpret_cast
。
But, any int type is neither hexadecimal nor decimal, just a number 但是,任何int类型既不是十六进制也不是十进制,而只是一个数字
which can be expressed in both ways... 可以用两种方式表达...
I am going to guess that you are on Windows
because HANDLE
is a name that is usually used by Microsoft's stuff. 我猜您在Windows
因为HANDLE
是Microsoft的人员通常使用的名称。
The HANDLE
type is a pointer to an object (of unspecified type), and is passed into other functions to perform operations on that object. HANDLE
类型是指向对象(未指定类型)的指针,并传递给其他函数以对该对象执行操作。 In general, there is not a need to manipulate it directly. 通常,不需要直接对其进行操作。
I am not sure exactly why you want to convert it to an int
, because it is not usually useful to look at, but you can use a C-style cast to do it, or reinterpret_cast
as mentioned in the other answer. 我不确定您为什么要将其转换为int
,因为通常看起来它没有用,但是您可以使用C样式强制转换来实现,也可以像其他答案中提到的那样reinterpret_cast
。
If you want to learn the true types behind these Microsoft type names, you can check out their documentation . 如果您想了解这些Microsoft类型名称背后的真实类型,可以查看其文档 。
HANDLE基本上是void *,即指针类型,如果需要,可以将HANDLE转换为void *然后转换为int
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.