I have following function
__declspec(dllexport) wchar_t* __stdcall __getJson(wchar_t * listN){
setlocale(LC_ALL, "");
//function logic
wstring ant = utf8_to_wstring(result);
const WCHAR* constRes = ant.c_str();
WCHAR* tempObj=new WCHAR[ant.length()];
wcscpy(tempObj, constRes);
thread Thread([tempObj]{
Sleep(1000);
delete[] tempObj;
});
Thread.detach();
return tempObj;
}
This DLL returns wchar_t*
to MetaTrader4.
I tried many ways to return correct value and avoid memory leaks such as set return type const wchar_t*
, creating my own class with destructor with delete[]
in. But all this attempts was unsuccessful: I got '??ello'
instead of 'hello'
. Just first one or two symbols were incorrect. With creating thread
it works right. But, I want to know, may there be better solution?