Click here to Skip to main content
15,922,427 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: VC6 -> .NET Pin
mcsherry2-Sep-05 2:54
mcsherry2-Sep-05 2:54 
GeneralRe: VC6 -> .NET Pin
toxcct2-Sep-05 2:59
toxcct2-Sep-05 2:59 
GeneralRe: VC6 -> .NET Pin
mcsherry2-Sep-05 3:18
mcsherry2-Sep-05 3:18 
QuestionUDP Pin
Eytukan2-Sep-05 1:58
Eytukan2-Sep-05 1:58 
GeneralRe: UDP Pin
sunit52-Sep-05 2:33
sunit52-Sep-05 2:33 
Questionexe disappears in 5-10 minutes automatically Pin
rajeevktripathi2-Sep-05 1:27
rajeevktripathi2-Sep-05 1:27 
AnswerRe: exe disappears in 5-10 minutes automatically Pin
Marc Soleda2-Sep-05 1:37
Marc Soleda2-Sep-05 1:37 
GeneralRe: exe disappears in 5-10 minutes automatically Pin
rajeevktripathi2-Sep-05 3:51
rajeevktripathi2-Sep-05 3:51 
GeneralRe: exe disappears in 5-10 minutes automatically Pin
Marc Soleda4-Sep-05 20:31
Marc Soleda4-Sep-05 20:31 
AnswerRe: exe disappears in 5-10 minutes automatically Pin
CWinThread2-Sep-05 8:59
CWinThread2-Sep-05 8:59 
AnswerRe: exe disappears in 5-10 minutes automatically Pin
ThatsAlok2-Sep-05 20:45
ThatsAlok2-Sep-05 20:45 
QuestionRezide dialog based application window Pin
johnnyXP2-Sep-05 0:55
johnnyXP2-Sep-05 0:55 
AnswerRe: Rezide dialog based application window Pin
toxcct2-Sep-05 1:11
toxcct2-Sep-05 1:11 
AnswerRe: Rezide dialog based application window Pin
Marc Soleda2-Sep-05 1:16
Marc Soleda2-Sep-05 1:16 
AnswerRe: Rezide dialog based application window Pin
namaskaaram2-Sep-05 1:16
namaskaaram2-Sep-05 1:16 
GeneralRe: Rezide dialog based application window Pin
johnnyXP2-Sep-05 5:30
johnnyXP2-Sep-05 5:30 
QuestionC Run-Time Library compilation problem Pin
Grant MacDonald2-Sep-05 0:48
Grant MacDonald2-Sep-05 0:48 
QuestionHow to call an Umanaged static library from Managed VC++ DLL?? Pin
smilerays2-Sep-05 0:41
smilerays2-Sep-05 0:41 
QuestionDownload WebBrowser Control?! Pin
bosfan2-Sep-05 0:32
bosfan2-Sep-05 0:32 
AnswerRe: Download WebBrowser Control?! Pin
Marc Soleda2-Sep-05 1:13
Marc Soleda2-Sep-05 1:13 
GeneralRe: Download WebBrowser Control?! Pin
bosfan2-Sep-05 2:29
bosfan2-Sep-05 2:29 
QuestionSerial Port Asynchronous Reading Pin
sergin801-Sep-05 23:52
sergin801-Sep-05 23:52 
AnswerRe: Serial Port Asynchronous Reading Pin
Cedric Moonen1-Sep-05 23:54
Cedric Moonen1-Sep-05 23:54 
GeneralRe: Serial Port Asynchronous Reading Pin
sergin802-Sep-05 1:34
sergin802-Sep-05 1:34 
I always use the debugger to check any errors. In the following, I marked the line where my program is crashing. Please make suggestions that overcome my problem.


#define MAX_BUFF 128
#define TEN_K 10240
#define STRMAX 1024

HANDLE Open_Com;

HANDLE SPEvent;

DCB dcb;
COMMTIMEOUTS CommTimeouts;
OVERLAPPED overlapped;

CWinThread* pComPort;
CSP_AsyncRead_2Dlg *pWnd = ((CSP_AsyncRead_2Dlg*) pComPort);

UINT ReadPort(LPVOID pComPort)
{
BYTE counter=0;

char sMsg[512];
BOOL fSuccess = 0;
DWORD dwEvtMask = 0;
BYTE tmp[16];
int ReadConstant = 1;

Open_Com = CreateFile("COM3",
GENERIC_READ | GENERIC_WRITE, //access (read and write)
0, // 0: cannot share the com port
NULL, // security (None)
OPEN_EXISTING, // creation : open existing
FILE_ATTRIBUTE_NORMAL, // overlapped I/O
NULL); // no templates file for COM port

if (Open_Com == INVALID_HANDLE_VALUE) //check whether the COM port is opened or not
{
AfxMessageBox("Port Acildi");
} // end if (m_hCom == INVALID_HANDLE_VALUE)

if (Open_Com)
{
memset(&dcb,0,sizeof(dcb));
dcb.DCBlength = sizeof ( DCB ) ;
dcb.BaudRate = 9600;
dcb.ByteSize = 8;
dcb.Parity = NOPARITY;
dcb.StopBits = ONESTOPBIT;

SetCommState(Open_Com, &dcb); // guncel dcb sutructure degerlerini yerlestir
SetupComm(Open_Com, MAX_BUFF, MAX_BUFF); // set input and output buffer sizes
fSuccess = SetCommMask (Open_Com, EV_RXCHAR | EV_RXFLAG); // Set the mask for the events you want to listen for

} // end if (Open_Com)
if(fSuccess)
{
while(Open_Com != INVALID_HANDLE_VALUE)
{
int iBytesRead = 0;
DWORD iBytesReadThisTime = 0;
char szData[MAX_BUFF];
BOOL bRead;

WaitCommEvent(Open_Com, &dwEvtMask, 0);

SetCommMask (Open_Com, EV_RXCHAR);
if (dwEvtMask & EV_RXCHAR){
bRead = ReadFile(Open_Com, &tmp, ReadConstant, &iBytesReadThisTime, 0);
iBytesRead += iBytesReadThisTime;
}
tmp[iBytesRead] = '\0';
if(tmp[0] != '\0'){

try
{
pWnd->m_Vreaddata.SetAt(counter++,*tmp);
}
catch(CException* e)
{
AfxMessageBox("Error Occurs!");
e->Delete();
}

} // if(szData[0] != '\0')
}
} //if(fSuccess)

return 0;
}
GeneralRe: Serial Port Asynchronous Reading Pin
Cedric Moonen2-Sep-05 2:02
Cedric Moonen2-Sep-05 2:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.