Monday, January 14, 2008

Export STL in C++

General guidelines are listed here.

How do I export STL components? Why do I get an access violation when accessing STL objects created in a DLL?

It is possible to export an instantiation of a Standard Template Library (STL) class. You can also export a class that contains a data member that is an STL object.

Note that you may not export a generalized template. The template must be instantiated, that is, all of the template parameters must be supplied and must be completely defined types at the point of instantiation. For instance "stack;" instantiates the STL stack class. The instantiation forces all members of class stack to be generated.

For details see the following article in the Microsoft Knowledge Base:

ARTICLE-ID: Q168958
TITLE: HOWTO: Exporting STL Components Inside and Outside a Class

When accessing a STL object created in one DLL or EXE through a pointer or reference in a different DLL or EXE, you may experience an access violation or other serious program errors including the appearance of data corruption or data loss. For details see the following article in the Microsoft Knowledge Base:

ARTICLE-ID: Q172396
TITLE PRB: Access Violation Caused when Accessing STL Object in DLL

Generally, NO good solutions for return a STL object from a DLL :(

A more detailed article briefly introduce the history and trend of export feature in C++ (exported Templates)


Comments: Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?