Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 27 Oct 1999 10:23:48 +0400 (MSD)
From:      Alexey Zelkin <phantom@scorpion.crimea.ua>
To:        rivers@dignus.com (Thomas David Rivers), hackers@FreeBSD.org
Subject:   Re: X11/C++ question
Message-ID:  <199910270623.KAA10106@scorpion.crimea.ua>
In-Reply-To: <Pine.BSF.4.10.9910262134050.29073-100000@picnic.mat.net> <199910270142.VAA31089@lakes.dignus.com>

next in thread | previous in thread | raw e-mail | index | archive | help
hi,

>> Does anyone (anyone, that is, who's coded X11 applications) know how you
>> handle X11 callbacks to C++ object methods?
>> 
>> Thanks,

 TDR>  If you mean Xt (and possibly Motif) - the answer is "very carefully."

 TDR>  The Xt callbacks are C based, so you typically can't directly call a 
 TDR>  C++ method.

 TDR>  But, you can have an extern "C" block that declares the call back
 TDR>  function (the extern "C" basically keeps any name mangling from going on)
 TDR>  and then, in that function, invoke the method as appropriate.

 TDR>  I believe you do something like:

 TDR>       class myclass {
 TDR> 	void mymethod(void * arg1) {
 TDR> 		cout << "Ha! I got to the class" << '\n';
 TDR> 	};
 TDR>       }

 TDR>       extern "C" {

 TDR>          void
 TDR>          callback_function(arg1)
 TDR>          void *arg1;
 TDR>          {
 TDR> 	  /* Call the method */
 TDR> 	   myclass::mymethod(arg1);
 TDR>          }

 TDR>       }

Looks good except one point -- mymethod should be static, i.e.

static void mymethod (...) {
  ...
}

 TDR> Then, you register "callback_function" as the Xt/Motif callback.

 TDR> I've at least "heard" of doing that kind of thing before...

-- 
/* Alexey Zelkin                       && phantom@cris.net    */
/* Tavric National University          && phantom@crimea.edu  */
/* http://www.ccssu.crimea.ua/~phantom && phantom@FreeBSD.org */


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199910270623.KAA10106>