My application contains RS232 communication. The user should be able to pick which Com port to use. The seriall interface is controlled by a separate thread. When the user pick a Com port from the list an int is stored in the Document corresponding to a Com port. This int has to be passed to the seriall com thread. I have managed to get a pointer to the Document but I get an assertion about access violation when passing the int value.

here is the assertion,
_AFX_INLINE int CString::Compare(LPCTSTR lpsz) const
{ ASSERT(AfxIsValidString(lpsz)); return _tcscmp(m_pchData, lpsz); }

here is the code used in the seriall com thread,

CWinApp* theApp = AfxGetApp();
appPos = theApp->GetFirstDocTemplatePosition();
CDocTemplate* docTemplate = theApp->
GetNextDocTemplate(appPos);
docPos = docTemplate->GetFirstDocPosition();
CGsdoc_b1Doc* pDoc = (CGsdoc_b1Doc*)docTemplat
-> GetNextDoc(docPos);
comPort = pDoc->GetComPort(); //Access violatio!!!
comStr.Format("%s%d", "Com", comPort);