pipi
2009-04-16 03:43:50 UTC
I use native c++ client app to call a dotnet assembly through CCW (COM
callable wrapper)
In dotnet component, I used the following to raise event
====================================================================
[ComVisible(true)]
public delegate void Evt2DeveloperDelegate( string value, string
subject);
public interface ITestEvents
{
void Evt2Developer([MarshalAs(UnmanagedType.BStr)] string
value, [MarshalAs(UnmanagedType.BStr)] string subject);
}
And C++ will use the following to handle the incoming event
====================================================================
HRESULT __stdcall Evt2Developer(BSTR value,BSTR subject)
{
BSTR bstrString=AsciiToBSTR(val);
//print bstring
/* SysFreeString(value); this will failed */
}
BSTR AsciiToBSTR(const char* pszFName)
{
WCHAR wszURL[MAX_PATH];
::MultiByteToWideChar(CP_ACP, 0, pszFName, -1, wszURL, MAX_PATH);
return SysAllocString(wszURL);
}
====================================================================
How to free the string memory? C++ (call SysFreeString(value); will
failed ) or Dotnet GC
Any help appreciate
callable wrapper)
In dotnet component, I used the following to raise event
====================================================================
[ComVisible(true)]
public delegate void Evt2DeveloperDelegate( string value, string
subject);
public interface ITestEvents
{
void Evt2Developer([MarshalAs(UnmanagedType.BStr)] string
value, [MarshalAs(UnmanagedType.BStr)] string subject);
}
And C++ will use the following to handle the incoming event
====================================================================
HRESULT __stdcall Evt2Developer(BSTR value,BSTR subject)
{
BSTR bstrString=AsciiToBSTR(val);
//print bstring
/* SysFreeString(value); this will failed */
}
BSTR AsciiToBSTR(const char* pszFName)
{
WCHAR wszURL[MAX_PATH];
::MultiByteToWideChar(CP_ACP, 0, pszFName, -1, wszURL, MAX_PATH);
return SysAllocString(wszURL);
}
====================================================================
How to free the string memory? C++ (call SysFreeString(value); will
failed ) or Dotnet GC
Any help appreciate