Click to See Complete Forum and Search --> : simplest thread program doesn't work


Organize
September 7th, 2005, 04:39 AM
DWORD WINAPI tredu (LPVOID lpParam );


int APIENTRY WinMain(HINSTANCE a,HINSTANCE b,LPSTR

comanda,int arata)
{

HANDLE hThread;
DWORD dwID,dwThrdParam = 1;
hThread = CreateThread (NULL, 0,tredu ,&dwThrdParam,

0, &dwID);
if (hThread==NULL)
MessageBox(0,"a","a",MB_OK);

return 0;
}

DWORD WINAPI tredu (LPVOID lpParam )
{
Beep(1000,1000);
MessageBox(0,"a","b",MB_OK);
return 0;
}



this does nothing?
where am I going wrong
I am using VC 7.0

PadexArt
September 7th, 2005, 04:54 AM
There are 2 problems with your current code:
1. you are trying to perform UI operations from a worker thread ( not safe)
2. you are not waiting for the second thread to finish. orhpan threads might can cause various problems in your app later on. In your case the 1st nuisance is that you do not see the thread's output. To fix that you should wait for the thread:


// in winmain
if (hThread==NULL)
MessageBox(0,"a","a",MB_OK);
else
WaitForSingleObject( hThread, INFINITE);


PS: biata hinstance merita un nume mai bun decat a :)

Marc G
September 7th, 2005, 01:44 PM
[ moved thread ]