473,386 Members | 1,828 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,386 software developers and data experts.

Is it possible to call C# code from C++ ?

Hi

I know that we can call C++ code from C# using COM interop, how about do
the reverse?

Ricky
Nov 16 '05 #1
12 1923
Ricky,

If you want to call a COM component from .NET, you just have to add a
reference to it in your VS.NET project (go to "Add References").

If you were working from the command line, you would run the TLBIMP
utility to generate a Runtime Callable Wrapper, and then set a reference to
that.

You can also call C++ code through the P/Invoke layer, if the C++ code
exposes functions through a DLL.

Or, finally, you can wrap the C++ code in a managed wrapper (using
Managed Extensions for C++) and then call it like a normal assembly.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Ricky" <sp**@spam.com> wrote in message
news:Ow**************@TK2MSFTNGP14.phx.gbl...
Hi

I know that we can call C++ code from C# using COM interop, how about do
the reverse?

Ricky

Nov 16 '05 #2
Ricky,

If you want to call a COM component from .NET, you just have to add a
reference to it in your VS.NET project (go to "Add References").

If you were working from the command line, you would run the TLBIMP
utility to generate a Runtime Callable Wrapper, and then set a reference to
that.

You can also call C++ code through the P/Invoke layer, if the C++ code
exposes functions through a DLL.

Or, finally, you can wrap the C++ code in a managed wrapper (using
Managed Extensions for C++) and then call it like a normal assembly.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Ricky" <sp**@spam.com> wrote in message
news:Ow**************@TK2MSFTNGP14.phx.gbl...
Hi

I know that we can call C++ code from C# using COM interop, how about do
the reverse?

Ricky

Nov 16 '05 #3
Yes, you can expose C# classes as a COM classes.
However, you have to respect some basic rules and preferably set some
attributes for this to work correctly, you also have to explicitly "register
the assembly for COM interop" [1].
For details, check the "COM interop tutorials" in the C# programmers
reference" on MSDN.

Willy.

[1] Windows XP SP2 offers a "registration free COM interop" facility.

"Ricky" <sp**@spam.com> wrote in message
news:Ow**************@TK2MSFTNGP14.phx.gbl...
Hi

I know that we can call C++ code from C# using COM interop, how about do
the reverse?

Ricky

Nov 16 '05 #4
Yes, you can expose C# classes as a COM classes.
However, you have to respect some basic rules and preferably set some
attributes for this to work correctly, you also have to explicitly "register
the assembly for COM interop" [1].
For details, check the "COM interop tutorials" in the C# programmers
reference" on MSDN.

Willy.

[1] Windows XP SP2 offers a "registration free COM interop" facility.

"Ricky" <sp**@spam.com> wrote in message
news:Ow**************@TK2MSFTNGP14.phx.gbl...
Hi

I know that we can call C++ code from C# using COM interop, how about do
the reverse?

Ricky

Nov 16 '05 #5
Hi

Sorry, I mean call C# from C++, not C++ from C#.
Ricky

Nicholas Paldino [.NET/C# MVP] wrote:
Ricky,

If you want to call a COM component from .NET, you just have to add a
reference to it in your VS.NET project (go to "Add References").

If you were working from the command line, you would run the TLBIMP
utility to generate a Runtime Callable Wrapper, and then set a reference to
that.

You can also call C++ code through the P/Invoke layer, if the C++ code
exposes functions through a DLL.

Or, finally, you can wrap the C++ code in a managed wrapper (using
Managed Extensions for C++) and then call it like a normal assembly.

Hope this helps.

Nov 16 '05 #6
Hi

Sorry, I mean call C# from C++, not C++ from C#.
Ricky

Nicholas Paldino [.NET/C# MVP] wrote:
Ricky,

If you want to call a COM component from .NET, you just have to add a
reference to it in your VS.NET project (go to "Add References").

If you were working from the command line, you would run the TLBIMP
utility to generate a Runtime Callable Wrapper, and then set a reference to
that.

You can also call C++ code through the P/Invoke layer, if the C++ code
exposes functions through a DLL.

Or, finally, you can wrap the C++ code in a managed wrapper (using
Managed Extensions for C++) and then call it like a normal assembly.

Hope this helps.

Nov 16 '05 #7
Ricky,

Yes, it is. You can export your .NET types to COM using the TLBEXP
tool, which will generate a type library for your .NET types.

However, going from .NET to COM is a little tricker than the other way
around. Before doing this, you should read the section of the .NET
framework documentation titled "", located at (watch for line wrap):
"Ricky" <sp**@spam.com> wrote in message
news:eW**************@TK2MSFTNGP15.phx.gbl...
Hi

Sorry, I mean call C# from C++, not C++ from C#.
Ricky

Nicholas Paldino [.NET/C# MVP] wrote:
Ricky,

If you want to call a COM component from .NET, you just have to add a
reference to it in your VS.NET project (go to "Add References").

If you were working from the command line, you would run the TLBIMP
utility to generate a Runtime Callable Wrapper, and then set a reference
to that.

You can also call C++ code through the P/Invoke layer, if the C++
code exposes functions through a DLL.

Or, finally, you can wrap the C++ code in a managed wrapper (using
Managed Extensions for C++) and then call it like a normal assembly.

Hope this helps.


Nov 16 '05 #8
Ricky,

Yes, it is. You can export your .NET types to COM using the TLBEXP
tool, which will generate a type library for your .NET types.

However, going from .NET to COM is a little tricker than the other way
around. Before doing this, you should read the section of the .NET
framework documentation titled "", located at (watch for line wrap):
"Ricky" <sp**@spam.com> wrote in message
news:eW**************@TK2MSFTNGP15.phx.gbl...
Hi

Sorry, I mean call C# from C++, not C++ from C#.
Ricky

Nicholas Paldino [.NET/C# MVP] wrote:
Ricky,

If you want to call a COM component from .NET, you just have to add a
reference to it in your VS.NET project (go to "Add References").

If you were working from the command line, you would run the TLBIMP
utility to generate a Runtime Callable Wrapper, and then set a reference
to that.

You can also call C++ code through the P/Invoke layer, if the C++
code exposes functions through a DLL.

Or, finally, you can wrap the C++ code in a managed wrapper (using
Managed Extensions for C++) and then call it like a normal assembly.

Hope this helps.


Nov 16 '05 #9
Oops, it would help if I gave the title and the link:

Qualifying .NET Types for Interoperation

http://msdn.microsoft.com/library/de...roperation.asp
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Ricky" <sp**@spam.com> wrote in message
news:eW**************@TK2MSFTNGP15.phx.gbl...
Hi

Sorry, I mean call C# from C++, not C++ from C#.
Ricky

Nicholas Paldino [.NET/C# MVP] wrote:
Ricky,

If you want to call a COM component from .NET, you just have to add a
reference to it in your VS.NET project (go to "Add References").

If you were working from the command line, you would run the TLBIMP
utility to generate a Runtime Callable Wrapper, and then set a reference
to that.

You can also call C++ code through the P/Invoke layer, if the C++
code exposes functions through a DLL.

Or, finally, you can wrap the C++ code in a managed wrapper (using
Managed Extensions for C++) and then call it like a normal assembly.

Hope this helps.


Nov 16 '05 #10
Oops, it would help if I gave the title and the link:

Qualifying .NET Types for Interoperation

http://msdn.microsoft.com/library/de...roperation.asp
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Ricky" <sp**@spam.com> wrote in message
news:eW**************@TK2MSFTNGP15.phx.gbl...
Hi

Sorry, I mean call C# from C++, not C++ from C#.
Ricky

Nicholas Paldino [.NET/C# MVP] wrote:
Ricky,

If you want to call a COM component from .NET, you just have to add a
reference to it in your VS.NET project (go to "Add References").

If you were working from the command line, you would run the TLBIMP
utility to generate a Runtime Callable Wrapper, and then set a reference
to that.

You can also call C++ code through the P/Invoke layer, if the C++
code exposes functions through a DLL.

Or, finally, you can wrap the C++ code in a managed wrapper (using
Managed Extensions for C++) and then call it like a normal assembly.

Hope this helps.


Nov 16 '05 #11
Thanks for your information.

Nicholas Paldino [.NET/C# MVP] wrote:
Oops, it would help if I gave the title and the link:

Qualifying .NET Types for Interoperation

http://msdn.microsoft.com/library/de...roperation.asp

Nov 16 '05 #12
Thanks for your information.

Nicholas Paldino [.NET/C# MVP] wrote:
Oops, it would help if I gave the title and the link:

Qualifying .NET Types for Interoperation

http://msdn.microsoft.com/library/de...roperation.asp

Nov 16 '05 #13

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

Similar topics

2
by: Pierre Rouleau | last post by:
I have a GUI application written in Python (with WxPython) which uses some low level classes also written in Python. These low level Python classes are given a pointer to some GUI Python object. ...
3
by: Rennie deGraaf | last post by:
The attached code compiles and works properly when I comment out the declaration, definition, and invocations of the method 'eck'. With "eck" in there, g++ fails with ttest.cpp:23: template-id...
2
by: FrankS | last post by:
Hi All, I have a problem with an call-template cmd at xslt 1.0: With: pCall = 'ExInput' ------ I try to: <xsl:call-template name="{$pCall}"> <xsl:with-param name="pVal" select="$pValue"/>...
5
by: randy | last post by:
Hello all, I have a DataTable which I am building column by column and adding rows after each new column. The DataTable columns match the columns in my database table. I'm building the...
13
by: Hiroshi Ochi | last post by:
Hello, Is it possible to initialize javascript function parameters (using MSIE 6.0 and above)? According to the link below, it seems possible to do this. ...
8
by: Arno R | last post by:
Hi all, Is the above possible? I guess I need an API call for this ? How and where to find this? One of my new apps is used as a sort of 'dedicated' thing. Users see an empty desktop with...
2
by: Jack | last post by:
Hello, I have a 3-level class hirarchy: 1=Grandparent 2=Parent 3=Child The Grandparent has a method called OnPaint which I want to override from the Child class. I can do this, but how...
5
by: Arquitecto | last post by:
Hi ,i would like to give u a piece of code and discuss if it is possible to call the hidden_function without modify code to call it . I have read on internet about buffer overflows and i can...
8
by: gnewsgroup | last post by:
I know that we can re-use/share code by placing the code in App_Code. But, is it possible for MyPage.aspx.cs to call a method defined in AnotherPage.aspx.cs? Suppose, in AnotherPage.aspx.cs,...
5
by: Simon | last post by:
I heard that we could do that by using AJAX. Could anybody share how to do it? Thanks.
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
0
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...

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.