 |
| C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

July 27th, 2004, 04:11 AM
|
|
|
Calling C# from C
Hello,
Is it possible to call a C# object/dll from a C environment.
I want to start developing code with Visual C# but the code needs to be accessible from within a C environment.
Previously, I was developing with Visual C++ version 6.
I made normal DLLs without name mangling. (with extern "C" applied to it)
These DLLs were accessible from within the C environment.
Is it also possible to do something similar with C#?
I cannot change the C environment, it is a requirement from the customer. But, it is allowed to develop libraries in other languages (C#) but they must be callable from within the C environment.
All hints/examples/code fragments/... are welcome.
Thanks in advance for all the help!
Bye for now,
dennis
|
|

July 28th, 2004, 12:00 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
When you create a .NET assembly, you can set a checkbox to have the assembly registered for COM interop. This will allow you to access it from any language that can call COM. (C can can't it? Been a long time since I touched C or C++.)
Go to the Configuration Properties -> Build page of your project properties. Look for "Register for COM Interop".
|
|

July 28th, 2004, 12:56 PM
|
|
|
Thanks for the info!
It works :)  :)
I'm usingit now from my C environment using COM Interop ...
I'm really starting to love C#
|
|

August 18th, 2004, 11:39 AM
|
|
Registered User
|
|
Join Date: Aug 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi Dennis,
I am also doing same kind of stuff.. But I am pretty much new to .Net & C#.
I would appreciate if you could mail me a simple example ..on how you call C# functions in C.
Thanks in Advance
Raj
|
|

August 31st, 2004, 04:50 PM
|
|
Authorized User
|
|
Join Date: Jul 2004
Posts: 69
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Does this make it possible to say declare a Form within the c app and then show it if it is declare in a C# dll.
www.CoderForRent.com
Get A Computer Job!
|
|

September 1st, 2004, 10:07 AM
|
|
|
Hello Raj, coderforrent,
Sorry for the late reply. I was on vacation with no possibility to check my mails, etc.
Some interesting websites with examples:
http://www.csharphelp.com/archives/archive190.html
http://www.codeproject.com/dotnet/cominterop.asp
Your question:
Does this make it possible to say declare a Form within the c app and then show it if it is declare in a C# dll.
Well, yes and no. It depends. Look at the links above. What you're actuallty doing is making COM components from your C# classes and these COM components can be called by your C code. It looks more difficult then it actually is. If the websites above don't help, drop me a line (beq02817 at yahoo.com) and I'll see if I can send you a small example.
Again, I'm sorry for the late reply.
Best regards,
Dennis
|
|

September 1st, 2004, 09:03 PM
|
|
Authorized User
|
|
Join Date: Jul 2004
Posts: 69
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Thank for the input.. I will check it out.
www.CoderForRent.com
Get A Computer Job!
|
|

September 15th, 2004, 07:52 PM
|
|
Registered User
|
|
Join Date: Sep 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hello,
Do you know where I can find a small example to call C# functions in C?
I have never used COM acces in C.
Thanks a lot.
Mat
|
|

September 16th, 2004, 02:06 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
When you compile the C# code, you need to enable the option to "register for COM interop" which sets up the assembly for COM registration. Then you can call .NET methods on the assembly from any COM interface.
|
|

September 16th, 2004, 08:11 PM
|
|
Registered User
|
|
Join Date: Sep 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hello planoie,
Thanks for this information but I don't know how to create a COM interface in C.
I haven't found an example yet.
If you have a little example, I would appreciate
Mat
|
|
 |