Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Multi Thread Program Not Working Window ME

This topic is 5461 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello I have a problem that I needed help for like 3 weeks. Im going to write a text base game similar to a MUD but it is for one player only so I my program a SUD (Single User Dungeon). Anyway Im found a basic multi thread example that runs on the command prompt. But for some reason It doesnt run for me correctly. It runs perfectly on two computers that have Windows XP Pro but it not working ok my computer which is running Window Me. Im using Visual C++ 6 and Im doing the program in C++. When you run the program your out put should be this: Intro to Windows Threading by redKlyde HAHAH!!!! This is me ... the thread ... I am running!! Press any key to continue . . . And this works perfectly on Windows XP Pro but when I run it on my computer it outputs this: Intro to Windows Threading by redKlyde Press any key to continue . . . Im not sure why this is happening all the functions that I used is compatible with Windows Me and it works on Windows XP Pro so why wouldnt it work on my computer that runs Windows Me. I thought it had something to do with something installed or something so I formated my hard drive and tried to compile the program again but it still didnt work. The program doesnt work right on Dev C++ 4 either. I hope some one could find out whats wrong with my program. Some one please help me Thanks in Advance Franklin!!. By the way this is the source of the program that''s not working. #include <iostream> #include <windows.h> #include <stdlib.h> using namespace std; void threadProc() { cout << "HAHAH!!!! This is me ... the thread ... I am running!!\n"; } void main() { cout << "Intro to Windows Threading by redKlyde\n"; HANDLE threadHandle; threadHandle = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) threadProc, NULL, 0, NULL); WaitForSingleObject(threadHandle, INFINITE); system("pause"); }

Share this post

Link to post
Share on other sites
You mean you found something that DOES work under Windows ME?

Now, in all seriousness. WinME is based on Windows 98. It says in the MSDN docs that the last parameter, lpThreadID, the address of a WORD (32-bit unsigned integer), may not be NULL, when running under Win95/98. Under NT (read; Win2000 and WinXP), it simply does not use this parameter if you pass NULL.

After the function runs, *lpThreadID will contain the thread ID of the new process.

The important half of the MSDN page follows...

HANDLE CreateThread(
LPSECURITY_ATTRIBUTES lpThreadAttributes, // pointer to security attributes
DWORD dwStackSize, // initial thread stack size
LPTHREAD_START_ROUTINE lpStartAddress, // pointer to thread function
LPVOID lpParameter, // argument for new thread
DWORD dwCreationFlags, // creation flags
LPDWORD lpThreadId // pointer to receive thread ID

=== Parameters ===
+ Pointer to a SECURITY_ATTRIBUTES structure that determines whether the returned handle can be inherited by child processes. If lpThreadAttributes is NULL, the handle cannot be inherited.
+ Windows NT: The lpSecurityDescriptor member of the structure specifies a security descriptor for the new thread. If lpThreadAttributes is NULL, the thread gets a default security descriptor.

+ Specifies the initial commit size of the stack, in bytes. The system rounds this value to the nearest page. If this value is zero, or is smaller than the default commit size, the default is to use the same size as the calling thread. For more information, see Thread Stack Size.

+ Pointer to the application-defined function of type LPTHREAD_START_ROUTINE to be executed by the thread and represents the starting address of the thread. For more information on the thread function, see ThreadProc.

+ Specifies a single 32-bit parameter value passed to the thread.

+ Specifies additional flags that control the creation of the thread. If the CREATE_SUSPENDED flag is specified, the thread is created in a suspended state, and will not run until the ResumeThread function is called. If this value is zero, the thread runs immediately after creation. At this time, no other values are supported.

+ Pointer to a 32-bit variable that receives the thread identifier.
+ Windows NT: If this parameter is NULL, the thread identifier is not returned.
+ Windows 95 and Windows 98: This parameter may not be NULL.

So, just make this change to your code...

WORD nThread;
threadHandle = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) threadProc, NULL, 0, &nThread);

[edited by - Wyrframe on October 10, 2003 3:41:27 AM]

Share this post

Link to post
Share on other sites
Man I cant believe I missed that I read that Webpage 50 times and I missed that part about cant be NULL on Win95/98. But I have one problem I made the changed and got this error.

C:\Windows\All Users\Desktop\Thread\main.cpp(19) : error C2664: ''CreateThread'' : cannot convert parameter 6 from ''unsigned short *'' to ''unsigned long *''
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.

Im not sure on how to change WORD nThread to a unsigned long but if you could tell me how that would be great help and thank you cause your the first person for weeks that showed me what was really wrong with my program.

Share this post

Link to post
Share on other sites
Some reason that cast thing wasnt working or I didnt get it right but then I read the MSDN for CreateThread and it said that the last paramater should be LPDWORD data type and I used it but the program still didnt work. And with the begin thread some reason it wouldnt allow me to use any C++ functions or output.

Share this post

Link to post
Share on other sites
Thank you so much for your help every one it finally worked. Using DWORD solved my problem a whole lot thank you. I can finally start and finish my program thanks again.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!