The following is episode of my code:
Code: Select all
// some construction code
SampleUnitOperation :: SampleUnitOperation
{
CoInitialize(NULL);
// have defined CComPtr<IThermoCompound> tc;
HRESULT hr=tc.CoCreateInstance(clsid);
}
Code: Select all
//some destruction code
SampleUnitOperation :: ~SampleUnitOperation
{
tc=NULL;
CoUninitialize();
}
click "Solve", then click "Reset", then click "Solve", then click "Reset", then again "Solve". At this moment, COFE will appear this window:(at the attachment)
Then I tested the COFE, I find when click "Solve", the COFE will call the construction function "SampleUnitOperation :: SampleUnitOperation" twice. But Aspen Plus only calls this construction function at the first time when inserts this Unit Operation, not at the "Solve" function.
So the collapsion of COFE is the conflict of construction function and destruction function, COFE's twice calling on "Solve" results in the chaos of COM reference.
So, why does COFE call Unit Operation's construction function at the "Slove" command twice? It's rational to call construction at the Unit Operation's creation, not the "Solve".
And where should I release the "tc" COM pointer and call "CoUninitialize"?
Thank you Jasper, any response will be appreciated.