Access Violation in <xlocale> 
Author Message
 Access Violation in <xlocale>

I wrote a static library that uses <fstream> to open a file, write to it and
close it.  Nothing spectacular there.  I wote a few test applications in C++
that used this library and everything worked OK.  Now I need to support VB
as well as C++, so I decided to write a COM wrapper for my original class in
ATL.

I also exported my original class from the DLL so that C++ clients could
still use the original directly.  Much to my dismay, the following line
produced an access violation:

m_file.open(strPathName.c_str(), std::ios::in | std::ios::binary);

m_file is declared as:

std::fstream m_file;

I traced into the function call and ended up in this function in <xlocale>:

void _Incref()
  {_Lockit _Lk;
    if (_Refs < (size_t)(-1))  //<-- Access violation here
      ++_Refs; }

Is this related to me building as a DLL instead of a static library?  I am
at a loss as to how to proceed from here, any advice would be greatly
appreciated.

Thanks,
Phillip Toland
Software Developer
Compression Engines

http://www.*-*-*.com/



Sun, 30 Dec 2001 03:00:00 GMT  
 Access Violation in <xlocale>

Quote:

>I also exported my original class from the DLL so that C++ clients could
>still use the original directly.  Much to my dismay, the following line
>produced an access violation:

>m_file.open(strPathName.c_str(), std::ios::in | std::ios::binary);

>m_file is declared as:

>std::fstream m_file;

>I traced into the function call and ended up in this function in <xlocale>:

>void _Incref()
>  {_Lockit _Lk;
>    if (_Refs < (size_t)(-1))  //<-- Access violation here
>      ++_Refs; }

>Is this related to me building as a DLL instead of a static library?

In a word, yes. That innocent looking operation on an fstream causes
all sorts of activity down in the bowels of the library. Doubtless, you're
allocating locale facets, or some other internal iostreams objects, on
one heap and freeing them on another. This is an unfortunate side
effect of the way DLLs manage memory in VC++.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com



Sun, 30 Dec 2001 03:00:00 GMT  
 Access Violation in <xlocale>

Quote:

>In a word, yes. That innocent looking operation on an fstream causes
>all sorts of activity down in the bowels of the library. Doubtless, you're
>allocating locale facets, or some other internal iostreams objects, on
>one heap and freeing them on another. This is an unfortunate side
>effect of the way DLLs manage memory in VC++.

Fortunately, this sort of heap mismatch can be avoided by linking all your C
and C++ components to the same CRT DLL. Mismatches occur only if they link
to different CRT DLLs, or you have a mixture of static and dynamic CRT
linking.

--
Doug Harrison

Visual C++ MVP



Sun, 30 Dec 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. <<<<<<<Parsing help, please>>>>>>>>

2. Access Violation with map<string,xxx>

3. <string>,memory access violation

4. File Format conversion, ascii freeform -->.csv <-->.wk1<-->dbf<-->?HELP

5. <<<>>>Need C code advice with functions and sorting.<<<>>>

6. <><><>HELP<><><> PCMCIA Motorola Montana 33.6

7. >>>Windows Service<<<

8. >> An Access Violation Occurred While Trying to copy the file <<

9. proposal: <basic.h>, <pascal.h>, <fortran.h>, <cobol.h>

10. <<<< C Grammar for yacc needed >>>>

11. - - - = = =<><> W e b - U S A <><>= = = - - -

12. >>>> * Get keypress * <<<<

 

 
Powered by phpBB® Forum Software