发表于:2006-08-17 16:17:00
楼主
初学opc
在GE的代码里有下面的一段
/////////////////////////////////////////////////////////////////////////////
// IXXXIM (IOPCItemMgt) interface functions
//
///////////////////////////////////////
// AddItems
///////////////////////////////////////
STDMETHODIMP IXXXIM::AddItems(
DWORD dwNumItems,
OPCITEMDEF * pItemArray,
OPCITEMRESULT ** ppAddResults,
HRESULT ** ppErrors
)
{
XXXGroup &g = *m_Parent;
unsigned int i;
OPCHANDLE j;
OPCITEMRESULT *ir;
HRESULT *hr;
BOOL ok = TRUE;
XXXItem *newitem;
// Defaults in case of error
//
*ppAddResults = ir = NULL; //acc001
*ppErrors = hr = NULL; //acc001
// First - allocate memory for the result array(s)
//
*ppAddResults = ir = (OPCITEMRESULT*)pIMalloc->Alloc(sizeof(OPCITEMRESULT) * dwNumItems); //acc001
if(ir == NULL) goto add_error;
*ppErrors = hr = (HRESULT*) pIMalloc->Alloc(sizeof(HRESULT) *dwNumItems); //acc001
if(hr == NULL) goto add_error;
// Now for each item...
//
for(i= 0; i<dwNumItems; i++)
{
// find a place to put the item
//
hr[i] = g.ItemAlloc(&j);
if (FAILED(hr[i]))
{
ok = FALSE;
continue;
}
// Then create an empty item
//
newitem = new XXXItem(&g);
if(newitem == NULL)
{
hr[i] = E_OUTOFMEMORY;
ok = FALSE;
continue;
}
// Then populate it
// and record it in this g