all groups > dotnet interop > october 2004 >
You're in the

dotnet interop

group:

How can you call managed code without hosting the CLR



Re: How can you call managed code without hosting the CLR Phil Wilson
10/26/2004 8:58:09 AM
dotnet interop: It says it uses a managed C++ DLL, so that will host the runtime.
--
Phil Wilson
[Microsoft MVP-Windows Installer]
[quoted text, click to view]

How can you call managed code without hosting the CLR Roy Chastain
10/26/2004 11:18:15 AM
The code at http://www.codeproject.com/dotnet/bridge.asp is an example of how to call managed C++ from an unmanaged CLI program.

This code does not make any of the calls to initiate the CLR etc.

I have tried it, and it works, but I really don't understand how and why since the CLR and default domain are never created.

Any comments?


-------------------------------------------
Roy Chastain
Re: How can you call managed code without hosting the CLR Roy Chastain
10/26/2004 12:17:09 PM
[quoted text, click to view]

How is that enough to get the CLR hosted. That would imply that all managed DLL's have CLR startup code in them and they all
'host' a copy of the CLR and we would then have multiple managed heaps etc. That can not possibly be right.

-------------------------------------------
Roy Chastain
Re: How can you call managed code without hosting the CLR Robert Jordan
10/26/2004 7:16:49 PM
Hi Roy,

[quoted text, click to view]

It's a mixed mode C++ project. The CLR is initialized by the
unmanaged C++ CRT.

bye
Re: How can you call managed code without hosting the CLR Roy Chastain
10/27/2004 7:54:03 AM
I was of the opinion that the unmanaged C++ CRT only initialized the CLR when the code was compiled to use CLR. I was also under
the impression that this would only happen in the EXE not in a DLL. Now it appears that my impressions and understandings are not
at all right, so the question now becomes.

In the case of a STRICTLY unmanaged EXE (not compiled to use CLR) calling a managed (Mixed Mode in this case) C++ DLL, does the
runtime initialize the CLR on every call into the DLL or does it do it once in DLL main (or the equivalent)?

Second question, is why is this such a mystery? I have not found any documentation from MS that would EVEN SUGGESTS that this
approach works. All of their documentation talks about calling CorBindToRuntimeEx from the unmanaged code and then doing COM like
things to find interface pointers.

In a nut shell, what are the trade-off between what appears to be a reverse It Just Works method of calling managed code from
unmanaged vs. explicitly hosting the CLR as is (almost) documented by Microsoft?

[quoted text, click to view]

-------------------------------------------
Roy Chastain
Re: How can you call managed code without hosting the CLR Robert Jordan
10/27/2004 3:02:12 PM
Hi Roy,

[quoted text, click to view]

The CLR will be initialized once per process, AFIK.

[quoted text, click to view]

There is no mistery ;-) It's just a checkbox of your project properties.
However, there are some problems with MC++ DLLs:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vcconMixedDLLLoadingProblem.asp

[quoted text, click to view]

The hosting interface is intended to be used from VS 6 or from
other unmanaged languages (Borland C++, Delphi, etc.).

bye
AddThis Social Bookmark Button