473,847 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Callback functions

Well, I'll try to keep this short and sweet.

I'm trying to use glut which is a toolkit for OpenGL. Inside this
toolkit are a couple of functions that are giving me a slight problem
with trying to add to a class.

Here is the header for the class I would like to make (simplified and
error checking removed):

namespace myGlut {

class glutWindow {

public:

glutWindow();
glutWindow(std: :string name, int x, int y, int w, int h);
void create();
void redraw(int _w, int _h);
void display();
void keyboard(unsign ed char _k, int _x, int _y);
void loop();

private:

std::string title;
int xpos, ypos, width, height;
};
}

Now the details aside the method I'm really looking at here is the
create() method.

Inside this method is a call to a function inside the glut toolkit.
Here is the prototype for that function:

void glutDisplayFunc ( void(*func)() );

Which as I see it, takes an address to a function (function pointer and
all that rot.)

However, the problem is that I would like to pass
myGlut::glutWin dow::display() as the callback function.

therefore in my code I make a call like so:

void glutWindow::cre ate() {

//Some really boring init stuff.
:
:
//Create a window with data members: title, xpos, ypos, width,
height.
:
:
glutDisplayFunc (myGlut::glutWi ndow::display);
:
:
//End of method
}

However, a conversion from void(*)() to void(myGlut::gl utWindow::*)()
is not possible. Making things static, I believe but correct me if I'm
wrong, would solve the conversion but would really defeat the purpose
of making a class in the first place.

Finally, I just wanted to let everyone know that I am aware of C++
toolkits that wrap OpenGL, but I believe that what I'm asking is more
along the lines of a much broader question of how does one pass a
member function to some of the older C style functions that are looking
for a format of type(*)(...), eh?

Thanks for all the help!

:-) Cheers and stuff from justyb's desktop!

Nov 22 '05 #1
1 1969

"slack_just yb" <ju******@gmail .com> wrote in message
news:11******** **************@ g49g2000cwa.goo glegroups.com.. .
However, a conversion from void(*)() to void(myGlut::gl utWindow::*)()
is not possible. Making things static, I believe but correct me if I'm
wrong, would solve the conversion but would really defeat the purpose
of making a class in the first place.

Finally, I just wanted to let everyone know that I am aware of C++
toolkits that wrap OpenGL, but I believe that what I'm asking is more
along the lines of a much broader question of how does one pass a
member function to some of the older C style functions that are looking
for a format of type(*)(...), eh?


This is addressed in the FAQ:
http://www.parashift.com/c++-faq-lit....html#faq-33.2
-Mike
Nov 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
5329
by: Eric Entressangle | last post by:
Hi all, is there any trouble setting an C++ static class method as callback function for a C program or library ? Thanks
5
551
by: Pratik | last post by:
what are callback functions? Where we require callback functions? In what scenario we require callback functions?
11
2477
by: ajay.sonawane | last post by:
Hello ther I read somewhere that callback function should be global or static member function. 1: I could use static member functions but how could I access members of class which ar not static. 2: I could use global function but want to access members of class. Let me know the possible solutions. Regards, Ajay Sonawane
15
2014
by: Felix Kater | last post by:
Hi, in a given library I register callback functions with this function: bool set_callback(int index, int (*callback_function)(long)); I need the callback function to also pass the index which is, however, not (re-)passed by the callback function. Normally, I would just register callback functions for each
4
5912
by: Jimmy | last post by:
I need to use Asynchronous Socket functions in a server application and am learning from sources such as the MSDN2 (http://msdn2.microsoft.com/en-us/library/bbx2eya8.aspx). What I observed is that all callback handlers in examples are static functions. I did try non-static callback handlers; they certainly works, and they usually make my code simpler. For example, a typical tutorial will start an asynchronous connection with:
4
4804
by: Edwin Gomez | last post by:
I'm a C# developer and I'm new to Python. I would like to know if the concept of Asynchronous call-backs exists in Python. Basically what I mean is that I dispatch a thread and when the thread completes it invokes a method from the calling thread. Sort event driven concept with threads. Thanks. Ed Gomez
6
7687
by: smmk25 | last post by:
Before I state the problem, I just want to let the readers know, I am knew to C++\CLI and interop so please forgive any newbie questions. I have a huge C library which I want to be able to use in a .NET application and thus am looking into writing a managed C++ wrapper for in vs2005. Furthermore, this library has many callback hooks which need to be implemented by the C++ wrapper. These callback functions are declared as "extern C...
2
4131
by: Evan Burkitt | last post by:
Hi, all. I have a Windows DLL that exports a number of functions. These functions expect to receive a pointer to a callback function and an opaque void* parameter. The callback functions are typedef'd to take void* parameters, through which the DLL's function passes its void* parameter to the callback function. This allows me to use class instances as callback handlers, as in the example below. //Executable and DLL know this:
1
2424
by: kikivenkat | last post by:
Hi, I understand the concept of function pointers. I am a little confused with the call back functions. 1.If a function is invoked using a function pointer, then does it mean the function invoked is a callback function? 2. Some say that the calling convention used for a callback function is different(__stdcall,PASCAL).However, I see that such calling conventions are used only for callback functions registered with the OS.I dont see...
5
4324
by: Jef Driesen | last post by:
I have a C DLL that I want to use from a C# project. The C header file contains these declarations: typedef void (*callback_t) (const unsigned char *data, unsigned int size, void *userdata); void myfunction (callback_t callback, void *userdata); How do I translate this to C#? I tried with:
0
10983
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10648
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10707
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10341
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9485
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7883
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7056
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5911
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3164
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.