NOTE: This is a reply to Timerbirds comment, posted as 'answer' simply to make code easier to read
That's the message about the memory leak. I never dealt with handle leaks before, so I'm not sure if, if it says 'memory leak', it can still be a handle leak. Can it?
Detected memory leaks!
Dumping objects ->
{170} client block at 0x0039FC48, subtype c0, 68 bytes long.
a CWinThread object at $0039FC48, 68 bytes long
Below see how I hoped to prevent the leak.
Allocate using new directive in the class constructor.
Deleting again in the deconstructor.
GPSComm::GPSComm()
{
CWinThread* pListeningThread = new CWinThread;
}
GPSComm::~GPSComm()
{
delete pListeningThread;
}
bool GPSComm::startListening()
{
listeningThreadEnd = false;
pListeningThread = AfxBeginThread(listeningThread, this, 0, 0,
CREATE_SUSPENDED, NULL);
pListeningThread->m_bAutoDelete = FALSE;
pListeningThread->ResumeThread();
}
bool GPSComm::stopListening()
{
listeningThreadEnd = true;
WaitForSingleObject( pListeningThread->m_hThread, 5000 );
return true;
}
UINT listeningThread(LPVOID pClassInstance)
{
GPSComm* pInstance = (GPSComm*) pClassInstance;
while(!(pInstance->listeningThreadEnd))
{
}
return 0;
}