I want to pass back a group of data to a caller. What I am currently
doing involves returning a pointer to a struct defined in IDL and
available in the TLB. The thing is this gets messy w/ managed .NET code
involving messing w/ a System.IntPtr. Will managed code properly
release a structure with BSTR's located within the struct during garbage
collection? Is there a better way then providing a function for
unmanaged users to call to release a object?
typedef struct DataResult
{
BSTR infoA;
BSTR infoB;
BSTR infoC;
long infoD;
boolean infoE;
}DataResult;
[
object,
]
interface IFoo:IUnknown
{
HRESULT GetData([out,retval]DataResult **dataOut);
HRESULT FreeData([in,out]DataResult **release);
};
Why not just make a class with a method that returns what you need? Strings
are classes (reference types) and are stored on the heap anyway, so what do
you gain by using a structure?
>I want to pass back a group of data to a caller. What I am currently doing
>involves returning a pointer to a struct defined in IDL and available in
[quoted text clipped - 21 lines]
> HRESULT FreeData([in,out]DataResult **release);
> };
Scott Markwell - 03 Apr 2006 23:43 GMT
Ease of use for a caller. Instead of building their own local format.
Basically the goal is to pass back some structure that is convent for a
caller from C++ or managed code and provides all the data from a single
record in a single type.
> Why not just make a class with a method that returns what you need? Strings
> are classes (reference types) and are stored on the heap anyway, so what do
[quoted text clipped - 25 lines]
>> HRESULT FreeData([in,out]DataResult **release);
>> };
Scott Markwell - 04 Apr 2006 01:04 GMT
Think I've found what I need.
System.Runtime.InteropServices.Marshal.DestroyStructure should handle
the BSTR's and call SysFreeString on them.
> Ease of use for a caller. Instead of building their own local format.
> Basically the goal is to pass back some structure that is convent for a
[quoted text clipped - 30 lines]
>>> HRESULT FreeData([in,out]DataResult **release);
>>> };