Use auto_ptr in VC6 dll cause crash
Posted
by Yan Cheng CHEOK
on Stack Overflow
See other posts from Stack Overflow
or by Yan Cheng CHEOK
Published on 2010-04-16T02:24:51Z
Indexed on
2010/04/16
2:33 UTC
Read the original article
Hit count: 362
// dll
#include <memory>
__declspec(dllexport) std::auto_ptr<int> get();
__declspec(dllexport) std::auto_ptr<int> get()
{
return std::auto_ptr<int>(new int());
}
// exe
#include <iostream>
#include <memory>
__declspec(dllimport) std::auto_ptr<int> get();
int main() {
{
std::auto_ptr<int> x = get();
}
std::cout << "done\n";
getchar();
}
The following code run perfectly OK under VC9. However, under VC6, I will experience an immediate crash with the following message.
Debug Assertion Failed!
Program: C:\Projects\use_dynamic_link\Debug\use_dynamic_link.exe File: dbgheap.c Line: 1044
Expression: _CrtIsValidHeapPointer(pUserData)
Is it exporting auto_ptr under VC6 is not allowed?
It is a known problem that exporting STL collection classes through DLL.
However, I Google around and do not see anything mention for std::auto_ptr.
Any workaround?
© Stack Overflow or respective owner