where should I put my AtlWaitWithMessageLoop(hThread); ??????

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: May 2007
Posts: 7
Reputation: amitmistry_petl is an unknown quantity at this point 
Solved Threads: 0
amitmistry_petl amitmistry_petl is offline Offline
Newbie Poster

where should I put my AtlWaitWithMessageLoop(hThread); ??????

 
0
  #1
May 16th, 2007
Can any body help me ???? i face a critcal problem with
AtlWaitWithMessageLoop(hThread);

will actually I don't know much about threading.
but when I put my main thread in wait at that time workerthread will not able to post the message (SendMessage() ) to the Mainthread I know That it is going in the deadlock situation but and I also found the soltuion for that but i dont know exctly where should I fix that code


 
for(int i=0;i<ListBoxItemCount;i++)
{
ListView_GetItemText(hwndListbox,i/*iSelectedFile*/,1,(LPWSTR)&szBuffer,MAX_PATH);
ListView_GetItemText(hwndListbox,i/*iSelectedFile*/,3,(LPWSTR)&szBuffer2,MAX_PATH); 
 
 
string inputFile2= util.ConvertWCHARToString(szBuffer2);
string filenamewithpath = util.ConvertWCHARToString(szBuffer);
string inputFile=inputFile2+"\\"+filenamewithpath;
 
MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,inputFile.c_str(),(int)(inputFile.length() + 1),bufferwithpath,MAX_PATH);
UINT Iselected=ListView_GetSelectedCount(hList);
 
Utility util;
string outputfile=PrepareOutputFile(hDlg,util.ConvertWCHARToString(bufferwithpath));
WCHAR w_Output[MAX_PATH];//=util.ConvertStringToWCHAR(outputfile); 
MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,outputfile.c_str(),(int)(outputfile.length() + 1),w_Output,MAX_PATH);
 
struct argument_list *l ;//[MAX_PATH];
l=(argument_list *)malloc(sizeof(argument_list));
 
l->pszInFile = (LPWSTR) malloc( 2 * wcslen(bufferwithpath) );
wcscpy(l->pszInFile, bufferwithpath);
l->pszOutFil = (LPWSTR) malloc( 2 * wcslen(w_Output) );
wcscpy(l->pszOutFil , w_Output);
 
/* 
l->pszInFile= bufferwithpath; 
l->pszOutFil=w_Output;
*/
 
l->_ProtectSet=_ProtectSet;
l->hList=hList;
strcpy(l->Host,HOST);
l->hwndEncrypt=hwndEncrypt;
l->hWndinoutfiledir=hWndinoutfiledir;
l->hwndParent=hDlg; 
strcpy(l->InitPackageRequest,sINIT_PACKAGE_RESPONSE.c_str()); 
l->Port=PORT;
strcpy(l->ScriptFile,COMMUNICATOR_SCRIPT_FILE_PATH);
strcpy(l->UserID,UserID.c_str());
/*if(i>0)
{
WaitForSingleObject(hThread,INFINITE);
}
*/
 
hThread[i] = (HANDLE ) _beginthreadex(NULL, 0, &Thread, l, 0, &tid); 
 
AtlWaitWithMessageLoop(hThread);
 
// hThread[i]=(HANDLE)_beginthread(&Thread ,0 ,l); 
//WaitForSingleObject(hThread,INFINITE);
} 
 
 
 
 
BOOL AtlWaitWithMessageLoop(HANDLE hEvent)
{
DWORD dwRet;
MSG msg;
while(1)
{
dwRet = MsgWaitForMultipleObjects(1, &hEvent, FALSE, INFINITE, QS_ALLINPUT);
if (dwRet == WAIT_OBJECT_0)
return TRUE; // The event was signaled
if (dwRet != WAIT_OBJECT_0 + 1)
break; // Something else happened
// There is one or more window message available. Dispatch them
while(PeekMessage(&msg,NULL,NULL,NULL,PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
if (WaitForSingleObject(hEvent, 0) == WAIT_OBJECT_0)
return TRUE; // Event is now signaled.
}
}
return FALSE;
}


How can it work for array of Threads ????????

Thread function which call from the loop is here

 
unsigned__stdcall Thread(void* pArguments )
{
if( pArguments == NULL )
{
MessageBox( NULL , _T("Problem in thread") , NULL , IDOK ) ; 
}
 
HRESULT hr=NULL;
struct argument_list *Lparam= (argument_list *)pArguments ;
Package pkg;
static int threadID;
threadID++; 
{
//WaitForSingleObject(GetCurrentThread(),5000);
DWORD ThreadId=GetCurrentThreadId();
hr=pkg.EncodeMediaContent(Lparam->pszInFile,Lparam->pszOutFil,Lparam->hwndParent,Lparam->Host,Lparam->UserID,Lparam->InitPackageRequest,Lparam->ScriptFile,Lparam->Port,Lparam->hList,Lparam->_ProtectSet,Lparam->hWndinoutfiledir,Lparam->hwndEncrypt);
}
if(hr==S_OK)
{ 
MessageBox(0,L"thread gone finished" ,L"therad",0);
_endthreadex( 0 ); 
} 
threadID--; 
return 0;
}
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,381
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1466
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: where should I put my AtlWaitWithMessageLoop(hThread); ??????

 
0
  #2
May 16th, 2007
You don't use SendMessage() to post to a different thread -- use PostThreadMessage() instead
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 7
Reputation: amitmistry_petl is an unknown quantity at this point 
Solved Threads: 0
amitmistry_petl amitmistry_petl is offline Offline
Newbie Poster

Re: where should I put my AtlWaitWithMessageLoop(hThread); ??????

 
0
  #3
May 16th, 2007
Originally Posted by Ancient Dragon View Post
You don't use SendMessage() to post to a different thread -- use PostThreadMessage() instead
ya i knew that but how i use atl function
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,381
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1466
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: where should I put my AtlWaitWithMessageLoop(hThread); ??????

 
0
  #4
May 16th, 2007
>>ya i knew that but how i use atl function
There is no such atl function equivalent. Just use the win32 api function.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC