Win32 threads

Started by
18 comments, last by LastResort 21 years, 5 months ago

  DWORD WINAPI ActualizaStatus(LPVOID param){    MessageBox(NULL,"THIS SHOULD WORK ON 98","Nice Thread",MB_OK)}  


This doesnt work
Advertisement
quote:Original post by LastResort
It ends when the app ends..


The process doesn''t end until the threads end and this:


  ...while(1){  WaitForSingleObject(hTimer,INFINITE);  StatusReport((HWND)param); // unimportant function}  


doesn''t end.

It also looks like your not linking with the multithreaded runtime libraries. This may have been the problem all along (however _beginthreadex should always be used over CreateThread).
// Ryan
I can always change while(1) by while(RUNNING) or something.. that was just an example.. I have other threads that do their job and end before the process ends. But, when the app ends, so does the process, wich means, all current threads end.. even if they are on a while(1). Correct me if im wrong

quote:
It also looks like your not linking with the multithreaded runtime libraries. This may have been the problem all along (however _beginthreadex should always be used over CreateThread).


What multithreaded runtime libraries?
Using #pragma to set the C runtime library won''t work. You have to go into project settings, and change it from there. It''s in the C/C++ language / code generation bit.

Sorry I can''t be more precise - I don''t have MSVC on this machine.

Helpful links:
How To Ask Questions The Smart Way | Google can help with your question | Search MSDN for help with standard C or Windows functions
To use multithreaded libraries in MSVC:

1) Click "Project" and then "Settings".
2) Click the "C/C++" tab.
3) From the Category drop down choose "Code Generation".
4) Choose an appropriate library for your project under "Use Run-time Library".


quote:
I can always change while(1) by while(RUNNING) or something.. that was just an example.. I have other threads that do their job and end before the process ends. But, when the app ends, so does the process, wich means, all current threads end.. even if they are on a while(1). Correct me if im wrong


Actually you''re right and I''m wrong. Somehow I got the idea that a running thread will keep the process alive (probably because I usually wait for my worker threads to end before I allow the primary thread to exit). MSDN says the opposite and so did the test I ran. Anyway, you should still allow the thread to exit in a controlled fashion. If another thread (like the primary thread) releases resources used by StatusReport() during shutdown (like HWND''s of windows that have been closed) your runnaway thread could generate errors.
// Ryan
Change your filename from .c to .cpp.
MSVC was moaning at me today for that.

HTH, Steve

Steve
DirectX Programmer
Soon to be the new Bill Gates
Member of the Unban Mindwipe Society (UMWS)
Ok, I guess this actually falls under the RT(F)M category:
The last parameter of CreateThread can''t be NULL under Win9x.
HardDrop - hard link shell extension."Tread softly because you tread on my dreams" - Yeats
quote:Original post by Solo
Actually you''re right and I''m wrong. Somehow I got the idea that a running thread will keep the process alive (probably because I usually wait for my worker threads to end before I allow the primary thread to exit). MSDN says the opposite and so did the test I ran. Anyway, you should still allow the thread to exit in a controlled fashion. If another thread (like the primary thread) releases resources used by StatusReport() during shutdown (like HWND''s of windows that have been closed) your runnaway thread could generate errors.


Your very right.. we should always avoid nasty errors

Anyway, as soon as i get home ill try that (the multithreaded libraries).

quote:Original post by DigitalDelusion
Ok, I guess this actually falls under the RT(F)M category:
The last parameter of CreateThread can''t be NULL under Win9x.


Ill try that also

Evil Bill, ill try that one more time hehehe

Thaks all for the help
Well, DigitalDelusion you are right, it cant be NULL..
It works, finaly, with or without the run time libs.
Thanks to you all


  ...LONG thread_id;CreateThread(NULL,0,ActualizaStatus,(HWND)hWnd,0,&thread_id);...  


Bye
glad I could help
HardDrop - hard link shell extension."Tread softly because you tread on my dreams" - Yeats

This topic is closed to new replies.

Advertisement