Adding .NET to a C program - Techist - Tech Forum

Go Back   Techist - Tech Forum > Computer Software > Programming
Click Here to Login
Closed Thread
 
Thread Tools Display Modes
 
Old 01-10-2011, 03:28 PM   #1 (permalink)
Newb Techie
 
Join Date: Jan 2011
Posts: 1
Default Adding .NET to a C program

I have a C program that is a Windows Win32 application. I develop it with the Watcom compiler, which is compatible with Microsoft Visual C. But it does not use MFC or .NET. Now I have been asked to interface to something that requires .NET. Is it possible for me to add .NET capability to my application without changing the whole structure from Win32 to managed code? I want to minimize the learning curve and I really don't want to rewrite everything in the app to conform to the .NET framework.
__________________

__________________
Tunelabguy is offline  
Old 01-11-2011, 11:03 AM   #2 (permalink)
It's all just 1s and 0s
 
office politics's Avatar
 
Join Date: Jan 2004
Location: in the lab
Posts: 6,555
Send a message via MSN to office politics
Default Re: Adding .NET to a C program

see if this helps


edit - this article is prolly better explaination

http://www.devsource.com/c/a/Using-V...Code-from-Net/




original post-

How to mix VB.NET and C code

Quote:
alexey_gusev:03/01/10 06:41 AM, ID: 27272631there is a little misinterpreting here

what I was getting at is:

- you create Win32 dll, in C or C++ - doesn't really matter, you just need to be careful and ensure you export non-decorated functions from there (via def file or export "C" clause)
- you DON'T reference it in your .net project, but use System.Runtime.InteropServices namespace and P/Invoke (ie DllImport - the exact syntax is slightly different in c# and vb.net)
- the above line means that you get a number of 'global' functions in your .net project (Shared in vb.net or static in c#)

what happens at runtime is that .net sees your DllImport statement and tries to load the dll that is specified there and call the function you've defined.

for more details check

Platform Invoke Tutorial (C#)
Essential P/Invoke - CodeProject



cpkilekofp:03/01/10 08:36 AM, ID: 27273924riceman0,

Review the info at this link: An Overview of Managed/Unmanaged Code Interoperability

You'll notice that the first method of linking unmanaged code to managed code (PInvoke) was already mentioned. You, I believe, will want to try the C++ Interop techniques, so I suggest you study them closely. This article overviews ALL of the techniques for linking managed and unmanaged code, so if it isn't here, it can't be done.
__________________

office politics is offline  
Old 01-11-2011, 12:16 PM   #3 (permalink)
Seg Fault'n
 
Join Date: Jul 2005
Location: The dried husk where America came from
Posts: 5,801
Default Re: Adding .NET to a C program

^^ Unfortunately this is the easy way around, by the looks of it the OP needs to access managed c# from his c application.
__________________


There are in order of increasing severity: lies, darn lies, statistics, and computer benchmarks. - diskinfo man page
"Get your money and let's go to court!" - Craig Mudie, MS
kmote is offline  
Old 01-11-2011, 04:08 PM   #4 (permalink)
It's all just 1s and 0s
 
office politics's Avatar
 
Join Date: Jan 2004
Location: in the lab
Posts: 6,555
Send a message via MSN to office politics
Default Re: Adding .NET to a C program

yup, i thought it was switched. The information i posted discusses integrating a c app in a .net program. The thread title confirms the mixup.
office politics is offline  
Closed Thread

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need a Program Design Online assistant for my Program. aff1993 Microsoft Windows and Software 1 09-25-2006 06:45 PM
Adding a program to startup? CrazeD Microsoft Windows and Software 4 05-31-2006 12:39 AM
adding ram bojker26 System Upgrades 25 03-10-2006 05:53 PM
Manager client program and agent server program concepts zillah Computer Networking and Internet Hardware 0 02-03-2006 10:07 PM
adding RAM carolinaadi Monitors, Printers and Peripherals 5 12-20-2003 02:51 PM



Copyright 2002- Social Knowledge, LLC All Rights Reserved.

All times are GMT -5. The time now is 09:34 AM.


Powered by vBulletin® Version 3.8.8 Beta 1
Copyright ©2000 - 2018, vBulletin Solutions, Inc.