We help IT Professionals succeed at work.

static STL objects in MFC extension DLLs

stuthulhu
stuthulhu asked
on
Medium Priority
408 Views
Last Modified: 2013-11-20
I have an extension DLL class which contains a static STL map object:

class AFX_EXT_CLASS SomeDLLClass
{
      static map<int,int> sm_SomeMap;
      //etc.
};

Within an application I try to make a copy of this object:

map<int,int> localMap(SomeDllClass::sm_SomeMap);

This causes a crash inside STL.  (In fact, it often causes Developer Studio to crash as well.)  My theory is that STL's internal static objects (such as _Tree<...>::_Nil) are not working properly across the extension DLL/app boundary, but I am having trouble generating a piece of test code that convinces me that I completely understand the problem.

Has anybody else already dealt with this problem?  Are some STL classes off limits within MFC extension DLLs?
Comment
Watch Question

Commented:
Get a better STL implementation from:
http://www.ipmce.su/~fbp/stl/

Author

Commented:
I will try the more recent STL implementation, but if it relies on class statics at all, it is going to have the same problem.  (Upon further testing I have convinced myself that class statics do not export correctly, even in a simple, non-STL scaffold.)

Commented:
anything defined as static *can't* be exported in VC.  That's one of the reasons people use static.  It's part of the definition.  Are you really talking about exporting a static function?

Author

Commented:
No, I am talking about exporting a class which has a data member which is the instantiation of some template.  The template class, in turn, has one or more static data members.  See the sample code.
Commented:
This Knowledge Base article proposes two workarounds to your problem:

http://www.microsoft.com/kb/articles/q172/3/96.htm

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.