本文介绍了如何在ole自动化中声明类类型变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发自动化应用程序。将VBA代码转换为C ++时。



回调为HYSYS.BackDoor

以上BackDoor是OLE Automation的类类型。



变量返回只是在VBA中声明,但c ++不是。



如何在ole中声明类类型变量自动化?



i不知道如何解决这个问题....



CoCreateInstance,CoGetObject ,Cogetclassobject ...



i在应用程序初始化时使用CoCreateInstance。当我得到应用程序对象时,我使用了CoGetObject。



当我声明外部(ole自动化服务器的类)类变量时,使用什么方法,函数,变量?br />


in VB



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





汇入C ++





conver to C++

class CMSHysys //header
{
    public:
    IDispatch*  m_hyApp;
    IDispatch*  m_hyCase;
    IDispatch*  m_back;
    IDispatch*  m_hyfs;
}
void CMSHysys::Initialize(bool bVisible)
// == Set hyapp = CreateObject("HYSYS.application")
{
    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) //.cpp
//==Set hycase = GetObject("C\\test.hsc")
{
    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");
    }
}


上面代码中的
,hyapp == m_hyapp,hycase == m_hycase和back == m_back。



hycase(m_hycase)和hyfs(m_hyfs)依赖于hyapp(m_hyapp)。 back(m_back)是独立的。



所以,我不知道如何声明和使用m_back ......就像VB一样



只是我想知道如何声明变量(自动化服务器的内部数据类型)


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 )

推荐答案

LONG doAction( char *action, void* data);





其中action是一些命令和数据是一些进行的记忆。 :-O





奖金:一些非官方的。


这篇关于如何在ole自动化中声明类类型变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 18:43