Click here to Skip to main content
15,919,358 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: How to use the WMI Class to get hardware/system information? Pin
Viorel.5-Sep-06 3:34
Viorel.5-Sep-06 3:34 
GeneralRe: How to use the WMI Class to get hardware/system information? Pin
HansonDavid5-Sep-06 21:32
HansonDavid5-Sep-06 21:32 
QuestionIncrease the window message priority Pin
helpcode5-Sep-06 2:30
helpcode5-Sep-06 2:30 
AnswerRe: Increase the window message priority Pin
Frank K5-Sep-06 2:42
Frank K5-Sep-06 2:42 
GeneralRe: Increase the window message priority Pin
helpcode6-Sep-06 18:40
helpcode6-Sep-06 18:40 
AnswerRe: Increase the window message priority Pin
ThatsAlok5-Sep-06 2:47
ThatsAlok5-Sep-06 2:47 
AnswerRe: Increase the window message priority Pin
Michael Dunn5-Sep-06 12:31
sitebuilderMichael Dunn5-Sep-06 12:31 
QuestionSerial communication + thread related problem Pin
harsha_12345-Sep-06 2:13
harsha_12345-Sep-06 2:13 
hi all,
i am having one problem with threading

i created one dialog based application whose work is to read the data from serial port and display it.so i created one thred for this work.

means now i got two threads one is application thread and other is serial communication thread which is created in OnInitDialog.

now everything is working i mean the thread got created it read some bytes
from port and now it wants to show the data so need to send this data to main
thread. so i am doing this with ::SendMessage() but it is giving access violation. i don't know why this is happening and currently i am not sending the data also i.e. buffer so please help me
below is code (stepwise)

1)In Oninitdialog
THREADPARAM *ptp = new THREADPARAM;
if(ptp)
{
memset(ptp->array,0,30);
strcpy(ptp->array,"Harshal");
ptp->appHandle = this->m_hWnd;
hSerialThread = CreateThread( NULL,
0,
(LPTHREAD_START_ROUTINE) SerialCommunication,
(LPVOID) NULL,
0,
&dwSerialThreadID);
}



2)Thread function
UINT SerialCommunication(LPVOID pParam)
{
int write_req=0;
THREADPARAM *ptp = (THREADPARAM *)pParam;
while(1)
{
if(write_req == 2)// send write request and read it
{
DWORD length=0;
DWORD dwRead=0;
if (WriteFile(hCom,
SEND_CMD, // pointer to data to write to file
NOOFBYTE, // number of bytes to write
&length, // pointer to number of bytes written
NULL) == 0)
{// write failed
write_req = 0;
continue;
}
// writefile succeeded issue readfile
char buffer[MAX_MESSAGE];
memset(buffer,0,MAX_MESSAGE);
if (!ReadFile(hCom, buffer, MAX_MESSAGE, &dwRead, NULL))
{
write_req = 0;
continue;
}
if(dwRead > 0)
{
//MessageBox(NULL,buffer,"Data with packet",MB_OK);
::SendMessage(ptp->appHandle,MY_SHOW_DATA,0,0);// error is here
}
write_req = 0;
}
else // only read from port and increment counter
{
DWORD dwRead=0;
char buffer[MAX_MESSAGE];
memset(buffer,0,MAX_MESSAGE);
if (!ReadFile(hCom, buffer, MAX_MESSAGE, &dwRead, NULL))
{
write_req++;
continue;
}
if(dwRead > 0)
{// you are in thread you need to send message to
// main application
//char a;
HWND hwnd = (HWND)AfxGetApp()->m_pMainWindow;
::SendMessage(ptp->appHandle,MY_SHOW_DATA,0,0);
//MessageBox(NULL,buffer,"Data without packet",MB_OK);
}
write_req++;

}
}


return 0;
}


3) Sent message function

LRESULT CReadDataDlg::OnShowDataMessage(UINT wParam, LONG lParam)
{
return 0;
}

Thanks and regards
Harshal

AnswerRe: Serial communication + thread related problem Pin
ThatsAlok5-Sep-06 2:50
ThatsAlok5-Sep-06 2:50 
AnswerRe: Serial communication + thread related problem Pin
Blake Miller6-Sep-06 11:49
Blake Miller6-Sep-06 11:49 
QuestionReading error Pin
Anu_Bala5-Sep-06 2:08
Anu_Bala5-Sep-06 2:08 
AnswerRe: Reading error Pin
_AnsHUMAN_ 5-Sep-06 2:12
_AnsHUMAN_ 5-Sep-06 2:12 
GeneralRe: Reading error Pin
Anu_Bala5-Sep-06 2:24
Anu_Bala5-Sep-06 2:24 
GeneralRe: Reading error Pin
_AnsHUMAN_ 5-Sep-06 2:29
_AnsHUMAN_ 5-Sep-06 2:29 
GeneralRe: Reading error Pin
Anu_Bala5-Sep-06 2:38
Anu_Bala5-Sep-06 2:38 
AnswerRe: Reading error Pin
Sebastian Schneider5-Sep-06 3:18
Sebastian Schneider5-Sep-06 3:18 
QuestionDebugging NULL call CTDs Pin
mnelles5-Sep-06 1:55
mnelles5-Sep-06 1:55 
AnswerRe: Debugging NULL call CTDs Pin
Frank K5-Sep-06 2:49
Frank K5-Sep-06 2:49 
GeneralRe: Debugging NULL call CTDs Pin
mnelles5-Sep-06 4:07
mnelles5-Sep-06 4:07 
QuestionCRichEditCtrl link color predefined Pin
YaronNir5-Sep-06 1:44
YaronNir5-Sep-06 1:44 
QuestionPlaySound question Pin
YaronNir5-Sep-06 1:43
YaronNir5-Sep-06 1:43 
AnswerRe: PlaySound question Pin
Hamid_RT5-Sep-06 2:21
Hamid_RT5-Sep-06 2:21 
GeneralRe: PlaySound question Pin
YaronNir5-Sep-06 3:04
YaronNir5-Sep-06 3:04 
QuestionRe: PlaySound question Pin
David Crow5-Sep-06 4:20
David Crow5-Sep-06 4:20 
AnswerRe: PlaySound question Pin
Hamid_RT5-Sep-06 5:33
Hamid_RT5-Sep-06 5:33 

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.