From: Nic on
Hello
how can I convert from UINT_PTR to LPVOID?
Thanks.
Nic



From: Igor Tandetnik on
Nic wrote:
> how can I convert from UINT_PTR to LPVOID?

UINT_PTR n = 42;
LPVOID p = reinterpret_cast<LPVOID>(n);

--
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
From: Nic on

"Igor Tandetnik" <itandetnik(a)mvps.org> wrote in message
news:OIKKA%23voKHA.5508(a)TK2MSFTNGP02.phx.gbl...
Nic wrote:
> how can I convert from UINT_PTR to LPVOID?

UINT_PTR n = 42;
LPVOID p = reinterpret_cast<LPVOID>(n);

--
With best wishes,
Igor Tandetnik

Many thanks. This has fixed the problem though I'm not sure why I can't just
do LPVOID(n)?
Nic.


From: David Wilkinson on
Nic wrote:
> UINT_PTR n = 42;
> LPVOID p = reinterpret_cast<LPVOID>(n);
>
> Many thanks. This has fixed the problem though I'm not sure why I can't just
> do LPVOID(n)?

Because UINT_PTR is not a pointer. It is an unsigned integer type with the same
size as a pointer. So you have to do an explicit cast.

--
David Wilkinson
Visual C++ MVP
From: Igor Tandetnik on
Nic wrote:
> "Igor Tandetnik" <itandetnik(a)mvps.org> wrote in message
> news:OIKKA%23voKHA.5508(a)TK2MSFTNGP02.phx.gbl...
> Nic wrote:
>> how can I convert from UINT_PTR to LPVOID?
>
> UINT_PTR n = 42;
> LPVOID p = reinterpret_cast<LPVOID>(n);
>
> Many thanks. This has fixed the problem though I'm not sure why I can't just
> do LPVOID(n)?

You can. Personally, I prefer the notation using type conversion operator, but a functional cast ( LPVOID(n) ) or a C-style cast ( (LPVOID)n ) should both work, too.
--
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