- Oct 30, 2000
- 42,589
- 5
- 0
Situation:
Code in File #1 (Foo) has only access to Foo2 header file (#3)
Foo2 has no knowledge of Foo.
File #1 (Foo.h)
#include "Foo2.h"
class Foo
{
Foo()
int Foo_Callback() {}
};
File #2 (Foo.cpp)
Foo *pFoo;
Foo2 *pFoo2;
LRESULT CALLBACK Foo2_Callback()
{
pFoo->Foo_Callback();
}
Foo::Foo()
{
pFoo = this;
pFoo2->CreateCallbackThread(Foo2_Callback);
}
File #3 (Foo2.h)
class Foo2
{
Foo2()
void CreateCallbackThread(LPVOID pCallbackRoutine);
};
File #4 (Foo2.cpp)
#include "Foo2.h"
static UINT Callback( LPVOID pCallbackRoutine )
{
// single pass after the thread is release
AfxGetThread()->SetThreadPriority(THREAD_PRIORITY_NORMAL);
while (true)
{
AfxGetThread()->SuspendThread();
pCallbackRoutine;
// (*pCallbackRoutine)(); // Compiler is not happy
}
}
Foo2::Foo2() {}
void Foo2::CreateCallbackThread(LPVOID pCallbackRoutine)
{
HANDLE hCallbackThread = AfxBeginThread (Callback, // static thread function
pCallbackRoutine, // parameter from Foo
THREAD_PRIORITY_ABOVE_NORMAL);
}
=======================================================
VC++6.0 Compiler will handle this code.
When executed, Callback in Foo2 skips over pCallbackRoutine.
How do I setup the pCallbackRoutine pointer to be executed in Callback
I can set an array of pointers to the function and index into the array.
The problem seems to be that pCallbackRoutine needs to be properly declared/executed as a function in Callback
Code in File #1 (Foo) has only access to Foo2 header file (#3)
Foo2 has no knowledge of Foo.
File #1 (Foo.h)
#include "Foo2.h"
class Foo
{
Foo()
int Foo_Callback() {}
};
File #2 (Foo.cpp)
Foo *pFoo;
Foo2 *pFoo2;
LRESULT CALLBACK Foo2_Callback()
{
pFoo->Foo_Callback();
}
Foo::Foo()
{
pFoo = this;
pFoo2->CreateCallbackThread(Foo2_Callback);
}
File #3 (Foo2.h)
class Foo2
{
Foo2()
void CreateCallbackThread(LPVOID pCallbackRoutine);
};
File #4 (Foo2.cpp)
#include "Foo2.h"
static UINT Callback( LPVOID pCallbackRoutine )
{
// single pass after the thread is release
AfxGetThread()->SetThreadPriority(THREAD_PRIORITY_NORMAL);
while (true)
{
AfxGetThread()->SuspendThread();
pCallbackRoutine;
// (*pCallbackRoutine)(); // Compiler is not happy
}
}
Foo2::Foo2() {}
void Foo2::CreateCallbackThread(LPVOID pCallbackRoutine)
{
HANDLE hCallbackThread = AfxBeginThread (Callback, // static thread function
pCallbackRoutine, // parameter from Foo
THREAD_PRIORITY_ABOVE_NORMAL);
}
=======================================================
VC++6.0 Compiler will handle this code.
When executed, Callback in Foo2 skips over pCallbackRoutine.
How do I setup the pCallbackRoutine pointer to be executed in Callback
I can set an array of pointers to the function and index into the array.
The problem seems to be that pCallbackRoutine needs to be properly declared/executed as a function in Callback