Ò
Ò»Ê×Ê«
Hi all,
This a problem about windows dll.
I wrote a dll export this API to learn how strings are passed over the
dll boundaries.
extern "C" PINVOKELIB_API char * TestStringAsResult()
{
STRSAFE_LPWSTR result = (STRSAFE_LPWSTR)CoTaskMemAlloc( 1000 * 1000
* 100 );
StringCchCopy( result, 1000 , (STRSAFE_LPWSTR)"This is return
value" );
return (char *) result;
}
In my opinion, as the function allocated memory but do not release
it, any call of it would leak 100M bytes memory.
But that doesn't happen! Is there some mechanism that automatically
release memory of string passed over dll boundaries?
Thanks a lot!
This a problem about windows dll.
I wrote a dll export this API to learn how strings are passed over the
dll boundaries.
extern "C" PINVOKELIB_API char * TestStringAsResult()
{
STRSAFE_LPWSTR result = (STRSAFE_LPWSTR)CoTaskMemAlloc( 1000 * 1000
* 100 );
StringCchCopy( result, 1000 , (STRSAFE_LPWSTR)"This is return
value" );
return (char *) result;
}
In my opinion, as the function allocated memory but do not release
it, any call of it would leak 100M bytes memory.
But that doesn't happen! Is there some mechanism that automatically
release memory of string passed over dll boundaries?
Thanks a lot!