Does this Question Belong in Windows Programming Category?
I believe the following question belongs under Windows Programming Catergory because I am working with multithreading on a windows system.

What OS, Compiler and IDE are you Using?

  • I am developing a console applcation for Windows XP that will be using multithreading
  • I am using Borland C++ Compiler 5.5
  • I am doing this all in Notepad++


What are you Trying to Do?

I have a class that is a singelton that creates, kills and yeilds threads for the most part. With the Create Function I have two parameters for a typedef of a function pointer for the thread I wish to create and a secound parameter for thats thread paratmeter. these parameter get past into the CreateThread function that is inside the function body of my Create function.

What is your Question ( AKA your Problem)?

When I pass my two parameters into the CreateThread parameters I get the resulting error.

This is what the compiler spews out
Code:
C:\Borland\Projects\MUD>bcc32 test
Borland C++ 5.6.4 for Win32 Copyright (c) 1993, 2002 Borland
test.cpp:
Error E2034 MUDThread.h 19: Cannot convert 'void (*)(void *)' to 'unsigned long
(__stdcall *)(void *)' in function MUDThread::Create(void (*)(void *),void *)
Error E2342 MUDThread.h 19: Type mismatch in parameter 'lpStartAddress' (wanted
'unsigned long (__stdcall *)(void *)', got 'void (*)(void *)') in function MUDTh
read::Create(void (*)(void *),void *)
Error E2176 test.cpp 3: Too many types in declaration
Error E2111 test.cpp 4: Type 'MUDThread' may not be defined here
Warning W8070 test.cpp 13: Function should return a value in function PrintThrea
d(void *)
Error E2451 test.cpp 17: Undefined symbol 'ThreadID' in function main()
Error E2379 test.cpp 17: Statement missing ; in function main()
Error E2451 test.cpp 18: Undefined symbol 'a' in function main()
Error E2247 test.cpp 18: 'MUDThread::Create(void (*)(void *),void *)' is not acc
essible in function main()
Error E2283 test.cpp 18: Use . or -> to call 'MUDThread::Create(void (*)(void *)
,void *)' in function main()
Error E2451 test.cpp 19: Undefined symbol 'b' in function main()
Error E2247 test.cpp 19: 'MUDThread::Create(void (*)(void *),void *)' is not acc
essible in function main()
Error E2283 test.cpp 19: Use . or -> to call 'MUDThread::Create(void (*)(void *)
,void *)' in function main()
Error E2247 test.cpp 21: 'MUDThread::WaitForFinish(unsigned long)' is not access
ible in function main()
Error E2283 test.cpp 21: Use . or -> to call 'MUDThread::WaitForFinish(unsigned
long)' in function main()
Error E2247 test.cpp 22: 'MUDThread::WaitForFinish(unsigned long)' is not access
ible in function main()
Error E2283 test.cpp 22: Use . or -> to call 'MUDThread::WaitForFinish(unsigned
long)' in function main()

*** 16 errors in Compile ***
So my problem is that the function I am passing in does not match my typedef. I am unsure as to what I need to change in my typedef so that I dont have this error.

Cannot convert 'void (*)(void *)' to 'unsigned long
(__stdcall *)(void *)'

The obvious difference is that the Thread Function I am trying to convert is using a windows calling convention and is returning a unsigned long. I want my Create function to have the flexiblity to handle, for the most part any type of thread function thrown at it

Also if I haven't noted I am following the MUD Programming Book by Ron Penton.

How can we help if you haven't shown us your Code?

Oh sorry here it is.

test.cpp is the code that is calling MUDThread class.
Code:
#include "MUDThread.h"

void PrintThread( void* data ) 
{
    // convert the data passed in into a character.
    char c = (char)data;

    for( int i = 0; i < 10000; i++ ) 
	{
        cout << c;
        cout.flush();
    }
}

int main() 
{
    MUDThread::ThreadID a, b;
    a = MUDThread::Create( PrintThread, (void*)'a' );
    b = MUDThread::Create( PrintThread, (void*)'b' );

    MUDThread::WaitForFinish( b );
    MUDThread::WaitForFinish( a );

    char c;
    cin >> c;
    return 0;
}

This is the Class that handles creating thread functions, killing and yeilding them.
Code:
#include <windows.h>
#include <map.h>
#include <iostream>
using namespace std;

typedef DWORD ThreadID;
std::map< DWORD, HANDLE > g_handlemap;
typedef void ( *thFunc)(void*); 
 
class MUDThread
{

	// CREATE THREAD
	inline ThreadID Create( thFunc p_func, void* p_param )
	{
		ThreadID t;

		HANDLE h;
		h = CreateThread( NULL, 0, p_func, p_param, 0, &t );
		
		if( h != 0 ) 
			g_handlemap[t] = h; // insert the handle into the handlemap
	}

	// KILL THREAD
	inline void Kill( ThreadID& p_thread )
	{
        TerminateThread( g_handlemap[p_thread], 0 ); //Terminate the thread
        CloseHandle( g_handlemap[p_thread] ); 		 //Close the handle of the thread   
        g_handlemap.erase( p_thread );				 //Remove HANDLE from map
	}
	// GET THREAD ID
	inline ThreadID GetID() 
	{
		return GetCurrentThreadId();
	}
	// WAIT FOR THREAD TO FINISH
	inline void WaitForFinish( ThreadID p_thread ) 
	{ 
        WaitForSingleObject( g_handlemap[p_thread], INFINITE ); //Look up the handle and wait for the thread to finish											
        CloseHandle( g_handlemap[p_thread] );					//Close the handle of the thread  
        g_handlemap.erase( p_thread ); 							//Remove the handle from the map
	}
	// YEILD THREAD
	inline void YieldThread( int p_milliseconds = 1 ) 
	{
        Sleep( p_milliseconds );
	}
	
}

Can you show some respect and do some groveling?

Please I beg of you. Oh Mighty Coders from the North Frigided Ice Lands!, For you are but My only hope to solve my Encumbersome Coding Misfortuntes, And I aplogize for my Awful Use of Gammer and Spelling Mistakes For I am too Dumb to Use a Spell Checker.