Calling C# DLL from C

  • Thread starter Thread starter Virajitha Sarma
  • Start date Start date
V

Virajitha Sarma

Hi,

Can u plz help me out with how to call a C# DLL from C...
I tried to find out by searching in net..but i couldnot find anything on
it....

Thanku
Virajitha
 
I believe there is a third option, hosting the CLR runtime. This
involves using COM to "load" the CLR runtime, but not to have the
particular assemblies "registered" like typical Active-X stuff.
 
Joel Lucsy said:
I believe there is a third option, hosting the CLR runtime. This involves
using COM to "load" the CLR runtime, but not to have the particular
assemblies "registered" like typical Active-X stuff.

Well not really, when hosting the CLR, you still need to call managed code
through one of the interop layers be it COM or Managed thunks. True, you
don't need an IA in a COM interop scenarion you can dynamically create a
CCW, but it's not a trivial task though.


Willy.
 
Willy said:
Well not really, when hosting the CLR, you still need to call managed code
through one of the interop layers be it COM or Managed thunks. True, you
don't need an IA in a COM interop scenarion you can dynamically create a
CCW, but it's not a trivial task though.


Willy.

Why would you need a CCW? The host uses COM to instantiate the CLR and
then uses those interfaces to call whichever managed code you want. To
call back into the host you could use P/Invoke just fine without having
a CCW around. Of course this method means you can't use classes defined
in the host, but this may not be a problem as it really depends on what
you're trying to accomplish. I've tested this technique just fine.
 
Joel Lucsy said:
Why would you need a CCW? The host uses COM to instantiate the CLR and
then uses those interfaces to call whichever managed code you want. To
call back into the host you could use P/Invoke just fine without having a
CCW around. Of course this method means you can't use classes defined in
the host, but this may not be a problem as it really depends on what
you're trying to accomplish. I've tested this technique just fine.

Joel,

I 'm not 100% clear on what you mean here. The host instantiates the CLR
using the COM based hosting API's, that's right, but the CLR is unmanaged
code. And then you say; "then uses those interfaces to call whichever
managed code you want."
If you mean by this that you can use the hosting API's to load an assembly
and START executing this managed ( say C#) code by calling it's entry point,
then I agree, but this is not the same thing as a direct call into managed
objects methods from native code. This is simply not possible has you need a
Object reference in order to call managed methods, or you need a CCW that
translates the .NET object model into a COM interface model so that native
COM clients can create instances and call methods through COM interop, or
you need a wrapper class that thunks the native C++ object into a managed
interface.

Willy.
 
Back
Top