Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
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


Reply With Quote
  #2 (permalink)  
Old July 28th, 2004, 12:00 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,413
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".
Reply With Quote
  #3 (permalink)  
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#

Reply With Quote
  #4 (permalink)  
Old August 18th, 2004, 11:39 AM
Registered User
 
Join Date: Aug 2004
Location: , , .
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

Reply With Quote
  #5 (permalink)  
Old August 31st, 2004, 04:50 PM
Authorized User
 
Join Date: Jul 2004
Location: , , .
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!
Reply With Quote
  #6 (permalink)  
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


Reply With Quote
  #7 (permalink)  
Old September 1st, 2004, 09:03 PM
Authorized User
 
Join Date: Jul 2004
Location: , , .
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!
Reply With Quote
  #8 (permalink)  
Old September 15th, 2004, 07:52 PM
Registered User
 
Join Date: Sep 2004
Location: , , .
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
Reply With Quote
  #9 (permalink)  
Old September 16th, 2004, 02:06 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,413
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.
Reply With Quote
  #10 (permalink)  
Old September 16th, 2004, 08:11 PM
Registered User
 
Join Date: Sep 2004
Location: , , .
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
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 09:33 AM



All times are GMT -4. The time now is 03:22 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.