ok, i have first defined a handle as a private and them i am inititating it in method and again when i try to close it in another method close fails. here is how it is:
class abc{
private:
HANDLE hCom;
public:
initiate();
closeP();
}
abc :: initiate()
{
hCom = CreateFile(pcCommPort, GENERIC_READ, 0, NULL, OPEN_EXISTING, ,..., NULL );
/////////if i call closeP() here it works
}
abc::closeP()
///////but closeP() does not work when i call it otherwise
////// and i always get the message box
{
if ( CloseHandle(hCom) == 0 )
{
MessageBox(NULL, "close failed", NULL, MB_OK);
}
}
why is above?