V
Voronkov Konstantin
Hello, All!
I have following problem with std::string class.
I exproted class from dll which has function which returns
std::string.
I compiled dll in *release* configuration
(using Multithreaded Dll run-time library)
I imported class in application and called function which returns
std:string. The application is compiled in debug configuration
with (Debug Multithreaded Dll run-time library) I have heap corruption
problem, here is the stack:
NTDLL! 77f43847()
NTDLL! 77f78135()
KERNEL32! 77e6cd3c()
_CrtIsValidHeapPointer(const void * 0x00322e28) line 1697
_free_dbg_lk(void * 0x00322e28, int 1) line 1044 + 9 bytes
_free_dbg(void * 0x00322e28, int 1) line 1001 + 13 bytes
free(void * 0x00322e28) line 956 + 11 bytes
operator delete(void * 0x00322e28) line 7 + 10 bytes
std::allocator<char>::deallocate(void * 0x00322e28, unsigned int 33)
line 64 + 16 bytes
main(int 1, char * * 0x00342d50) line 9 + 18 bytes
mainCRTStartup() line 338 + 17 bytes
KERNEL32! 77e4f38c()
Does that mean that I can not link release library to debug
application?
Does anyone knows the workarond for my problem?
Mayve I did someting wrong?
Maybe some external STL library helps me, aka STL Port?
I'm using MS VS Compiler with sp5.
Here is the code of dll.h: ########################
#ifdef TESTDLL2_EXPORTS
#define TESTDLL2_API __declspec(dllexport)
#else
#define TESTDLL2_API __declspec(dllimport)
#endif
#include <string>
class TESTDLL2_API Foo
{
public:
std::string toString()const;
};
Here is the code of dll.cpp: ########################
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows
headers
#include <windows.h>
#include "stdafx.h"
#include "TestDll2.h"
BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call,
LPVOID lpReserved)
{
return TRUE;
}
std::string Foo::toString()const
{
std::string string = "-";
std::string sStringEnd = ":R";
return domainTI_String + sStringEnd;
}
Here is the code of application.cpp: ########################
#include <TestDll2.h>
int main(int argc, char* argv[])
{
Foo foo;
std::string str = foo.toString();
return 0;
}
Best Regards,
Voronkov Konstantin
I have following problem with std::string class.
I exproted class from dll which has function which returns
std::string.
I compiled dll in *release* configuration
(using Multithreaded Dll run-time library)
I imported class in application and called function which returns
std:string. The application is compiled in debug configuration
with (Debug Multithreaded Dll run-time library) I have heap corruption
problem, here is the stack:
NTDLL! 77f43847()
NTDLL! 77f78135()
KERNEL32! 77e6cd3c()
_CrtIsValidHeapPointer(const void * 0x00322e28) line 1697
_free_dbg_lk(void * 0x00322e28, int 1) line 1044 + 9 bytes
_free_dbg(void * 0x00322e28, int 1) line 1001 + 13 bytes
free(void * 0x00322e28) line 956 + 11 bytes
operator delete(void * 0x00322e28) line 7 + 10 bytes
std::allocator<char>::deallocate(void * 0x00322e28, unsigned int 33)
line 64 + 16 bytes
std::basic_string said:::_Tidy(unsigned char 1) line 592
line 59 + 17 bytesstd::basic_string said:::~basic_string<char,std::char_traits<char>,std::allocator<char> >()
main(int 1, char * * 0x00342d50) line 9 + 18 bytes
mainCRTStartup() line 338 + 17 bytes
KERNEL32! 77e4f38c()
Does that mean that I can not link release library to debug
application?
Does anyone knows the workarond for my problem?
Mayve I did someting wrong?
Maybe some external STL library helps me, aka STL Port?
I'm using MS VS Compiler with sp5.
Here is the code of dll.h: ########################
#ifdef TESTDLL2_EXPORTS
#define TESTDLL2_API __declspec(dllexport)
#else
#define TESTDLL2_API __declspec(dllimport)
#endif
#include <string>
class TESTDLL2_API Foo
{
public:
std::string toString()const;
};
Here is the code of dll.cpp: ########################
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows
headers
#include <windows.h>
#include "stdafx.h"
#include "TestDll2.h"
BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call,
LPVOID lpReserved)
{
return TRUE;
}
std::string Foo::toString()const
{
std::string string = "-";
std::string sStringEnd = ":R";
return domainTI_String + sStringEnd;
}
Here is the code of application.cpp: ########################
#include <TestDll2.h>
int main(int argc, char* argv[])
{
Foo foo;
std::string str = foo.toString();
return 0;
}
Best Regards,
Voronkov Konstantin