473,407 Members | 2,546 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

When to initialize managed wrappers in mixed mode

I have a mixed-mode DLL doing some SSPI stuff that needs to support a web
service.

The article at http://support.microsoft.com/?id=814472 says you need to
manually initialize the CRT when doing mixed-mode work.

The only method I need to call in the mixed-mode DLL is a single, static
method of one class.

Do I need to manually initialize the CRT every time I call into that DLL, or
can I just do it once when the web service starts?
Nov 16 '05 #1
3 1515
Hugh,
I have a mixed-mode DLL doing some SSPI stuff that needs to support a web
service.

The article at http://support.microsoft.com/?id=814472 says you need to
manually initialize the CRT when doing mixed-mode work.

The only method I need to call in the mixed-mode DLL is a single, static
method of one class.

Do I need to manually initialize the CRT every time I call into that DLL, or can I just do it once when the web service starts?


You *should* do it only once (as that should initialize the CRT for the
lifetime of the DLL), and then uninitialize it before it is unloaded (such
as when the application is going down).

--
Tomas Restrepo
to****@mvps.org
Nov 16 '05 #2
Thanks Tomas --

One follow-up... I'm not too deep in my understanding of how DLLs get loaded
and the dynamics of CRT initialization:

If the process that loads my DLL (in my case, an instance of aspnet_wp.exe)
has already initialized the CRT because of something else that's going on,
do I need to do it again? Put another way, is the CRT initialized on a
per-DLL or per-process basis?

Thanks again.
"Tomas Restrepo (MVP)" <to****@mvps.org> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Hugh,
I have a mixed-mode DLL doing some SSPI stuff that needs to support a web
service.

The article at http://support.microsoft.com/?id=814472 says you need to
manually initialize the CRT when doing mixed-mode work.

The only method I need to call in the mixed-mode DLL is a single, static
method of one class.

Do I need to manually initialize the CRT every time I call into that DLL, or can I just do it once when the web service starts?


You *should* do it only once (as that should initialize the CRT for the
lifetime of the DLL), and then uninitialize it before it is unloaded (such
as when the application is going down).

--
Tomas Restrepo
to****@mvps.org

Nov 16 '05 #3
Hi Hugh,
One follow-up... I'm not too deep in my understanding of how DLLs get loaded and the dynamics of CRT initialization:

If the process that loads my DLL (in my case, an instance of aspnet_wp.exe) has already initialized the CRT because of something else that's going on,
do I need to do it again? Put another way, is the CRT initialized on a
per-DLL or per-process basis?


Great question, and not exactly too easy to answer. The basic answer is, it
depends!

If you take .NET out of the picture, the answer would still be "it depends".
Why? Because there might be multiple copies of the CRT on a single process,
as it all depends on your linking options. If you have modules that are
statically linked against the CRT, then each one of those modules will have
it's own copy of the CRT. Those that are linked to the DLL version of the
CRT, on the other hand, will share the CRT.
That said, each copy of the CRT is usually initialized either from the .exe
as it loads, or for dll modules from within DllMain as it is loaded. I'm not
fully aware of all the details (but could be checked by looking at the CRT
source code), even for modules linked to the MSVCRTXX.DLL, you still need
per-module initialization of the DLL (even though, conceptually, they are
using the same CRT instance). The reason might be just that initializing the
CRT does far more than just initialize it's internal structures, but also
ensures some language features work, such as initializing static global
objects, for example (which is clearly module-specific).

These basic rules don't change just because you bring .NET into the mix. It
just gets more complex for mixed-mode dlls because of the loader-lock issue.

--
Tomas Restrepo
to****@mvps.org
Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: Alper AKCAYOZ | last post by:
Hello Esteemed Developers and Experts, I have been using Microsoft Visual C++ .NET for 1 year. During this time, I have searhed some topics over internets. Most of the topics about .NET is...
5
by: Adam McKee | last post by:
We are using Visual Studio.NET 2003 in our project with .NET framework 1.1. One of our libraries is a mixed-mode dll assembly consisting of one managed C++ library, and several unmanaged C++...
1
by: Jesse McGrew | last post by:
Hi all, I'm trying to make a plugin DLL for a third-party application, using VC++ .NET 2003. This DLL acts as a bridge between the C++ plugin API of the application, and my actual plugin code...
15
by: Geoff Cox | last post by:
Hello, Can I separately declare and initialize a string array? How and where would I do it in the code below? It was created using Visual C++ 2005 Express Beta 2 ... In C# I would have ...
7
by: Lee Crabtree | last post by:
I'm starting work on what will eventually be a very, very LARGE project. A lot of the project involves taking C/C++ class libraries and wrapping them with managed C++. I'd like to minimize the...
9
by: Herby | last post by:
Is possible to have a managed method within a Native(un-managed) class within a \clr project? E.g. class myClass { public: #pragma managed void myMethod(void);
10
by: morangolds | last post by:
Hi, I've been having a problem with C++ Windows Forms apps not "ending" when you close the form window. I've searched about this problem all over the place and most searches have lead me to...
5
by: =?Utf-8?B?aWduaGVucnk=?= | last post by:
I have a managed C++ project and two C# projects. All are class library projects. The C++ project links with native C++ static libraries and references to one C# project. The projects structure...
3
by: Pixel.to.life | last post by:
All, A question on JIT debugging with VS2005. I have a managed app that builds great on one machine (Vista Home basic, VS2005, JIT enabled for managed/unmanaged code). I can also debug it...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.