[英]How to convert int to LPBYTE
I need to convert int value to LPBYTE. 我需要将int值转换为LPBYTE。 when I look at the definitions is shows like this.
当我查看定义时就是这样显示的。 I'm not sure what is
far
word says. 我不知道什么是
far
话说。
typedef unsigned char BYTE;
typedef BYTE far *LPBYTE;
Edit 编辑
foo(LPBYTE x){
}
int main()
{
int y = koo();
foo(y); // how to cast here
return 0;
}
Actual code 实际代码
int iVal = 0;
LONG res = RegQueryValueEx(hKey, L"UseSystemSeparators", NULL, &lpType, (LPBYTE)iVal, &size);
If I understand you correctly, you want the address of the variable , and then convert that address to LPBYTE
. 如果我理解正确,则需要该变量的地址 ,然后将该地址转换为
LPBYTE
。
Then you need to use the address-of operator &
on the variable to get a pointer to the variable, and cast that pointer: 然后,您需要在变量上使用address-of运算符
&
以获得指向该变量的指针,并将该指针转换为:
foo(reinterpret_cast<LPBYTE>(&y));
If the variable actually hold an address, then you first of all have to be very careful because it's not guaranteed that
int
can hold a memory address (ie a pointer).
如果变量实际上保存一个地址,那么您首先必须非常小心,因为不能保证
int
可以保存一个内存地址(即一个指针)。
Think for example on a 64-bit system where pointers are 64 bits, but
int
is usually still a 32 bit type.
例如,在指针为64位的64位系统上,但
int
通常仍为32位类型。
Use instead
intptr_t
which is guaranteed to be big enough to hold either an
int
or a pointer.
使用
intptr_t
代替,后者必须足够大以容纳
int
或指针。
Then you should do eg
那你应该做例如
intptr_t y = ...; foo(reinterpret_cast<LPBYTE>(y));
I'm not sure what is far word says.
我不确定说的话到底是什么。
far
is a 32-bit pointer which consists of 16-bit 'selector' that helps in determining the start address of the memory region, and a 16-bit offset into the memory region. far
是一个32位指针,该指针由有助于确定存储区起始地址的16位“选择器”和进入存储区的16位偏移量组成。
You can cast your variable like this: 您可以像这样转换变量:
int main()
{
int y = koo();
foo(static_cast<LPBYTE>(&y));
return 0;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.