COFE collapses when using CoUninitialize in destruction
Posted: 10 August 2014, 08:29
I have finished a simple Unit Operation, it performs very good in the environment of Aspen Plus, but easily collapses in the environment of COFE.
The following is episode of my code:
Well, there's no error with the code, but after the process finished in the COFE, COFE will collapse at this case:
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.
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.