Reputation: 2403
In the documentation for GetQueuedCompletionStatus(), MSDN says
This is done by specifying a valid event handle for the hEvent member of the OVERLAPPED structure, and setting its low-order bit.
How do I do this with a C++-style cast, given that the event is of type HANDLE, a typedef of void *? I can't directly apply |= 1 to the pointer, reinterpret_cast converts between types with the same level of indirection only, and static_cast also doesn't work. What's the C++ way of doing this, avoiding C-style casts and using C++-style ones to convert to size_t? I know the alternative is to use a union but that seems even more of a hack than using C-style casts.
Upvotes: 1
Views: 2109
Reputation: 3156
reinterpret_cast is what you need:
OVERLAPPED MyOverlapped;
// ...
MyOverlapped.hEvent = GetEvent(); // replace with whatever O/S call that is provided the event handle
ASSERT((reinterpret_cast<uintptr_t>(MyOverlapped.hEvent) & 0x1) == 0x0); // if lsbit is a flag, then OS source of hEvent better NOT have it INITIALLY set!
reinterpret_cast<uintptr_t &>(MyOverlapped.hEvent) |= 0x1;
// ...
GetQueuedCompletionStatus(..., &MyOverlapped, ...);
Upvotes: 4