I need to return a vector of vectors from the COM layer to my .NET
application. I've implemented a struct called ROW which is made up of
a SAFEARRAY of another struct called CELL.
[
uuid(C1111111-7016-413c-8DCD-AE003D785A64)
]
struct ROW
{
SAFEARRAY(struct CELL) *m_cells;
};
[id(1), helpstring("method GetRows")]
HRESULT GetRows( [out,retval] SAFEARRAY(struct ROW) *ppRows);
[
uuid(72222222-DC15-4b29-A6C2-66F9C69DCA71)
]
struct CELL
{
BSTR m_value;
BSTR m_id;
};
I'm trying to create a two-dimensional safe array structure to return
from the COM layer. Having read some of the articles on the web about
implementing SAFEARRAYs I've followed their guidance as far as
possible but get a runtime error when running the code as the
safearray does not get created properly. Does anyone have any advice
on these kind of arrays? (I have already successfully created one
dimensional safearrays and one dimensional safearrays of structs).
vector<Row> rows; // where row is defined as a vector of cells
SAFEARRAY* rowsArray;
SAFEARRAYBOUND bound[2];
long cRows = rows.size();
bound[0].lLbound = 0;
bound[0].cElements = cRows;
if (cRows > 0)
{
// Setup the safe array
IRecordInfo* pRecInfo(NULL);
HRESULT hr = GetRecordInfoFromGuids(LIBID_MYLib, 1, 0, 0x409,
__uuidof(ROW), &pRecInfo);
// 2 dimensions
rowsArray = ::SafeArrayCreateEx(VT_RECORD, 2, bound,
(PVOID)pRecInfo);
struct ROW* pRowData; // array data
// This block defines the scope of the safearray lock
{
vector<Row>::iterator rowIter;
vector<Row>::iterator begin = rows.begin();
vector<Row>::iterator end = rows.end();
int i = 0;
SmartSafeArrayLocker safeArrayLocker( rowsArray,
(void**)&pRowData ); // runtime code blows up here becuase pRowData is
null
Thanks


|