Sign in to follow this  
WuTz

Callbacks from Class-Funktions?

Recommended Posts

Hi! I‘ve got a simple question: Can I make use of callback-functions in classes? Something like this:

MyCallback=Browser::BrowserFunc;

MSVC++ returns an Error to me if I do it that way... -In addition to that: A friend of mine is not able to open any GameDev.net page. Evertyime occurs a strange 'domain-for-sell' page :( Do you know whether anybody else have the same problem?

Share this post


Link to post
Share on other sites
You sohuld probably post the error. You should use the address-of operator to yeild a pointer-to-member function. It is also possible that your type declaration for "MyCallback" is incorrect.

Its always a good idea to try post a minimal example that fails to compile.

Share this post


Link to post
Share on other sites
Sorry, I forgot about this problem. I did something else, because that stuff was non workinh. And now I am again at this problem. Here is some Example code:


//This is what I want to do:
ToolWindow Browser; //Global
Browser.wb.MyVars.MsgProc=(LPMSGPROCCALLBACK)Browser.wb.TheFunc;

...

//here is the (very simplified) browser-class:
class ToolWindow
{
public:
ToolWindow(void);
~ToolWindow(void);

WD2DWindow wb; //wb = [w]browser
}

...

//This is the "TheFunc"-Function of the (simplified)WD2DWindow-Class:
class WD2DWindow
{
public:
WD2DWindow(void);
~WD2DWindow(void);

InputStruct MyVars;
void CALLBACK TheFunc(UI_Item* Item,UINT Msg){} //Empty, just a test
}

...

//Here is the Input-Struct and the Callback-Typedef:
typedef void (CALLBACK *LPMSGPROCCALLBACK)(UI_Item* Item,UINT Msg);
struct InputStruct
{
ID2D1SolidColorBrush* BlackBrush;
ID2D1SolidColorBrush* WhiteBrush;
ID2D1SolidColorBrush* Brush;
ID2D1LinearGradientBrush* LinearBrush;
IWICImagingFactory* ImageFactory;

ID2D1HwndRenderTarget* RT;
ID2D1Factory* D2DFactory;
bool bNeedsReDraw;
POINT MousePos;
LPMSGPROCCALLBACK MsgProc; //<--------------
SharedParameters* Params;
HWND MyWindow;
IDWriteFactory* WriteFactory;
IDWriteTextFormat* WriteTextFormat;

};






It just works perfectly with function which aren't in classes. :(

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this