(Solved) Re: Function pointer callback from C

Mike Johnson mrjohnson at miketec.org
Sun Feb 25 22:45:46 PST 2007

Aw, geez. You're right. Works perfectly. I guess I misunderstood 
something I had read.


For google cache:

connect the signal:

                                         cast(gpointer) this);


     private extern(C) void on_sv_changed(int *widget, gpointer data) {

         GtkSourceView v = cast(GtkSourceView) data;
             v.changed = true;

Tyler Knott wrote:
> Mike Johnson wrote:
>> 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?
> You can't convert /instances/, but you can cast any object /references/ 
> to void pointers (because references are just pointers with syntactic 
> sugar that hides all the details).  When you cast back from void* to a 
> class type, D even checks to make sure it's a sane cast (the cast will 
> return null if it's not sane).  The only caveat is that you're going to 
> be careful to keep a reference to that object in memory the GC is aware 
> of, otherwise it could get prematurely collected and cause weird runtime 
> crashes.

More information about the Digitalmars-d-learn mailing list