Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

seedj

DirectDraw callback functions in C++

This topic is 6943 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ive come up against a problem concerning the use of callback functions in a class. I use inheritance to add an errorhandler to my ddraw wrapper classm kinda like class DDrawWrapper: public ErrorHandler { ... }; Now i want to use error handling in a DDraw callback function(like the one for DirectDrawEnumerateEx). The problem is, that the callback function cant be part of the class, since this will cause the compiler to report something like expecting DirectDrawCallback(.......) not DDrawWrapper::DirectDrawCallback(......) but if the callback function isnt part of the class I cant use class functions (like the error handling functions) One solution would be to pass a pointer to the class in the LPVOID context part and declaring the callback function a a friend of the class, but this isnt a very elegant approach. I was wondering if therer is some syntax that would actually allow the callback to be part of the class?

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
quote:
Original post by seedj

Well seedj, it´s in the middle of the night (at least it is here) and my brain is off to bed, but yes there is a more C++ like solution:

Just declare the function as "static" and there will be no problem. Besides the fact, that you´ll need to pass a "this-pointer" to your class, so you can access it´s member.

By the way the reason why it won´t compile, is that C++ is handling over a "secret" this-pointer, which makes the functions parameters different from what DirecX expects; and all you´ll get is a irritating compiler-error.

Now I will sleep.

zzzzzzzzzzzzzzzzzzz

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!