473,388 Members | 1,213 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

can I pass an object from cpp to c

Hi all,
I have a piece of code written in c++. I wanted to pass that
object to a Cprogram. Can I do that, then how can I access the members
of that object from C function.

Dec 19 '05 #1
4 1382
jamy wrote:
Hi all,
I have a piece of code written in c++. I wanted to pass that
object to a Cprogram. Can I do that, then how can I access the members
of that object from C function.

Route #1: define the 'thing' as a C struct instead of a C++ class. This
is of course possible only if you have control of the C++ code.

Route #2: in the C++ source export an API callable from C in which each
C++ object will be represented by a handle, and there will be functions
(1 by result type for get, maybe 1 for set) to access the members;
either 1 (or more) per member, of generic ones with the member name
given as a string.

HaND,
--
Michel Bardiaux
R&D Director
T +32 [0] 2 790 29 41
F +32 [0] 2 790 29 02
E mailto:mb*******@mediaxim.be

Mediaxim NV/SA
Vorstlaan 191 Boulevard du Souverain
Brussel 1160 Bruxelles
http://www.mediaxim.com/
Dec 19 '05 #2
In article <11*********************@f14g2000cwb.googlegroups. com>,
jamy <pk****@gmail.com> wrote:
Hi all,
I have a piece of code written in c++. I wanted to pass that
object to a Cprogram. Can I do that, then how can I access the members
of that object from C function.


Not portable. Can't discuss it here. Blah, blah, blah.

To be just a little more verbose: The C standard says nothing about
interfacing with any other language.

Dec 19 '05 #3
jamy said:
Hi all,
I have a piece of code written in c++. I wanted to pass that
object to a Cprogram. Can I do that, then how can I access the members
of that object from C function.


You can certainly pass objects from C++ programs to C functions, although
the mechanism for so doing is a C++ mechanism and so discussion of it ought
really to be taken up in the comp.lang.c++ newsgroup.

To pass an object from a C++ program to a C /program/ is also possible, but
the mechanism for doing so (other than writing the data out to a file and
then reading that file from the C program, which is portable but clumsy)
would involve inter-process communication mechanisms that are beyond the
scope of either comp.lang.c or its C++ sister newsgroup. If this is what
you actually meant, then I suggest you ask the question in a newsgroup
devoted to your platform - perhaps comp.unix.programmer or
comp.os.ms-windows.programmer.win32 would be appropriate.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Dec 19 '05 #4
Can u plz tell me some thing about how to export API callable from C ,
and how to represent each object as a handle

Dec 22 '05 #5

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

Similar topics

110
by: Mr A | last post by:
Hi! I've been thinking about passing parameteras using references instead of pointers in order to emphasize that the parameter must be an object. Exemple: void func(Objec& object); //object...
7
by: Zlatko Matić | last post by:
Let's assume that we have a database on some SQL server (let it be MS SQL Server) and that we want to execute some parameterized query as a pass.through query. How can we pass parameters to the...
3
by: Andrew Mueller | last post by:
Hello, I tried this question prior and got no response, so thought I would try to explain differently.. I am not sure which type of object to pass between a VB 6.0 ActiveX dll and C#. I am...
4
by: z_learning_tester | last post by:
I'm reading the MS press C# book and there seems to be a contradiction. Please tell me which one is correct, 1 or 2. Thanks! Jeff 1. First it gives the code below saying that it prints 0 then...
10
by: John Bailo | last post by:
I want to pass a SqlCommand object as a input parameter to a method. I want to pass the SqlCommand "by value" so that any updates to the original object are *not* reflected in the object within...
4
by: Jon Slaughter | last post by:
I'm reading a book on C# and it says there are 4 ways of passing types: 1. Pass value type by value 2. Pass value type by reference 3. Pass reference by value 4. Pass reference by reference. ...
13
by: Francois Appert | last post by:
This post was originally in the C# Corner site, but their server is down. I'd like to see if this group can answer. I program in C++ and am learning C#. The issue is: why should anybody...
12
by: Bryan Parkoff | last post by:
I write my large project in C++ source code. My C++ source code contains approximate four thousand small functions. Most of them are inline. I define variables and functions in the global scope....
9
by: raylopez99 | last post by:
I'm posting this fragment from another thread to frame the issue clearer. How to pass an object to a function/method call in C# that will guarantee not to change the object?* In C++, as seen...
12
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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,...

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.