Discussion:
HWND to LPVOID
(too old to reply)
Nic
2010-02-16 23:26:18 UTC
Permalink
Hello

In the VS 2005 I have been using, handles such as HWND and HISTANCE are
defined with DECLARE_HANDLE (..) which concerns me because I have been
casting these handles to LPVOID. Should I be concerned about this?

Thanks in advance
Nic
David Lowndes
2010-02-17 00:08:43 UTC
Permalink
Post by Nic
In the VS 2005 I have been using, handles such as HWND and HISTANCE are
defined with DECLARE_HANDLE (..) which concerns me because I have been
casting these handles to LPVOID. Should I be concerned about this?
Probably, and since you're posting the question, I guess you are :)

Dave
Igor Tandetnik
2010-02-17 00:11:07 UTC
Permalink
Post by Nic
In the VS 2005 I have been using, handles such as HWND and HISTANCE
are defined with DECLARE_HANDLE (..) which concerns me because I have
been casting these handles to LPVOID. Should I be concerned about
this?
I'm not sure I understand the problem. How does the handles being defined with DECLARE_HANDLE hinder your ability to cast them to LPVOID? Come to think of it, _why_ are you casting them to LPVOID in the first place?
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is hard to be sure where they are going to land, and it could be dangerous sitting under them as they fly overhead. -- RFC 1925
Nic
2010-02-17 04:33:01 UTC
Permalink
Post by Igor Tandetnik
Post by Nic
In the VS 2005 I have been using, handles such as HWND and HISTANCE
are defined with DECLARE_HANDLE (..) which concerns me because I have
been casting these handles to LPVOID. Should I be concerned about
this?
I'm not sure I understand the problem. How does the handles being defined
with DECLARE_HANDLE hinder your ability to cast them to LPVOID? Come to
think of it, _why_ are you casting them to LPVOID in the first place?
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily
a good idea. It is hard to be sure where they are going to land, and it
could be dangerous sitting under them as they fly overhead. -- RFC 1925
Thanks Igor and Dave for the reply. In answer to the above question, I have
been looking into the InterlockedExchangePointer function, which requires
casting to LPVOID, as I am declaring a global variable as:'volatile
HINSTANCE ghInstance' in a multithreaded application . However, the variable
is only assigned a values at startup and it is declared as volatile
therefore, I do not think it is necessary to use the
InterlockedExchangePointer function here after all.

Nic
Ulrich Eckhardt
2010-02-17 08:13:25 UTC
Permalink
[...] I have been looking into the InterlockedExchangePointer function,
which requires casting to LPVOID, as I am declaring a global variable
as:'volatile HINSTANCE ghInstance' in a multithreaded application .
However, the variable is only assigned a values at startup and it is
declared as volatile therefore, I do not think it is necessary to use the
InterlockedExchangePointer function here after all.
It is not even necessary to define it as volatile.

Uli
--
C++ FAQ: http://parashift.com/c++-faq-lite

Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932
Tim Roberts
2010-02-18 07:45:12 UTC
Permalink
Post by Nic
In the VS 2005 I have been using, handles such as HWND and HISTANCE are
defined with DECLARE_HANDLE (..) which concerns me because I have been
casting these handles to LPVOID. Should I be concerned about this?
DECLARE_HANDLE basically defines the handles as pointers to incomplete
structures. The standards promise that you can convert a pointer (other
than a pointer to function) to a void pointer and back again.
--
Tim Roberts, ***@probo.com
Providenza & Boekelheide, Inc.
Loading...