Click here to Skip to main content
15,899,634 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
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 
GeneralRe: Serial Port Asynchronous Reading Pin
sergin802-Sep-05 2:52
sergin802-Sep-05 2:52 
GeneralRe: Serial Port Asynchronous Reading Pin
Cedric Moonen2-Sep-05 3:16
Cedric Moonen2-Sep-05 3:16 
GeneralRe: Serial Port Asynchronous Reading Pin
sergin802-Sep-05 3:49
sergin802-Sep-05 3:49 
GeneralRe: Serial Port Asynchronous Reading Pin
Cedric Moonen2-Sep-05 3:53
Cedric Moonen2-Sep-05 3:53 
QuestionMessage Handlers Pin
Anonymous1-Sep-05 23:49
Anonymous1-Sep-05 23:49 
JokeRe: Message Handlers Pin
Eytukan1-Sep-05 23:56
Eytukan1-Sep-05 23:56 
AnswerRe: Message Handlers Pin
ThatsAlok2-Sep-05 0:05
ThatsAlok2-Sep-05 0:05 
AnswerRe: Message Handlers Pin
Marc Soleda2-Sep-05 1:41
Marc Soleda2-Sep-05 1:41 
GeneralRe: Message Handlers Pin
ThatsAlok2-Sep-05 20:43
ThatsAlok2-Sep-05 20:43 
GeneralRe: Message Handlers Pin
Marc Soleda4-Sep-05 20:33
Marc Soleda4-Sep-05 20:33 
GeneralRe: Message Handlers Pin
ThatsAlok4-Sep-05 21:45
ThatsAlok4-Sep-05 21:45 
QuestionSwitching from console to application window Pin
klboy1-Sep-05 23:15
klboy1-Sep-05 23:15 
AnswerRe: Switching from console to application window Pin
Cedric Moonen1-Sep-05 23:46
Cedric Moonen1-Sep-05 23:46 
GeneralRe: Switching from console to application window Pin
klboy2-Sep-05 0:11
klboy2-Sep-05 0:11 
QuestionHowI compress string into a compressed string? Pin
nk1231-Sep-05 22:38
nk1231-Sep-05 22:38 
AnswerRe: HowI compress string into a compressed string? Pin
HasanMalaysia2-Sep-05 0:23
HasanMalaysia2-Sep-05 0:23 

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.