CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Callbacks

  1. #1
    Join Date
    May 1999
    Posts
    136

    Callbacks

    Hi,
    I'm porting some VB code to VC++. Need help, hope this is simple.
    I have a generic file class in VB. It has a function that takes as one of it
    param's a object, specifically a class object...
    MyClass
    MyCallBackFunc()
    ...
    End Function
    Call MyFunc( Me)

    MyFileClass
    MyFunc(obj as Object)
    obj.MyCallBackFunc
    End Function

    Problem: I can't seem to find the proper way to declare the prototypes or
    write the proper code for these functions in VC++. Could someone please
    help?

    Steve Palmer



  2. #2
    Join Date
    May 1999
    Location
    Oregon, USA
    Posts
    302

    Re: Callbacks

    I prefer the typedef approach to this. What I would do is this :

    typedef int (*CallBackFunc)( MyFileClass *mfc );

    int MyFunc( CallBackFunc func, MyFileClass *mfc )
    {
    return (*func)( mfc );
    }

    If you don't need the function as an argument then drop the typedef and use this :

    int MyFunc( MyFileClass *mfc )
    {
    return mfc->MyCallBack();
    }

    or use a reference :

    int MyFunc( MyFileClass & mfc )
    {
    return mfc.MyCallBack();
    }

    Hope this helps, just ask if not.



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured