
Using Non-Static Callback Functions as member Functions VC5.0
HELP!
Until the release of Visual C++ 5.0, we were able to use member functions
as callback's without declaring them static. From what I have read in the
Microsoft Knowledge Base Article Q148789, the ability to use member
functions as callbacks without making them static was in fact a bug in
Visual C++ 4.0 - 4.2 and that to use a member function in this manner is
against the Ansii C++ standard.
So within Visual C++ 5.0 I must make these callbacks static to get the app.
to run and compile. The limitations caused by the lack of an implied this
pointer in a static function of course makes application design a good deal
more convoluted.
IF ANYONE can tell me how to use a member function as a callback function
without declaring it static, I would greatly appreciate the input. Here is
a sample of what worked in Visual C++ 4.2:
Definitions:
#define RM_PATHPROC FAR __cdecl EXPORT
Function Prototype:
typedef int (RM_PATHPROC * LPMEMBERFN3DPATHPROC)(LPWORLDPARAMST, DWORD,
WORLDPT3DST);
typedef int (RM_PATHPROC * LPFN3DPATHPROC)(C3DAnimationObject *,
LPWORLDPARAMST, DWORD, WORLDPT3DST);
////////////////////////////////////////////////////////////////////////////
/
// C3DFunctionPath - Path is described by a function in world coordinates.
class C3DFunctionPath : public C3DPath, CFunctionPath
{
public:
// Constructors
C3DFunctionPath(LPMEMBERFN3DPATHPROC lpfn3DPathProc, WORLDPT3DST
wpt3dInitial);
C3DFunctionPath(LPFN3DPATHPROC lpfn3DPathProc, WORLDPT3DST wpt3dInitial);
// Implmentation
virtual int UpdatePosition(LPWORLDPARAMST lpWorldParamSt,
C3DAnimationObject * pAniObject);
public:
virtual ~C3DFunctionPath();
protected:
// DWORD dwDeltaTime;
WORLDPT3DST wpt3dInitial; // starting point of path
LPFN3DPATHPROC lpfn3DPathProc;
Quote:
};
At this point a class will be defined to use the LPMEMBERFN3DPATHPROC
ie:
class CCamera : public C3DAnimation
{
.
.
.
C3DFunctionPath *m_pCameraPath_0;
int RM_PATHPROC Camera_Proc_0(LPWORLDPARAMST lpWorldParamSt,
DWORD dwDeltaTime,
WORLDPT3DST wptstInitial);
Quote:
}
Within the body of the implemenation, there will be something like this:
CCamera::CCamera()
{
.
.
.
m_pCameraPath_0 = new C3DFunctionPath(Camera_Proc_0,wptstCameraInitial);
Quote:
}
int RM_PATHPROC CCamera::Camera_Proc_0(LPWORLDPARAMST lpWorldParamSt,
DWORD dwDeltaTime,
WORLDPT3DST wptstInitial)
{
.
.
.
return 0;
Quote:
}
With the above setup I am able to have a member function callback that has
access to all of the member variables of class CCamera through the implied
this pointer. With this I can create multiple objects of this class type,
and have a common callback that is able to access the data members for the
given instance of the object. Using this callback as a control routine is
then very easy to design.
The problem with VC++ 5.0 comes to light by forcing me to make these
callbacks static. Without an implied this pointer I am unable to access
the data members directly and therefore cannot use this callback as a
common control callback for multiple instances of the same object. (I hope
this makes sense!).
Thanks in Advance.
Cliff Kondratiuk, PEng.
Rainmaker Digital Pictures Group.