473,795 Members | 2,875 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Question about accessing functions via pointers

Hi,

I am a moonlighting Java programmer who needs to get some JNI written in C.
Thanks to legacy considerations, it must be in C. I hope I can frame this
question in a way that you all can understand.

Now, some of the calls I make returns a pointers to an objects. The objects
themselves are written in C++. I need to call methods on these objects. How
is this done? I hope there is wither a really short answer I can be given, or
that there is a FAQ, how-to, tutorial or some such I can be pointed to.

Thanks!

Jeff
Nov 14 '05 #1
3 1227
On Sat, 15 May 2004 15:17:59 -0500 (CDT), "Jeff Gaynor"
<jz**@jqhomze.n etz> wrote in comp.lang.c:
Hi,

I am a moonlighting Java programmer who needs to get some JNI written in C.
Thanks to legacy considerations, it must be in C. I hope I can frame this
question in a way that you all can understand.
I can understand your question, but there is one important thing you
are misunderstandin g.
Now, some of the calls I make returns a pointers to an objects. The objects
themselves are written in C++. I need to call methods on these objects. How
You are contradicting yourself here. Above you said you were talking
about C code. Suddenly you are talking about C++, an entirely
different language, which has no "methods". Actually C++ does not
have "methods" either, although it does have something called member
functions.
is this done? I hope there is wither a really short answer I can be given, or
that there is a FAQ, how-to, tutorial or some such I can be pointed to.

Thanks!

Jeff


Your biggest problem is that you are asking in the wrong place. C and
C++ are two entirely different languages, and C++ is completely
off-topic here. C++ questions go to comp.lang.c++, down the hall to
the left. But before you do that, take the link in my signature to
their FAQ. There is a section dealing with your question, but it is
not particularly simple.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++
http://www.contrib.and rew.cmu.edu/~ajo/docs/FAQ-acllc.html>

Nov 14 '05 #2

Hi
One implementation, would be to save the function pointers for each method
, and access the method using these pointers. The function pointers can be
saved in the constructor.

pawan
On Sat, 15 May 2004, Jeff Gaynor wrote:
Hi,

I am a moonlighting Java programmer who needs to get some JNI written in C.
Thanks to legacy considerations, it must be in C. I hope I can frame this
question in a way that you all can understand.

Now, some of the calls I make returns a pointers to an objects. The objects
themselves are written in C++. I need to call methods on these objects. How
is this done? I hope there is wither a really short answer I can be given, or
that there is a FAQ, how-to, tutorial or some such I can be pointed to.

Thanks!

Jeff

Nov 14 '05 #3

"Jeff Gaynor" <jz**@jqhomze.n etz> wrote in message

Now, some of the calls I make returns a pointers to an objects.
The objects themselves are written in C++. I need to call methods
on these objects. How is this done?
The only sensible way is to write your code in C++ and call
ptr->method().
I hope there is wither a really short answer I can be given, or
that there is a FAQ, how-to, tutorial or some such I can be pointed > to.

You can call C from C++, but it is very difficult to call C++ from C.

If you are really determined to do it, you need to find out how classes are
implemented on the C++ compiler you are using. You will probably find that
each class has a hidden first member which indexes onto a table of function
pointers. To access from C, you need to access this hidden member and then
do lots of messy casts to retrieve the member function pointer. You then
call it, remembering to set up the "this" pointer.

The code will not be portable from one C++ compiler to the next.
Nov 14 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3065
by: pertheli | last post by:
Hello, I have a large array of pointer to some object. I have to run test such that every possible pair in the array is tested. eg. if A,B,C,D are items of the array, possible pairs are AB, AC, AD, BC and CD. I'm using two nested for loop as below, but it is running very slow whenever I access any data in the second loop.
3
1917
by: Dabeule | last post by:
Hello, I have to read/write in the UART to transfer bytes through the serial port. I use Visual C++ 6 and Win2000. When I used Win98, the problem was easy : the functions _inp and _outp (or the file port95nt.dll) allow to read/write on the UART. But these functions (or this DLL) do not work... If anyone knows how to have the rights to access the UART with Win2000 or the functions to use in VC++, please help me !
4
385
by: aap | last post by:
Hi, I have the following code. #include <iostream> using namespace std; class Root { public: virtual void Root1() = 0; virtual void Root2() = 0;
20
6572
by: __PPS__ | last post by:
Hello everybody in a quiz I had a question about dangling pointer: "What a dangling pointer is and the danger of using it" My answer was: "dangling pointer is a pointer that points to some area of ram that's not reserved by the program. Accessing memory through such pointer is likely to result in core dump (memory access violation)"
62
9204
by: ROSY | last post by:
hello experts plz answer following questions::: thanks in advance. 1. Out of fgets() and gets() which function is safe to use and why? 2. What is a far pointer? where we use it? 3. What does the error 'Null Pointer Assignment' mean and what causes this error? 4. What is near, far and huge pointers? How many bytes are occupied by them? 5. How would you obtain segment and offset addresses from a far address of a memory location?
3
2039
by: Alex | last post by:
I'm having a problem porting an ASP solution to ASPX. In the ASP solution I'm accessing a DCOM server, create sub DCOM objects and call functions from VB script on the ASP pages. The DCOM object handles are stored in session variables. This works fine without a problem. Ported it to ASPX, accessing the same DCOM server from code behind pages. Still, usually no problems. However sometimes I'm seeing an error stating that the DCOM handle...
21
3226
by: yeti349 | last post by:
Hi, I'm using the following code to retrieve data from an xml file and populate a javascript array. The data is then displayed in html table form. I would like to then be able to sort by each column. Once the array elements are split, what is the best way to sort them? Thank you. //populate data object with data from xml file. //Data is a comma delimited list of values var jsData = new Array(); jsData = {lib: "#field...
12
11724
by: Steve Blinkhorn | last post by:
Does anyone know of a way of accessing and modifying variables declared static within a function from outside that function? Please no homilies on why it's bad practice: the context is very particular and involves automatically generated code. I know several other ways of attacking my problem, but this would be the cleanest if it could be made to work. A little more context. I use C as the output of a code generating system which...
10
1719
by: Zero | last post by:
Hello all, I wonder about void? To which category in the C programming language does it belong? Of how many bits consits void? Is it possible to define a varibale called void a;
0
9522
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10443
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10216
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10002
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9044
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7543
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6783
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2921
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.