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

	// 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);
testString = L"You joking?";