Advertisement

DirectDraw callback functions in C++

Started by April 21, 2000 04:00 PM
0 comments, last by seedj 24 years, 8 months ago
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?
.
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

This topic is closed to new replies.

Advertisement