Problem: Exiting Native app causes crash when using Managed C++ Bridge

  • Thread starter Thread starter s_schutte
  • Start date Start date
S

s_schutte

Here's my situation. I have an unmanaged C++ project that I am using
to interface with the Lotus Notes C API. I then have a managed C++
project in the same solution that functions as a "C++ Bridge". It
defines a function in a header that the native C++ library can call,
and then it forwards the calls along to a third project, which is a C#
DLL, and displays a System.Windows.Form.

So, I have:

Lotus -> Native C++ -> Managed C++ -> C#

Granted, I could combine the middle two into a single mixed assembly
(with #pragma unmanaged/managed, etc.) but for now I have them split.

So, when Lotus loads and I fire my event in the Native C++ library,
everything works fine. The Managed C++ automatically shims the CLR in
a bootstrap, and then I see my C# Windows form dialog pop up. Once the
dialog is done, I go ahead and call System.GC.Collect() just to be
safe.

Then, when I exit Lotus Notes, I get a DDE Server error (memory could
not be "read"). I have verified that when I comment out the code to
the Managed C++ call (which prevents the CLR from being loaded), the
error does not occur on Lotus shutdown.

So, it appears that Notes is choking on the CLR when it tries to shut
down and free all the memory in its process.

So, my question is, using this method, is there a way to force the CLR
to shutdown prior to the host application closing? I have researched
this, and it certainly seems that even after my ShowDialog() function
exits, the CLR stays loaded (static members persist, etc.). So, I need
some way for the native dll to tell the CLR to close.

I appreciate any help,

Sam
 
Just an FYI, it seems that when I get rid of my "EMDeregister" call in
the exit func of my DLL, this problem goes away.
 
Back
Top