This will not work because
sret
is a local pointer, so the calling application will still have it pointing somewhere else. You need the
address
of the pointer, something like:
__declspec(dllexport) int Function(wchar_t* s, wchar_t** sret, int len)
{
int sLen = wcslen(s);
*sret = new wchar_t(sLen+4); wcscpy_s(*sret, sLen, s);
wcscat_s(*sret, 4, L"_456");
len = wcslen(*sret);
return 1; }
However, a much better way would be to just return the pointer, something like:
__declspec(dllexport) wchar_t* Function(wchar_t* s)
{
int sLen = wcslen(s);
wchar_t* sret = new wchar_t[sLen + 5];
wcscpy_s(sret, sLen, s);
wcscat_s(sret, 4, L"_456");
return sret;
}
Is there a specific reason that you think this needs to be in a DLL?