How do I pass an array of structs (containing std:string or BSTR) from ATL to C#. SafeArray? Varian
- by Andrew
Hi, I have an ATL COM object that I am using from C#. The interface currently looks like:
interface ICHASCom : IDispatch{
[id(1), helpstring("method Start")] HRESULT Start([in] BSTR name, [out,retval] VARIANT_BOOL* result);
...
[id(4), helpstring("method GetCount")] HRESULT GetCount([out,retval] LONG* numPorts);
...
[id(7), helpstring("method EnableLogging")] HRESULT EnableLogging([in] VARIANT_BOOL enableLogging);
};
That is, it's a very simple interface. I also have some events that I send back too.
Now, I would like to add something to the interface. In the ATL I have some results, which are currently structs and look like
struct REPORT_LINE
{
string creationDate;
string Id;
string summary;
};
All the members of the struct are std::string. I have an array of these that I need to get back to the C#. What's the best way to do this?
I suspect someone is going to say, "hey, you can't just send std::string over COM like that. If so, fine, but what's the best way to modidfy the struct? Change the std::string to BSTR? And then how do I,
1) Set up the IDL to pass an array of structs (structs with BSTR or std::string)
2) If I must use SAFEARRAYS, how do I fill the SAFEARRAYS with the structs.
I'm not familiar with COM except for use with simple types.
Thanks,
Dave