Re: Message between threads

Tech-Archive recommends: Fix windows errors by optimizing your registry



That's the wrong way to do it. You have a graphics thread. That should be
the main thread, not a separate thread created by you manually with
CreateThread. I'm unclear on why you have a GUI thread when *you don't have
a GUI*!

Paul T.

"wceess" <wceess@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:A5B33F3F-6384-4A98-90FE-CDEAA02E6368@xxxxxxxxxxxxxxxx
Hi Paul,

I have pasted my code. I would really appreciate if u could take a look at
it.


#define WM_COMMUNICATION_STATUS 2000
DWORD graphics_thread(LPVOID lpv)
{

MSG msg;
WaitForSingleObject(algorithm_event, 100);
while (GetMessage(&msg,Hwndmain, 0, 0))
{
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}

//Sleep(100);
return 0;
}

DWORD communication_thread(LPVOID lpv)
{
short int j = 0;
while(TRUE)
{
EnterCriticalSection(&csObject1);

for(int i=0; i <=TARGET_TRACKS; i++)
{
target_track[i].data = j++;
if(j == 10)
j=0;
}
Failure_Status = FALSE;
Failure_Id = 0;

LeaveCriticalSection(&csObject1);
PostMessage(Hwndmain,(UNIT)WM_COMMUNICATION_STATUS,(WPARAM)Failure_Status,(LPARAM)Failure_Id);
}
SetEvent(algorithm_event);
return 0;
}

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,int nCmdShow)
{
HANDLE comm_thread;
HANDLE graphic_thread;
DWORD comm_threadid;
DWORD graphic_threadid;

Hwndmain = (HWND) hInstance;

InitializeCriticalSection(&csObject1);

algorithm_event = CreateEvent(NULL, FALSE, FALSE, NULL); // auto reset


comm_thread = CreateThread(NULL,
0,
(LPTHREAD_START_ROUTINE)communication_thread,
(LPVOID*)&csObject1,
0,
&comm_threadid);

graphic_thread =
CreateThread(NULL,0,
(LPTHREAD_START_ROUTINE)graphics_thread,(LPVOID*)&csObject1,0,&graphic_threadid);

CeSetThreadPriority(comm_thread, HIGH_PRIORITY);
CeSetThreadPriority(graphic_thread, LOW_PRIORITY);

while (TRUE)
{
RETAILMSG(3, (_T("-- \n")));
Sleep(1000);
}

DeleteCriticalSection(&csObject1);
return 0;

}


.



Relevant Pages

  • Re: Message between threads
    ... MSG msg; ... DWORD communication_thread(LPVOID lpv) ... int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance, ...
    (microsoft.public.windowsce.embedded)
  • Re: Wait for Multiple objects
    ... Now wait for single object works for both the event but ... DWORD thread2(LPVOID lpv) ... The ret1 is still 87..plz need help ...
    (microsoft.public.windowsce.embedded)
  • Re: Wait for Multiple objects
    ... Wait for both objects in the WaitForMultipleObjects, ... DWORD thread2(LPVOID lpv) ... The ret1 is still 87..plz need help ...
    (microsoft.public.windowsce.embedded)
  • Re: Wait for Multiple objects
    ... Previously when i setevent k1 i waited for ... DWORD thread2(LPVOID lpv) ... The ret1 is still 87..plz need help ...
    (microsoft.public.windowsce.embedded)
  • Re: Wait for Multiple objects
    ... The docs for WaitForMultipleObjects ... DWORD thread2(LPVOID lpv) ... The ret1 is still 87..plz need help ...
    (microsoft.public.windowsce.embedded)