Hi all,

just to be sure. I have a C++ DLL in which I am implementing a bit of low-level functionality. To this library I wish to pass a managed System.String pointer (ref) so that the library can load the string with the new/returned value.

The question is, do I need to de-allocate the passed reference (and how) or is the following snippet ok?

I am getting the feeling the code could lead to leaks.

extern "C" __declspec(dllexport) bool TestUnicodeString(wchar_t* &testString)
{
	// Required by MFC
	AFX_MANAGE_STATE(AfxGetStaticModuleState());

	// Needed? If so how? The following doesn't work (heap corruption)
	// if (testString) delete [] testString;

	testString = L"You joking?";

	return true;
}

fill it with zeroes then..

size_t buf_size = wcslen(testString);
memset(testString,0,buf_size);
testString = L"You joking?";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.