Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > IDL > Implementing a ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 1 Topic 198 of 225
Post > Topic >>

Implementing a 2 dimensional safe array with structs?

by abedford <abedford@[EMAIL PROTECTED] > Aug 13, 2007 at 07:25 AM

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
 




 1 Posts in Topic:
Implementing a 2 dimensional safe array with structs?
abedford <abedford@[EM  2007-08-13 07:25:03 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Jul 9 6:14:07 CDT 2008.