🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.windows.x
Article #38373

Re: C++ and callbacks

#38373
From: Brandon Van Every
Date: Tue, 03 May 1994 18:35
41 lines
2322 bytes
Paul Durbin (pauld@verdix.com) wrote:
: I attempt to use a member function as callback but all three arguments (to the
: callback) are garbage. If I make it a friend then the arguments are correct,
: but then I can't get to the class data, without reference thru an instance of
: the class and I don't want the data to be static.

: So, what is causing this problem? 

Motif is based on C, not C++.  You have to use "extern C" linkage for any of
your callbacks.  You can't register any C++ function directly.  You have to
write a plain C front end for anything you want to have callbacked.


: Could I possibly use the *this pointer as
: the client_data to the callback, then cast to the appropriate class?

Yes.  That's how I do it below.  Write functions like this:


extern "C" void ImageExposeCB(Widget DrawArea,
			      XtPointer Image,
			      XtPointer cbs)
{  
  XmDrawingAreaCallbackStruct *x = (XmDrawingAreaCallbackStruct *)cbs;
  XExposeEvent *e = (XExposeEvent *)(x->event);
  (Image *)Image->Expose(e);

}


Here (Image) is my own C++ object.  What I'm really trying to do, is get my
Image->Expose(e) function to be used as a callback.  (cbs) is a callback
structure provided by Motif.


Cheers,
Brandon

--
Brandon Van Every             "No more LaunchPAD .Sigs!  HA HA HA HA HA HA!!!"
brandon@uncvx2.oit.unc.edu    
Technical Details
Message-ID: <2q65gv$oln@bigblue.oit.unc.edu>
Path: arc1-ca.pugleaf.net!bga.com!news.sprintlink.net!rtp.vnet.net!mary.iia.org!babbage.ece.uc.edu!news.kei.com!eff!news.duke.edu!concert!bigblue.oit.unc.edu!uncvx2!brandon
References: <pauld.767898877@sarge>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 103734,ad5a39011a2d3d26
X-Google-Attributes: gid103734,public
X-Google-Thread: 10ba33,ad5a39011a2d3d26
X-Google-Attributes: gid10ba33,public
X-Google-Thread: 109fba,ad5a39011a2d3d26
X-Google-Attributes: gid109fba,public
X-Google-ArrivalTime: 1994-05-03 13:55:50 PST
Path: arc1-ca.pugleaf.net!bga.com!news.sprintlink.net!rtp.vnet.net!mary.iia.org!babbage.ece.uc.edu!news.kei.com!eff!news.duke.edu!concert!bigblue.oit.unc.edu!uncvx2!brandon
From: brandon@uncvx2.oit.unc.edu (Brandon Van Every)
Newsgroups: comp.windows.x,comp.lang.c++,gnu.g++.help
Subject: Re: C++ and callbacks
Followup-To: comp.windows.x,comp.lang.c++,gnu.g++.help
Date: 3 May 1994 18:35:11 GMT
Organization: The University of North Carolina at Chapel Hill
Lines: 41
Message-ID: <2q65gv$oln@bigblue.oit.unc.edu>
References: <pauld.767898877@sarge>
NNTP-Posting-Host: uncvx2.oit.unc.edu
X-Newsreader: TIN [version 1.2 PL2]