i'm developing ole automation application. while converting VBA code to C++.
Dim back As HYSYS.BackDoor
above "BackDoor" is OLE Automation's class type.
variable back is simply declared in VBA , but c++ is not.
how to declare class type variable in ole automation ?
i don't know how to solve this problem....
CoCreateInstance, CoGetObject, Cogetclassobject...
i used CoCreateInstance when application initializing. and when i got application object, i used CoGetObject.
when i declare external(ole automation server's class) class variable, what use method, function, variable ?
in VB
Dim hyapp As HYSYS.Application
Dim hycase As HYSYS.SimulationCase
Dim hyfs As HYSYS.Flowsheet
Dim back As HYSYS.BackDoor
Sub main()
Set hyapp = CreateObject("HYSYS.application")
Set hycase = GetObject("C\\test.hsc")
Set hyfs = hycase.Flowsheet
Call GetHyObj(hyfs)
End Sub
Function GetHyObj(hyfs As Flowsheet)
For Each subOperation In hyfs.Operations("digitalop")
Set back = subOperation // autocasting data type
Set hyrv = back.BackDoorVariable(":selection.501").Variable
Next
End function
conver to C++
class CMSHysys {
public:
IDispatch* m_hyApp;
IDispatch* m_hyCase;
IDispatch* m_back;
IDispatch* m_hyfs;
}
void CMSHysys::Initialize(bool bVisible)
{
CoInitialize(NULL);
CLSID clsid;
m_hr = CLSIDFromProgID(L"Hysys.Application", &clsid);
if(SUCCEEDED(m_hr))
{
m_hr = CoCreateInstance(clsid, NULL, CLSCTX_LOCAL_SERVER, IID_IDispatch, (void **)&m_hyApp);
if(FAILED(m_hr)) m_hyApp=NULL;
}
}
HRESULT CMSHysys::Connect(LPCTSTR szFilename) {
m_hr = CoGetObject(szFilename, NULL,IID_IDispatch,(void **)&m_hyCase);
if(FAILED(m_hr))
{
printf("[-] connect fail\n");
}
else
{
printf("[+] connect ok\n");
}
VARIANT result;
VariantInit(&result);
m_hr=OLEMethod(DISPATCH_PROPERTYGET, &result, m_hyCase, L"Flowsheet", 0);
m_hyfs= result.pdispVal;
if(FAILED(m_hr))
{
printf("[-] flowsheet fail \n");
}
else
{
printf("[+] flowsheet ok\n");
}
}
in above code, hyapp == m_hyapp , hycase == m_hycase and back == m_back.
hycase(m_hycase)and hyfs(m_hyfs) depend on hyapp(m_hyapp). back(m_back) is independent.
so, i do not know how to declare and use m_back... like VB
just i want to know how to declare variable (ole automation server's inner data type )