无法从UINT32_T*转换为lpdword

Cannot convert from uint32_t* to LPDWORD

本文关键字:转换 lpdword UINT32      更新时间:2023-10-16

我正在尝试调用Windows API函数GetExitCodeProcess,该函数将LPDWORD作为其第二个参数。

根据MSDN,LPDWORD是指向未签名的32位值的指针。因此,我尝试通过uint32_t*,但是编译器(MSVC 11.0)对此不满意:

错误c2664:'getExitCodeProcess':无法将参数2从'uint32_t *'转换为'lpdword'

static_cast也无济于事。这是为什么?在这种情况下,使用reinterpret_cast安全吗?

来自文档:

dword

一个32位未签名的整数。范围为0至4294967295小数。 此类型在intsafe.h中声明如下:

typedef unsigned long DWORD;

所以,LPDWORDunsigned long int*。但是您正在尝试通过unsigned int*。我知道类型指向大小相同的变量,但指针类型不兼容。

解决方案是声明类型DWORD的变量,并传递该变量的地址。这样的东西:

DWORD dwExitCode;
if (!GetExitCodeProcess(hProcess, &dwExitCode))
{
    // deal with error
}
uint32_t ExitCode = dwExitCode;