Home > Archive > VC STL > February 2005 > Reg. Access Violation When Accessing STL Object between a DLL and
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Reg. Access Violation When Accessing STL Object between a DLL and
|
|
| Muthu Nivas 2005-02-28, 9:00 am |
| 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.
Thanks & Regards,
Muthu Nivas.H
| |
| Doug Harrison [MVP] 2005-02-28, 4:02 pm |
| 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++
|
|
|
|
|