The application has many C++ compiled DLLs, each exposing many C type interfaces. The application has some std::string type configuration variables which needs to be used in the DLL interface logic. While passing this std::string type parameters to these DLLs, "0xC0000005: Access violation executing location" has thrown. Is this something related to VS project settings for DLL projects? Kindly clarify.
Asked
Active
Viewed 321 times
0
-
Could be also related to https://stackoverflow.com/questions/1634773 – IIRistoII Sep 06 '19 at 08:41
1 Answers
1
You probably won't make them to work easily.
std::string
may not be compatible between different compilations from different libraries.
When you say "The application has many C++ compiled DLLs", very likely you're in this scenario:
Library A:
// STL
class std::string
{
... under the hood implementation of std::string (version A)
};
// Library code
std::string someFunctionInA();
Library B:
// STL
class std::string
{
... under the hood implementation of std::string (version B)
};
// Library code
void someFunctionInB(const std::string& myString);
The crash program:
std::string stringFromA = someFunctionInA();
someFunctionInB(stringFromA);
Got it? You have 2 versions of std::string
and you program compiles because you're using the same headers during the compilations of your program... but in runtime, they are expecting 2 different types.
Size of the objects, order of data and simply the allocators may not match... and it will crash!
How to resolve:
- if you can compile from source, make sure you use the same STL version.
- if you can't compile from source, create C wrappers for them and use C-String as interface... they will always work.

Wagner Patriota
- 5,494
- 26
- 49
-
I am using same header file for std::string during compile and runtime. – Balamurugan T Sep 04 '19 at 08:52