Is this behaviour of get_ActiveDocument by design?

Is this behaviour of get_ActiveDocument by design?

oransen
Collaborator Collaborator
567 Views
5 Replies
Message 1 of 6

Is this behaviour of get_ActiveDocument by design?

oransen
Collaborator
Collaborator

If I call this function:

 

CComPtr<Document> pDoc;
HRESULT hRes = pInvApp->get_ActiveDocument(&pDoc);

 I get an S_OK result even if no document is open.

 

Does that mean that I should always check both the hRes and the &p... in all get_ calls which initialize a pointer?

 

 

0 Likes
Accepted solutions (1)
568 Views
5 Replies
Replies (5)
Message 2 of 6

jdkriek
Advisor
Advisor
Accepted solution

get_ActiveDocument will put NULL in pDoc if there is no document open.

 

Yes, you have to check that as well as hRes

Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.


0 Likes
Message 3 of 6

oransen
Collaborator
Collaborator

And in general all the get_... fuctions which pass back a pointer I suppose?

 

0 Likes
Message 4 of 6

jdkriek
Advisor
Advisor

That's correct

Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.


0 Likes
Message 5 of 6

oransen
Collaborator
Collaborator

I just found another! Just want to be sure...

 

// Get the sketch in the part by name...
CComPtr<PlanarSketch> pSketch = NULL;
hRes = pPartCompDef->Sketches->get_Item(CComVariant(L"MAIN_TUBE_CIRCS"), &pSketch);
if (FAILED(hRes) || (pSketch == NULL)) { 
    ReportCOMError (hRes,L"AddSolid but could not 'get' sketch\n");
    return (false) ;
}

Even in this case I should check pSketch as well as hRes?

 

Does FAILED(hRes) mean "I've understood your question..."

 

And does pSketch == NULL mean "..but I cannot answer it"

?

 

 

 

0 Likes
Message 6 of 6

xiaodong_liang
Autodesk Support
Autodesk Support

Hi oransen,

 

FAILED(hRes) returnes the status of calling the method. If all goes without any failure/error, it returns Succeed. But even if succeeds, there may be possiblity the object the method returns may be NULL due to specific reasons.This depends on how the inner logic of the method is written. So it is a safer way to check the object as well. Normally, if you are confident in the method, it is OK to check status only. 

 

Hope this makes sense.

0 Likes