problem with minitialize() and mterminate()

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a mix-mode Managed C++ dll which wraps some C++ static library and
exposes functions to C# IRTDServer.

So the scenario is like this:

C++ Static library (with static member variables in classes)

|

|

v

Managed C++ dll

|

|

v

C# IRTDServer (to be used in Excel Add-Ins)

|

|

v

Microsoft Excel



IRTDServer calls Managed C++'s minitialize() everytime IRTDServer's
ServerStart() function is called by Excel.

IRTDServer then calls Managed C++'s mterminate() everytime IRTServer's
ServerTerminate() function is called by Excel, e.g. when a worksheet is
closed or when Excel is closed.

However, I found out that Managed C++'s minitialize() returns false the
second time I re-open an Excel worksheet.

My questions are:

1. Is it allowed to call minitialize() and mterminate() multiple times?

1.1 If so, why does minitialize() return false the second time
it is called?

2. I also looked into the code in vcclrit.h and found out minitizlie()
returns false because global variables __initialized and __terminate are not
reset to false in mterminate().

I then reset the value myself but it causes some even more strange errors.
 
Hi scottrm!
1. Is it allowed to call minitialize() and mterminate() multiple times?

You can call "minitialize" multiple times, but it will only initialize
the CRT the first time

You *cannot* call "mterminate" more than _one_ time! If you have called
it, your CRT has terminated!!!
There is no reference counting in these functions!

So please call the "minitialize" and "mterminate" *only* once!!!

1.1 If so, why does minitialize() return false the second time
it is called?

It will return false if "mterminate" was called before...


--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
 
Back
Top