Posted on 2005-03-02
Medium Priority
Last Modified: 2008-02-01
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?

Question by:Crestline
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 55

Expert Comment

by:Jaime Olivares
ID: 13446648
That's very strange, effectively a handler is a 32 bit value (many times a masked pointer), so this wouldn't cause a warning

HANDLE someHandle = ....... etc.
DWORD parameter = (DWORD)someHandle;

Author Comment

ID: 13446704
This is the warning i get...

warning C4311: 'type cast' : pointer truncation from 'HANDLE' to 'DWORD'

Author Comment

ID: 13446715
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(findWindow, &pid);
HANDLE ph = OpenProcess(PROCESS_ALL_ACCESS, false, pid);
DWORD theDword = (DWORD)ph;
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

LVL 30

Expert Comment

ID: 13446720
Hi Crestline,
Can you post the code to include variable declarations?
LVL 55

Expert Comment

by:Jaime Olivares
ID: 13450886
maybe you can make a test.
try to create a MessageBox with sizeof() DWORD and HANDLE

Accepted Solution

guitaristx earned 150 total points
ID: 13451330
I'll bet the error will go away if you disable the compiler's 64-bit portability warnings.
LVL 14

Expert Comment

ID: 13453320
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.

Author Comment

ID: 13454094
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!

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question