I have a ATL COM component method which has an [out] BSTR* parameter. I have create a reference to this component from my .NET application which treats the parameter as an out String type. The COM component allocates this string like this:
USES_CONVERSION;
*sText = SysAllocString(T2OLE(psText));
where psText is a char*
However, when the method call returns, the .NET code still has an empty string. Can anyone see what is wrong?
The code isn’t wrong but the .Net runtime may be too stupid to parse the indirection. You might want to rephrase your IDL from:
to:
The first syntax will yield in C#:
2nd:
Any 8-bit to 16-bit Unicode conversion must go through SysAllocString, since both
outandout, retvalrequire the caller to free the string. However, the .Net-runtime might get better results if it is told that this is the return value;