From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,8a3b943d6cda9a77 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local01.nntp.dca.giganews.com!nntp.comcast.com!news.comcast.com.POSTED!not-for-mail NNTP-Posting-Date: Thu, 05 May 2005 22:17:31 -0500 From: "Steve" Newsgroups: comp.lang.ada References: Subject: Re: Importing and using a C++ class in Ada. Pragma Cpp_Constructor,Cpp_Class Date: Thu, 5 May 2005 20:20:08 -0700 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-RFC2646: Format=Flowed; Original Message-ID: NNTP-Posting-Host: 24.22.63.157 X-Trace: sv3-XCiFXs4yt0bMp6Cw6Th3QHaEPxIg264LlKx18WdfUioN5L/X+xmzOshgRBIIGw/7kUyPunc3ofs+4V8!fD7RxpJjMGV7kZaaPJzHenlNUBx3v8DBjd0ZjBivcYIGRLYTaGMIXrb9Wqq5 X-Complaints-To: abuse@comcast.net X-DMCA-Complaints-To: dmca@comcast.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.31 Xref: g2news1.google.com comp.lang.ada:10937 Date: 2005-05-05T20:20:08-07:00 List-Id: I have interfaced Ada with C++ classes, but the technique I used wasn't particularly pretty. Before I say anything about that, have you considered making your C++ code into a COM object and then using GNATCOM to generate bindings to the object? To make the not so pretty interface I set up a non-member equivalent for each method in the C++ class I wanted to call from Ada. In addition to the arguments for the method, I explicitly passed the value of the "this" pointer of the object to the member function. The member function would then turn around and call the member function via the this pointer. Like I said, not pretty, but it works. In the C++ code I set up a table of structures, where each structure contains: The name of the routine The signature of the routine A pointer to a static function that will call the member function. During initialization I called a "register_callbacks" function in the Ada code with the list of structures. In the Ada code I set up a function pointer to each of the callback routines. The register_callbacks routine sets up a list of pointers to functions based on a match on the function name and signature. I also set up a tagged type on the Ada side to mirror each object instance on the C++ side. The base tagged type contains the "this" pointer for the C++ object instance. A procedure or function for the tagged type corresponding to each C++ method, and calls the methods in the C++ code using the "this" pointer. Like I said. It's not pretty but it works. BTW: It isn't as ugly as it sounds, but it is certainly not as easy as being able to "just use it". IMHO the gain of using Ada is worth the effort. Steve (The Duck) "Christopher Gosset" wrote in message news:mailman.108.1115327462.24457.comp.lang.ada@ada-france.org... I need to use some classes from a DLL in my Ada app. I was hoping that this was a straigthforward thing to do using pragma import and pragma cpp_class and cpp_constructor. Is there a working example of this somwhere. I am building the damn dll myself and I am also buliding the damn .def file myself but the damn thing will still not work. Functions that are not class members are no problem this works perfect! Are there any tutorials, sample code available on this? As I see it this is far from intuitive and its a major reason for NOT converting to ada. What I would like is a simple "MS Visual Studio " like library brows tree thing. So instead of having to "build a new operating system" to solve even the most trivial task, such as calling a member function or a constructor I could actually add a with clause or import clause and then be able to see whats available in the lib. So if anyone has a working sample on the usage of these pragmas I would be more than happy. I assume that the fact that there are no examples of the usage of these Pragmas in the userguide or reference manual suggests that this is not as straigth forward as advertised. /CG