Proper way to compare HANDLE and INVALID_HANDLE_VALUE in 64 bit (and 32 bit)?

  • Thread starter Thread starter hector santos
  • Start date Start date
H

hector santos

Guest
I am porting my 32 bit system to 64 bit and I've come across some my thread class code where I was using a macro to compare a handle to INVALID_HANDLE_VALUE when terminating the thread:

#define VH(h) (h != INVALID_HANDLE_VALUE)

The problem is that under 64 bit this is always true. When the thread is closed, this is done:


void CloseThread()
{
if (VH(hThread)) {
HANDLE h = (HANDLE)InterlockedExchange((LPLONG)&hThread, -1);
CloseHandle(h);
}
}

I suppose I need to use a 64 bit InterLockedExchange() consideration, but overall, I thought -1 or INVALID_HANDLE_VALUE in 64 bit is 0xFFFFFFFFFFFFFFFF and not 0x00000000FFFFFFFF?

I suppose I could use 0 here but this is widely used thread class code for a big platform and I need compatibility here. Why is the VH macro not working? What i am missing here?

Thanks







Hector Santos, CTO Santronics Software, Inc. Santronics Software, Inc.

Continue reading...
 
Back
Top