some questions about loading the CAPE-OPEN dll
Posted: 09 January 2013, 03:27
Recently I write some code to load the CAPE-OPEN dll files, I have no problem to get the interface of "IDispatch", "ICapeIdentification" and "ICapeUnit", and the functions in ICapeIdentification can be called very well. But for some specific CAPE-OPEN dll, when I use functions in ICapeUnit, It's always terminate with error, the warning message is:
****************************************************
Microsoft Visual C++ Debug Library
Debug Error!
Program: f:\c works\cd\debug\dc.exe
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
******************************************************
My source code is:
*******************
CoInitialize(NULL);
CLSID clsid;
CLSIDFromProgID(OLESTR("COCO_COUS.Compressor.1"),&clsid);
//after intalled COCO,you could find "COCO_COUS.Compressor.1" from registry
CComPtr<IDispatch> pGetRes;
CComPtr<ICapeIdentification> iCapeIdenti;
pGetRes.CoCreateInstance(clsid);
CComPtr<ICapeUnit> iCapeUnit;
//the following get the interface of ICapeUnit, for most CAPE-OPEN dlls, It has no problem, but when call the functions in ICapeUnit, it will terminate.
HRESULT hr=pGetRes->QueryInterface(__uuidof(ICapeUnit),(LPVOID*)&iCapeUnit);
if(SUCCEEDED(hr)) AfxMessageBox(_T("QueryInterface ICapeUnit Succeeded"));
else return;
//the following get the interface of ICapeIdentification
hr=pGetRes->QueryInterface(__uuidof(ICapeIdentification),(LPVOID*)& iCapeIdenti);
if(SUCCEEDED(hr)) AfxMessageBox(_T("QueryInterface ICapeIdentification Succeeded"));
else return;
//the following get the description of component, use the ICapeIdentification interface, it's always right
_bstr_t abc= iCapeIdenti->GetComponentDescription();
CString des;
des=(LPCSTR)abc;
AfxMessageBox(_T("the component's description is ")+des);
//the following get the ValStatus of component, use the ICapeUnit interface, for some components it's always wrong, I don't know why.
CapeValidationStatus cvs=iCapeUnit->GetValStatus();
CString cv;
cv.Format(_T(" CapeValidationStatus is %d"),cvs);
AfxMessageBox(cv);
//the following get the ports, if "iCapeUnit->GetValStatus()" is succeeded, this one will be succeed.
LPDISPATCH ld=iCapeUnit->Getports();
CComPtr<ICapeCollection> iCapeCollection;
hr=ld->QueryInterface(__uuidof(ICapeCollection),(LPVOID*)&iCapeCollection);
if(SUCCEEDED(hr)) AfxMessageBox(_T("QueryInterface ICapeCollection Succeeded"));
else return;
//show the count of ports
CString pc;
pc.Format(_T("the count of ports is %d"),iCapeCollection->Count());
AfxMessageBox(pc);
CoUninitialize();
*******************
for most CAPE-OPEN dlls, the above code will runs very good,for example the "CPPMixerSplitterexample.dll", but others like "COCOCOUS.dll","COCO_COUS.HeatExchanger.1","COCO_COUS.HeaterCooler.1","COCO_COUS.CSTR.1" from COCO is always terminate. But I tried the "COCOCOUS.dll","COCO_COUS.HeatExchanger.1","COCO_COUS.HeaterCooler.1","COCO_COUS.CSTR.1" in Aspen Plus V7.2, aspen runs very well, so I suspect whether my code has some problem ?
On the other hand, I can't use "Initialize()" function in ICapeUnit, and I can't use "ICapeUnitCollection" too, my tlb file is "CAPE-OPENv1-1-0.tlb", I don't find the reason.
****************************************************
Microsoft Visual C++ Debug Library
Debug Error!
Program: f:\c works\cd\debug\dc.exe
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
******************************************************
My source code is:
*******************
CoInitialize(NULL);
CLSID clsid;
CLSIDFromProgID(OLESTR("COCO_COUS.Compressor.1"),&clsid);
//after intalled COCO,you could find "COCO_COUS.Compressor.1" from registry
CComPtr<IDispatch> pGetRes;
CComPtr<ICapeIdentification> iCapeIdenti;
pGetRes.CoCreateInstance(clsid);
CComPtr<ICapeUnit> iCapeUnit;
//the following get the interface of ICapeUnit, for most CAPE-OPEN dlls, It has no problem, but when call the functions in ICapeUnit, it will terminate.
HRESULT hr=pGetRes->QueryInterface(__uuidof(ICapeUnit),(LPVOID*)&iCapeUnit);
if(SUCCEEDED(hr)) AfxMessageBox(_T("QueryInterface ICapeUnit Succeeded"));
else return;
//the following get the interface of ICapeIdentification
hr=pGetRes->QueryInterface(__uuidof(ICapeIdentification),(LPVOID*)& iCapeIdenti);
if(SUCCEEDED(hr)) AfxMessageBox(_T("QueryInterface ICapeIdentification Succeeded"));
else return;
//the following get the description of component, use the ICapeIdentification interface, it's always right
_bstr_t abc= iCapeIdenti->GetComponentDescription();
CString des;
des=(LPCSTR)abc;
AfxMessageBox(_T("the component's description is ")+des);
//the following get the ValStatus of component, use the ICapeUnit interface, for some components it's always wrong, I don't know why.
CapeValidationStatus cvs=iCapeUnit->GetValStatus();
CString cv;
cv.Format(_T(" CapeValidationStatus is %d"),cvs);
AfxMessageBox(cv);
//the following get the ports, if "iCapeUnit->GetValStatus()" is succeeded, this one will be succeed.
LPDISPATCH ld=iCapeUnit->Getports();
CComPtr<ICapeCollection> iCapeCollection;
hr=ld->QueryInterface(__uuidof(ICapeCollection),(LPVOID*)&iCapeCollection);
if(SUCCEEDED(hr)) AfxMessageBox(_T("QueryInterface ICapeCollection Succeeded"));
else return;
//show the count of ports
CString pc;
pc.Format(_T("the count of ports is %d"),iCapeCollection->Count());
AfxMessageBox(pc);
CoUninitialize();
*******************
for most CAPE-OPEN dlls, the above code will runs very good,for example the "CPPMixerSplitterexample.dll", but others like "COCOCOUS.dll","COCO_COUS.HeatExchanger.1","COCO_COUS.HeaterCooler.1","COCO_COUS.CSTR.1" from COCO is always terminate. But I tried the "COCOCOUS.dll","COCO_COUS.HeatExchanger.1","COCO_COUS.HeaterCooler.1","COCO_COUS.CSTR.1" in Aspen Plus V7.2, aspen runs very well, so I suspect whether my code has some problem ?
On the other hand, I can't use "Initialize()" function in ICapeUnit, and I can't use "ICapeUnitCollection" too, my tlb file is "CAPE-OPENv1-1-0.tlb", I don't find the reason.