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 / Languages / Managed C++ / August 2007

Tip: Looking for answers? Try searching our database.

Routines in mixed (managed and native) assemblies

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bob Altman - 30 Aug 2007 01:29 GMT
Hi all,

I have an unmanaged DLL.  The entry points in the DLL are declared via a
.def file (which is syntactically easier for me to deal with than the arcane
#pragma gibberish).

Now I want some of the functions in this DLL to interact with a managed DLL.
For performance reasons, I need to be absolutely certain where the
transitions are between unmanaged and managed code and vice versa.  I've
stared long and hard at the MSDN documentation, but I haven't found a clear
description of this, so I figured I'd ask in this NG.

From what I've read, it looks like all I need to do is:

1. Add the /clr option to my project (Property Pages->Configuration
Properties->General, "Common Language Runtime Support" field)

2. Include "#using <mscorlib.dll>" after the precompiled header directive in
any files that contain functions that want to call into managed code.  I
believe (but I'm not certain) that *only* these files will be compiled as
managed code (unless I fiddle with #pragma managed/unmanaged).  Further, if
I include the name of a function defined in one of these files in the .def
file, an unmanaged entry point will be exported from the DLL.  When that
entry point is called, the unmanaged caller will magically call into the
managed code.

3. I also need to make sure managed and unmanaged code use different
precompiled header files, or disable precompiled headers alltogether.

Is this all correct?
Jeffrey Tan[MSFT] - 30 Aug 2007 04:44 GMT
Hi Bob,

1. Instead of adding it to the entire project, add /clr only on those files
that contain functions that need to be managed.  Put another way, you
should decide which functions need to be managed and ensure that only those
are built /clr.
2. No, any file compiled /clr will be managed, regardless of whether it
contains #using<mscorlib.dll>.  You should avoid #pragma managed/unmanaged.
Your understanding of DLL exports is correct, with the caveat that
__clrcall functions (including functions containing managed types in the
signature) cannot be exported.
3. Yes. It's preferable to have them use different precompiled headers,
since it will improve build speed.

Actually, I was a bit confused with the "#pragma managed/unmanaged". Then,
by discussing with VC++ team, I was told that we may run into many
situations where these pragmas caused unexpected interactions with
templates and compiler generated functions. The primary use for these
pragmas, we found, was to control managed/native pathways to fix loader
lock problems.  However, it turns out that separating code into /clr and
native compilands does the job a lot better.

Hope it helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Bob Altman - 30 Aug 2007 17:30 GMT
Thanks Jeffrey, that helps a lot!

 - Bob

> Hi Bob,
>
[quoted text clipped - 46 lines]
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
Jeffrey Tan[MSFT] - 31 Aug 2007 04:16 GMT
You are welcome.

If you need further help, please feel free to post, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

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.