| | |
where should I put my AtlWaitWithMessageLoop(hThread); ??????
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: May 2007
Posts: 7
Reputation:
Solved Threads: 0
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
How can it work for array of Threads ????????
Thread function which call from the loop is here
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; }
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.
•
•
Join Date: May 2007
Posts: 7
Reputation:
Solved Threads: 0
•
•
•
•
You don't use SendMessage() to post to a different thread -- use PostThreadMessage() instead
![]() |
Similar Threads
- Did Hubby Put Spyware on My PC??! (Viruses, Spyware and other Nasties)
- Where I have to put my... (PHP)
- How do I put up an icon? (Geeks' Lounge)
- how do i put message boards on my site?? please help!! thanx (JavaScript / DHTML / AJAX)
- Manually Put Your Computer into Hibernation (Windows tips 'n' tweaks)
Other Threads in the C++ Forum
- Previous Thread: a few win32 bitmap loading question
- Next Thread: Question on Book
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count data database delete deploy developer dll download dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings struct temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






