I am trying to figure out why I am getting an "Access Denied" error when I try to open a serial port. It happens when I try to recreate an instance of a serial port. The first time is okay. (Overlapped read/write done in a thread.)

It suggests that when I close the object I don't shut down the serial port correctly. At the end of the thread I reset the port with the original configuration and timeout values and then call that purge routine. Then I close the handle of the port.

This problem only happens on my laptop...not my desktop.

Heres the code at the end of the thread.

Code:
    CloseHandle(overlappedread.hEvent);
    CloseHandle(overlappedevent.hEvent);
    CloseHandle(overlappedwrite.hEvent);
	CloseHandle(quitthread);

	PurgeComm(commhandle, 
                   PURGE_TXABORT | PURGE_RXABORT | PURGE_TXCLEAR | PURGE_RXCLEAR);

//--- RESTORE OLD TIMELIMITS:---------------------------------------------------
    if(SetCommTimeouts(commhandle, &original_timeouts) == FALSE)
	{
		error = GetLastError();
		return(FALSE);
	}
//--- RESTORE OLD CONFIGURATION:------------------------------------------------
    if(SetCommConfig(commhandle, &original_config, sizeof(COMMCONFIG)) == FALSE)
	{
		error = GetLastError();
		return(FALSE);
	}

	CloseHandle(commhandle);
	commhandle = NULL;
	commthread = NULL;
    return(1);
Any ideas?

Thanks,

Brian