Hi developers!
This is part of a bigger application written entirely in C++.
This is my first time developing an application of this size in C++, and also my first time using the Win32 APIs implementation of threading.
So of course I was MEANT to run into errors :).
This is what I wish for it to be:
Be as easy to use/implement as that of Java. - And yet provide the flexibility, possible of a C++ program.
This is what I got so far:
thread.h:

#include <windows.h>

struct RUNNABLE{
	virtual void run() = 0;
};

class Thread{
public:
	void start(void* ptr){
		DWORD thread_id;
		HANDLE thr_handl = CreateThread(0, 0, thread_proc, ptr, 0, &thread_id);
		handl = &thr_handl;
	}
private:
	HANDLE *handl;

	DWORD WINAPI thread_proc(LPVOID vpParam){
		((RUNNABLE*)vpParam)->run();
		CloseHandle(handl);
		return 0;
	}
};

& here's an example implementation to test its few features so far:

class MyObject : RUNNABLE{
	virtual void run(){
		for(;;){
			mdia_deref->draw_text("thread", 0, 0);
			dbSync();
		}
	}
};

MyObject *obj = new MyObject();
Thread thread;
thread.start(obj)

This is the error produced by the compiler (MSVC++ 2008 Express Edition):

error C3867: 'Thread::thread_proc': function call missing argument list; use '&Thread::thread_proc' to create a pointer to member

I don't know how to interpret or patch it up, AT ALL, so help is appreciated :)

Best regards,
Benjamin.

Bump.

I've had this same issue with using a class member function for CreateThread.

The ThreadProc parameter to CreateThread() must be either a simple global c-style function or a static method of a c++ class. You can not pass non-static class methods to any win32 api function.

line 12: handl = &thr_handl;

Just what do you expect to accomplish with that statement??? As soon as the function ends the pointer will be invalidated because thr_handl will get auto destroyed.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.