Unable to convert from uint32_t * to LPDWORD

I am trying to call the Windows API function GetExitCodeProcess , which takes LPDWORD as the second parameter.

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

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

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

+6
source share
1 answer

From the documentation :

DWORD

32-bit unsigned integer. The range is from 0 to 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 types point to variables of the same size, but pointer types are incompatible.

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

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

All Articles