Using Non-Static Callback Functions as member Functions VC5.0 
Author Message
 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.



Tue, 21 Sep 1999 03:00:00 GMT  
 Using Non-Static Callback Functions as member Functions VC5.0


Quote:
>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:

No it is not possible.

[sample code deleted]

Quote:

>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!).

You can accomplish this by explicitly passing a pointer to the object as one
of the parameters, then call the member function of that object.

--------------------------------------------------------------------------------


XIOtech Corporation               Personal Home Page:   http://www.visi.com/~nde
Eden Prairie, MN

"Question authority...and the authorities will end up questioning YOU!"
--------------------------------------------------------------------------------



Tue, 21 Sep 1999 03:00:00 GMT  
 Using Non-Static Callback Functions as member Functions VC5.0



Quote:
> 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.

Sorry, but I think you're out of luck.

As you implied, it was simply an error of Microsoft that allowed your
non-static member functions to be used as callbacks in Visual C++ 4.x.
Microsoft is continually improving their ANSI compliance in Visual C++, and
this is an issue that they didn't let slip through the cracks with Visual
C++ 5.0.
--
Jeff Ferguson, MCPS/WOSSA
Logicon Technologies International
http://www.logicontech.com/
http://www.toto.com/JeffFerguson/



Wed, 22 Sep 1999 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Getting pointer to non-static member function from C callback function

2. Using Non-Static Callbacks as member functions VC 5.0

3. CALLBACK and non-static member function problem!

4. using non-static member functions using delegates

5. One Problem in Calling Static function from Non static function

6. Accessing non-static functions from a static function

7. static function access member variable and member function

8. template member function - non template class - VC5 - error

9. illegal call of non-static member function

10. illegal call of non-static member function

11. illegal call of non-static member function *HELP*

12. iilegal call of non-static member function

 

 
Powered by phpBB® Forum Software