Adding .NET to a C program

Status
Not open for further replies.

Tunelabguy

Beta member
Messages
1
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.
 
see if this helps


edit - this article is prolly better explaination

http://www.devsource.com/c/a/Using-VS/Calling-Unmanaged-Code-from-Net/




original post-

How to mix VB.NET and C code

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.
 
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.
 
Status
Not open for further replies.
Back
Top Bottom