Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / October 2004

Tip: Looking for answers? Try searching our database.

How can you call managed code without hosting the CLR

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Roy Chastain - 26 Oct 2004 16:18 GMT
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
KMSystems, Inc.
Phil Wilson - 26 Oct 2004 16:58 GMT
It says it uses a managed C++ DLL, so that will host the runtime.
Signature

Phil Wilson
[Microsoft MVP-Windows Installer]

> The code at http://www.codeproject.com/dotnet/bridge.asp is an example of
> how to call managed C++ from an unmanaged CLI program.
[quoted text clipped - 9 lines]
> Roy Chastain
> KMSystems, Inc.
Roy Chastain - 26 Oct 2004 17:17 GMT
>It says it uses a managed C++ DLL, so that will host the runtime.

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
KMSystems, Inc.
Robert Jordan - 26 Oct 2004 18:16 GMT
Hi Roy,

> The code at http://www.codeproject.com/dotnet/bridge.asp is an example of how to call managed C++ from an unmanaged CLI program.
>
[quoted text clipped - 3 lines]
>
> Any comments?

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

bye
Rob
Roy Chastain - 27 Oct 2004 12:54 GMT
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?

>Hi Roy,
>
[quoted text clipped - 11 lines]
>bye
>Rob

-------------------------------------------
Roy Chastain
KMSystems, Inc.
Robert Jordan - 27 Oct 2004 14:02 GMT
Hi Roy,

> 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)?

The CLR will be initialized once per process, AFIK.

> 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.

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/ht
ml/vcconMixedDLLLoadingProblem.asp


> 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?

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

bye
Rob

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.