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

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

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

Thread function which call from the loop is here

[B]unsigned__stdcall Thread(void* pArguments )[/B]
[B]{[/B]
[B]if( pArguments == NULL )[/B]
[B]{[/B]
[B]MessageBox( NULL , _T("Problem in thread") , NULL , IDOK ) ; [/B]
[B]}[/B]
 
[B]HRESULT hr=NULL;[/B]
[B]struct argument_list *Lparam= (argument_list *)pArguments ;[/B]
[B]Package pkg;[/B]
[B]static int threadID;[/B]
[B]threadID++; [/B]
[B]{[/B]
[B]//WaitForSingleObject(GetCurrentThread(),5000);[/B]
[B]DWORD ThreadId=GetCurrentThreadId();[/B]
[B]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);[/B]
[B]}[/B]
[B]if(hr==S_OK)[/B]
[B]{ [/B]
[B]MessageBox(0,L"thread gone finished" ,L"therad",0);[/B]
[B]_endthreadex( 0 ); [/B]
[B]} [/B]
[B]threadID--; [/B]
[B]return 0;[/B]
[B]}[/B]

You don't use SendMessage() to post to a different thread -- use PostThreadMessage() instead

You don't use SendMessage() to post to a different thread -- use PostThreadMessage() instead

ya i knew that but how i use atl function

>>ya i knew that but how i use atl function
There is no such atl function equivalent. Just use the win32 api function.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.