简体   繁体   中英

Cannot convert from uint32_t* to LPDWORD

I'm trying to call the Windows API function GetExitCodeProcess which takes a LPDWORD as its second parameter.

According to MSDN , LPDWORD is a pointer to an unsigned 32-bit value. So I tried to pass a uint32_t* , but the compiler (MSVC 11.0) is not happy with it:

error C2664: 'GetExitCodeProcess' : cannot convert parameter 2 from 'uint32_t *' to 'LPDWORD'

Also a static_cast does not help. Why is that? And is it safe to use a reinterpret_cast in this case?

From the documentation :

DWORD

A 32-bit unsigned integer. The range is 0 through 4294967295 decimal. This type is declared in IntSafe.h as follows:

 typedef unsigned long DWORD; 

So, LPDWORD is unsigned long int* . But you are trying to pass unsigned int* . I know that the types point to variables that are the same size, but the pointer types are not compatible.

The solution is to declare a variable of type DWORD , and pass the address of that variable. Something like this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM