Click here to Skip to main content
15,896,606 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: about multi threading in visual C++ Pin
mt_samiei5-Sep-06 21:33
mt_samiei5-Sep-06 21:33 
AnswerRe: about multi threading in visual C++ Pin
Viorel.5-Sep-06 20:50
Viorel.5-Sep-06 20:50 
GeneralRe: about multi threading in visual C++ Pin
mt_samiei5-Sep-06 21:31
mt_samiei5-Sep-06 21:31 
QuestionTo add own colors to popup menu [modified] Pin
johnalek5-Sep-06 19:56
johnalek5-Sep-06 19:56 
AnswerRe: To add own colors to popup menu Pin
Hamid_RT5-Sep-06 20:06
Hamid_RT5-Sep-06 20:06 
GeneralRe: To add own colors to popup menu Pin
johnalek5-Sep-06 20:52
johnalek5-Sep-06 20:52 
GeneralRe: To add own colors to popup menu Pin
Hamid_RT5-Sep-06 21:01
Hamid_RT5-Sep-06 21:01 
Questionthread related issue Pin
harsha_12345-Sep-06 19:53
harsha_12345-Sep-06 19:53 
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;
}

4)the handle i am storing in appHandle is right or wrong?
Thanks and regards
Harshal
AnswerRe: thread related issue Pin
Viorel.5-Sep-06 20:31
Viorel.5-Sep-06 20:31 
AnswerRe: thread related issue Pin
ThatsAlok5-Sep-06 22:34
ThatsAlok5-Sep-06 22:34 
QuestionHow to get the window size of a popup window(CHtmlView)? Pin
Tcpip20055-Sep-06 19:43
Tcpip20055-Sep-06 19:43 
AnswerRe: How to get the window size of a popup window(CHtmlView)? Pin
ThatsAlok5-Sep-06 22:35
ThatsAlok5-Sep-06 22:35 
QuestionAPI for Driver Names Pin
velayudhan_raj5-Sep-06 16:32
velayudhan_raj5-Sep-06 16:32 
AnswerRe: API for Driver Names Pin
Stephen Hewitt5-Sep-06 17:51
Stephen Hewitt5-Sep-06 17:51 
AnswerRe: API for Driver Names Pin
ThatsAlok5-Sep-06 18:58
ThatsAlok5-Sep-06 18:58 
GeneralRe: API for Driver Names Pin
Stephen Hewitt5-Sep-06 19:39
Stephen Hewitt5-Sep-06 19:39 
GeneralRe: API for Driver Names Pin
ThatsAlok5-Sep-06 22:33
ThatsAlok5-Sep-06 22:33 
AnswerRe: API for Driver Names Pin
Hamid_RT5-Sep-06 20:20
Hamid_RT5-Sep-06 20:20 
QuestionAssert error Pin
lj_wml5-Sep-06 16:28
lj_wml5-Sep-06 16:28 
AnswerRe: Assert error Pin
Cedric Moonen5-Sep-06 20:44
Cedric Moonen5-Sep-06 20:44 
GeneralRe: Assert error Pin
lj_wml5-Sep-06 23:02
lj_wml5-Sep-06 23:02 
AnswerRe: Assert error Pin
Nibu babu thomas5-Sep-06 23:01
Nibu babu thomas5-Sep-06 23:01 
QuestionSplitter Window Sample Application Pin
velayudhan_raj5-Sep-06 15:57
velayudhan_raj5-Sep-06 15:57 
AnswerRe: Splitter Window Sample Application Pin
Rick York5-Sep-06 16:19
mveRick York5-Sep-06 16:19 
AnswerRe: Splitter Window Sample Application Pin
Hamid_RT5-Sep-06 20:01
Hamid_RT5-Sep-06 20:01 

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.