Re: Reg. Access Violation When Accessing STL Object between a DLL and

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Doug Harrison [MVP] (dsh_at_mvps.org)
Date: 02/28/05


Date: Mon, 28 Feb 2005 10:19:46 -0600

Muthu Nivas wrote:

>Hi all,
> One of MS KB article explains that there might be access violation when
>we access a STL object created in one DLL or EXE through a pointer or
>reference in a different DLL or EXE (
>http://support.microsoft.com/kb/q172396/ ). To avoid this that article gives
>two resolutions.
>1. If the object is either static, or static data members of a class then we
>need to
> create an accessor method.
>2. If the object is non-static data members of a class that are exported
>from a DLL
> or for automatic data then we have to Export the template class
>instantiation
> from one executable image and import it into the other executable images.
>
> Please refer the above mentioned article for more details.
>
>The same article refers one more article
>http://support.microsoft.com/kb/168958/EN-US/)
>which explains how to export STL Components Inside & Outside of a Class. In
>that it says that map, set, queue, list, deque are all contain nested classes
>and cannot be exported. So does that mean we can NOT have a class in a DLL
>with <map> as a non-static member & use it in the EXE after importing?
>
>Also it says that <basic_string> has been already exported by C Runtime
>DLL(if symbol _DLL is defined), therefore you cannot export them from your
>DLL. If it is already exported then why we need to write accessor methods
>for accessing global string object as mentioned in the sample given in
>article q172396? Also in that sample it does NOT refer a global or static
>but a string object created in heap!!!!
>
>Can anybody clarify this please? Or Please refer some good article or books
>which give more info abt this.

Link all your modules (EXE and DLL) to the same CRT DLLs, and you won't have
to worry about this explicit instantiation and exporting approach. You also
won't have to worry about the modules using different heaps, C-level file
descriptors, errno, etc. However, if you are using VC6, you need to apply
the fixes to <xtree> mentioned here:

http://www.dinkumware.com/vc_fixes.html

-- 
Doug Harrison
Microsoft MVP - Visual C++


Relevant Pages

  • Re: whats different between asp application and web site
    ... "this means pages can not refer to each other", ... "Without an assembly making a reference to another that it wishes to use the ... all files in the appcode folder go into one dll. ... then the page implements the interface. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Reg. Access Violation When Accessing STL Object between a DLL and
    ... we access a STL object created in one DLL or EXE through a pointer or ... reference in a different DLL or EXE ( ... Please refer the above mentioned article for more details. ...
    (microsoft.public.vc.stl)
  • Re: MSI and dll file
    ... my first dll should refer to the second dll. ... >>linked up with a dll file, MSI can auto find out the related dependent dll ...
    (microsoft.public.vb.general.discussion)
  • Re: Refering to Class, Types, and Functions from Dlls
    ... DLL that "contains a class", it is most likely a COM coclass. ... Visual Developer - Visual C# ... that would return a pointer to the ... what would I need to do to refer to the Dll, ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Need help in exporting API for Kernel Mode DLL to Application
    ... I am facing some problem in exporting kernel mode Driver DLL API to ... When this MYDTest is called in application, ...
    (microsoft.public.windowsce.platbuilder)