Function pointer callback from C

Mike Johnson mrjohnson at
Sun Feb 25 22:12:51 PST 2007


I've been beating my head against D's delegate support. I've probably 
read every mention in the docs and post on the news server multiple 
times and I'm just not getting it. Any help would be awesome.

I'm currently trying to connect a signal handler to a member function.

The member function needs access to the `this' pointer. The callback 
itself works, but I get undefined weirdness and crashes on trying to 
modify any D member variables.

(This is GTK.)

The signal handler is installed:


The function doing black magic:

     extern(C) public void connectSignal(
         char[] signalName,
         void delegate(int* widget, gpointer data) func,
         int data = 0,
         GConnectFlags flags = cast(GConnectFlags) 0) {

                               cast(gpointer) data,
                               cast(int *) 0,

Of course, I can pass void* data through the gpointer variable. But I 
can't convert a class instance to an pointer... which would be really 
*cough* cool *cough* :-) But maybe something else?

The signal handler itself:

     private extern(C) void on_sv_changed(int *widget, int *data) {
	this.changed = true; // GTK spews warnings and dies weirdly

Thanks so much,
Mike Johnson

More information about the Digitalmars-d-learn mailing list