Frisky wrote:
We are talking about C calling managed code.
C does not understand *anything* about managed code, it does not know
what managed code is, or anything about how it manages objects.
Willy has a good idea about using COM Interop to do it.
This is the *only* way to call managed objects from C because it is the
only way to initialize the runtime correctly and get access to a managed
object that uses .NET's thunking layers.
From a pure "C" perspective you can't do it. "C" has no notion of
namespaces, and .Net relies on them heavily. I base this on trying
This is irrelevant because C cannot access managed objects. For a start,
all methods on managed objects use a special calling convention called
__clrcall and C does not understand this. (Try it and see <g>, BTW this
calling convention can be used in managed C++ in .NET 2.0, but not by
earlier versions).
one of my good old C++ "Hello World" pieces written in managed code
and changing the extension of the file from ".cpp" to ".c". For 3
lines of code I 20 errors and numerous warnings.
Again, this is irrelevant. The managed extensions are for *C++* not for
C, there is no concept of Managed C (from Microsoft).
Is there a problem with having a single file of C++ code mixed in
with your "C"? What about an external DLL written in C++ that acts as
a shim to the "C" code. The C++ code you have to write is really a
lot like newer "C" code (not like old K&R stuff). Here is a sample:
Let's me re-assert what the OP was saying - dvtaylor wanted to access
code in a managed assembly library written in C#, the call would be made
from C. Thus the call is made from unmanaged code to managed code. The
example from codeproject was managed code calling unmanaged code (and
not very well, since there is a memory leak in the code).
Richard