Click here to Skip to main content
15,894,405 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Hello world... please help Pin
Christian Graus13-May-07 22:34
protectorChristian Graus13-May-07 22:34 
GeneralRe: Hello world... please help Pin
Nelek13-May-07 22:53
protectorNelek13-May-07 22:53 
GeneralRe: Hello world... please help Pin
Nelek13-May-07 22:27
protectorNelek13-May-07 22:27 
GeneralRe: Hello world... please help Pin
Nelek13-May-07 20:46
protectorNelek13-May-07 20:46 
GeneralRe: Hello world... please help Pin
David Crow14-May-07 3:27
David Crow14-May-07 3:27 
QuestionHello world... help Pin
WakenDJ13-May-07 17:23
WakenDJ13-May-07 17:23 
AnswerRe: Hello world... help Pin
amets13-May-07 22:53
amets13-May-07 22:53 
QuestionThreadpool Linker Problem Pin
Cyrilix13-May-07 12:35
Cyrilix13-May-07 12:35 
I'm trying to get my code to create a thread pool class that fires off 5 threads and prints the instantiation sequence of the threads right before terminating by raising an event from the spawned thread itself, but I'm getting the following linker errors when compiling with VC8:

1>EventHandler.obj : error LNK2019: unresolved external symbol "private: static class CSource * CThreadPool::source" (?source@CThreadPool@@0PAVCSource@@A) referenced in function "private: static unsigned int __stdcall CThreadPool::DoWork(void *)" (?DoWork@CThreadPool@@CGIPAX@Z)
1>EventHandler.obj : error LNK2019: unresolved external symbol "private: static class CReceiver * CThreadPool::receiver" (?receiver@CThreadPool@@0PAVCReceiver@@A) referenced in function "public: __thiscall CThreadPool::CThreadPool(class CSource *,class CReceiver *)" (??0CThreadPool@@QAE@PAVCSource@@PAVCReceiver@@@Z)

The below is my source code:

#include <stdio.h>
#include <process.h>
#include <windows.h>

[event_source(native)]
class CSource
{
public:
   __event void MyEvent(int nValue);
};

[event_receiver(native)]
class CReceiver
{
public:
   void MyHandler(int nValue)
   {
      printf("Thread %d terminating...\n", nValue);
   }

   void hookEvent(CSource* pSource) 
   {
      __hook(&CSource::MyEvent, pSource, &CReceiver::MyHandler);
   }

   void unhookEvent(CSource* pSource)
   {
      __unhook(&CSource::MyEvent, pSource, &CReceiver::MyHandler);
   }
};

class CThreadPool
{
public:
	CThreadPool(CSource* source, CReceiver* receiver)
	{
		CThreadPool::source = source;
		CThreadPool::receiver = receiver;
		receiver->hookEvent(source);
	}
	~CThreadPool()
	{
		receiver->unhookEvent(source);
	}
	void Initialize()
	{
		SpawnThreads();
	}

private:

	static CSource* source;
	static CReceiver* receiver;

	void SpawnThreads()
	{
		HANDLE hThread[5];
		unsigned threadID[5];

		for (int i = 0; i < 5; i++)
		{
			hThread[i] = (HANDLE)_beginthreadex(0, 0, &CThreadPool::DoWork, (void*)i, 0, &threadID[i]);
		}
	};
	static unsigned int __stdcall DoWork(void* pArgs)
	{
		unsigned int x = 0;
		for (int i = 0; i < 1000000; i++)
		{
			x++;
		}
		__raise CThreadPool::source->MyEvent(*(int*)pArgs);
		return x;
	}
};

int main() {
   CSource source;
   CReceiver receiver;
   CThreadPool* threadPool = new CThreadPool(&source, &receiver);
   threadPool->Initialize();
}

AnswerRe: Threadpool Linker Problem Pin
led mike13-May-07 15:44
led mike13-May-07 15:44 
GeneralRe: Threadpool Linker Problem Pin
Cyrilix13-May-07 16:59
Cyrilix13-May-07 16:59 
QuestionProblem with print function ? Pin
Lewis0113-May-07 10:31
Lewis0113-May-07 10:31 
AnswerRe: Problem with print function ? Pin
bob1697213-May-07 10:57
bob1697213-May-07 10:57 
GeneralRe: Problem with print function ? Pin
Lewis0113-May-07 11:05
Lewis0113-May-07 11:05 
GeneralRe: Problem with print function ? Pin
bob1697213-May-07 11:27
bob1697213-May-07 11:27 
GeneralRe: Problem with print function ? Pin
David Crow14-May-07 3:34
David Crow14-May-07 3:34 
QuestionTrying to use m_strSort with OLE DB Pin
Lewis0113-May-07 10:27
Lewis0113-May-07 10:27 
QuestionMemory leak found after reporting "No memory leaks detected" Pin
dum13-May-07 8:04
dum13-May-07 8:04 
AnswerRe: Memory leak found after reporting "No memory leaks detected" Pin
bob1697213-May-07 9:30
bob1697213-May-07 9:30 
QuestionRe: Memory leak found after reporting "No memory leaks detected" Pin
dum13-May-07 11:16
dum13-May-07 11:16 
AnswerRe: Memory leak found after reporting "No memory leaks detected" Pin
bob1697213-May-07 12:06
bob1697213-May-07 12:06 
QuestionRe: Memory leak found after reporting "No memory leaks detected" Pin
dum13-May-07 12:11
dum13-May-07 12:11 
QuestionRe: Memory leak found after reporting "No memory leaks detected" Pin
dum13-May-07 12:13
dum13-May-07 12:13 
AnswerRe: Memory leak found after reporting "No memory leaks detected" Pin
cmk13-May-07 14:55
cmk13-May-07 14:55 
QuestionRe: Memory leak found after reporting "No memory leaks detected" Pin
dum13-May-07 15:15
dum13-May-07 15:15 
AnswerRe: Memory leak found after reporting &quot;No memory leaks detected&quot; Pin
Mark Salsbery14-May-07 5:09
Mark Salsbery14-May-07 5:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.