Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
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
 
Old July 27th, 2004, 04:11 AM
NoXuS
Guest
 
Posts: n/a
Default 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


 
Old July 28th, 2004, 12:00 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

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".
 
Old July 28th, 2004, 12:56 PM
NoXuS
Guest
 
Posts: n/a
Default

Thanks for the info!

It works :):)
I'm usingit now from my C environment using COM Interop ...

I'm really starting to love C#

 
Old August 18th, 2004, 11:39 AM
Registered User
 
Join Date: Aug 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

 
Old August 31st, 2004, 04:50 PM
Authorized User
 
Join Date: Jul 2004
Posts: 69
Thanks: 0
Thanked 1 Time in 1 Post
Default

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!
 
Old September 1st, 2004, 10:07 AM
NoXuS
Guest
 
Posts: n/a
Default

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


 
Old September 1st, 2004, 09:03 PM
Authorized User
 
Join Date: Jul 2004
Posts: 69
Thanks: 0
Thanked 1 Time in 1 Post
Default

Thank for the input.. I will check it out.

www.CoderForRent.com
Get A Computer Job!
 
Old September 15th, 2004, 07:52 PM
Registered User
 
Join Date: Sep 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
 
Old September 16th, 2004, 02:06 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

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.
 
Old September 16th, 2004, 08:11 PM
Registered User
 
Join Date: Sep 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
calling a sub collatos BOOK: Beginning Microsoft Visual Basic 2008 ISBN: 978-0-470-19134-7 1 October 3rd, 2008 02:07 PM
Calling C# DLL from C virajithasarma C# 1 August 17th, 2005 04:01 AM
cannot use parentheses when calling a sub Adam H-W Classic ASP Basics 5 October 29th, 2004 03:41 AM
Let's keep it friendly here - no name calling jminatel Forum and Wrox.com Feedback 0 March 16th, 2004 10:33 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.