Calling C Code from C#

  • Thread starter Thread starter Joey Harrison
  • Start date Start date
J

Joey Harrison

I am investigating the different ways in which one can call C functions from
inside a C# project. In particular, I need to do this in such a way as to
preserve the ability to debug the C code. It is difficult to debug a DLL,
so I'm trying to find a different approach from importing a DLL.

Ideally, I would like to be able to just include the C code in the C#
project. Does anyone have any ideas? I am using Visual Studio.NET.

Thanks,
Joey
 
you could use a Managed C++ project, that'll let you mix C and Managed C++
in a "mixed mode DLL" there are a couple of pitfalls though: static types
cant be initialized properly unless you build a few workarounds but other
than that its all good.

obviously PInvoke is used to call into C/C++ functions imported from native
DLLs
 
Joey,
I am investigating the different ways in which one can call C functions from
inside a C# project. In particular, I need to do this in such a way as to
preserve the ability to debug the C code. It is difficult to debug a DLL,
so I'm trying to find a different approach from importing a DLL.

If you enable the "Enable Unmanaged Debugging" option in the project
properties, you should be able to step into the C code.

Ideally, I would like to be able to just include the C code in the C#
project. Does anyone have any ideas?

That wont work, you can only have C# source code in a C# project.



Mattias
 
Arnt they redoing the C++/CLI syntax to avoid all this __blah keyword mess?


Eric Newton said:
you could use a Managed C++ project, that'll let you mix C and Managed C++
in a "mixed mode DLL" there are a couple of pitfalls though: static types
cant be initialized properly unless you build a few workarounds but other
than that its all good.

obviously PInvoke is used to call into C/C++ functions imported from native
DLLs

--
Eric Newton
C#/ASP Application Developer
http://ensoft-software.com/
(e-mail address removed)-software.com [remove the first "CC."]


Joey Harrison said:
I am investigating the different ways in which one can call C functions from
inside a C# project. In particular, I need to do this in such a way as to
preserve the ability to debug the C code. It is difficult to debug a DLL,
so I'm trying to find a different approach from importing a DLL.

Ideally, I would like to be able to just include the C code in the C#
project. Does anyone have any ideas? I am using Visual Studio.NET.

Thanks,
Joey
 
Arnt they redoing the C++/CLI syntax to avoid all this __blah keyword mess?
Yes, with talk of standardizing it with the ECMA, although I don't know the
state of it(I can't find the prelim spec on the ECMA site anymore, saw it
there some months back however)
Eric Newton said:
you could use a Managed C++ project, that'll let you mix C and Managed C++
in a "mixed mode DLL" there are a couple of pitfalls though: static types
cant be initialized properly unless you build a few workarounds but other
than that its all good.

obviously PInvoke is used to call into C/C++ functions imported from native
DLLs

--
Eric Newton
C#/ASP Application Developer
http://ensoft-software.com/
(e-mail address removed)-software.com [remove the first "CC."]


Joey Harrison said:
I am investigating the different ways in which one can call C
functions
from
inside a C# project. In particular, I need to do this in such a way
as
 
Back
Top