Crestline
asked on
HANDLE to DWORD
I have a function that needs a DWORD as one of the parameters but I currently have that value in a HANDLE. When I try to cast a HANDLE as a DWORD it says it's getting truncated and I don't get the desired results. Both are unsigned 32-int so I thought that would have been possible.
Any ideas?
Any ideas?
ASKER
This is the warning i get...
warning C4311: 'type cast' : pointer truncation from 'HANDLE' to 'DWORD'
warning C4311: 'type cast' : pointer truncation from 'HANDLE' to 'DWORD'
ASKER
This is the chunk of code... Trying to get the Process Handle (not Process ID) of an application.
DWORD pid;
HWND findWindow = FindWindow("WindowsForms10 .Window.8. app4", NULL);
GetWindowThreadProcessId(f indWindow, &pid);
HANDLE ph = OpenProcess(PROCESS_ALL_AC CESS, false, pid);
DWORD theDword = (DWORD)ph;
DWORD pid;
HWND findWindow = FindWindow("WindowsForms10
GetWindowThreadProcessId(f
HANDLE ph = OpenProcess(PROCESS_ALL_AC
DWORD theDword = (DWORD)ph;
Hi Crestline,
Can you post the code to include variable declarations?
Can you post the code to include variable declarations?
maybe you can make a test.
try to create a MessageBox with sizeof() DWORD and HANDLE
try to create a MessageBox with sizeof() DWORD and HANDLE
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
HANDLE is defined as
typedef void *HANDLE;
This would be 64 bits on a 64-bit OS; casting this to a 32 bit DWORD would generate this error.
guitaristx is spot-on.
typedef void *HANDLE;
This would be 64 bits on a 64-bit OS; casting this to a 32 bit DWORD would generate this error.
guitaristx is spot-on.
ASKER
I turned off 'Detect 64-bit portability issues' and I no longer get the warning. Thanks quitaristx.
Wayside, thanks for the info. I learn something new every day!
Wayside, thanks for the info. I learn something new every day!
HANDLE someHandle = ....... etc.
DWORD parameter = (DWORD)someHandle;