简体   繁体   English

如何访问CANoe COM服务器接口中的子对象

[英]How to access sub object in CANoe COM Server Interface

I have one big and difficult to understand problem with COM Server. 我有一个很大的难以理解的COM服务器问题。 I'm trying write client application to CANoe (application by Vector). 我正在尝试将客户端应用程序写入CANoe(Vector的应用程序)。 They gave CANoe.tlb, CANoe.h and CANoe_i.cpp files but I use only CANoe.tlb via #import. 他们给了CANoe.tlb,CANoe.h和CANoe_i.cpp文件,但我只使用CANoe.tlb通过#import。 All examples are in Visual Basic and I'm trying to write it in VC++ (console application). 所有示例都在Visual Basic中,我试图在VC ++(控制台应用程序)中编写它。 The problem is with inheritance. 问题在于继承。 Ie in help they wrote, that main object is Application and access to all methods, object events etc. is possible only via this object. 即在他们写的帮助中,主要对象是Application,只有通过这个对象才能访问所有方法,对象事件等。 All examples in Visual Basic are also simple, ie: Visual Basic中的所有示例都很简单,即:

Dim gCanApp As CANalyzer.Application
Set gCanApp = New Application
gCanApp.Open ("C:\Program Files\CANalyzer\Demo_CL\motbus.cfg")
gCanApp.CAPL.Compile
gCanApp.Measurement.Start

I'm sure that I'm making mistake but I have no idea where. 我确定我犯了错误,但我不知道在哪里。 In simply words I don't have access to subobjects, their methods etc. I have only access to Application's methods. 简单地说,我无法访问子对象,他们的方法等。我只能访问应用程序的方法。 For example I'd like to call method Start from Measurement object in this way: pApp->Measurement->Start() but it is impossible. 例如,我想以这种方式调用方法Start from Measurement对象:pApp-> Measurement-> Start()但是这是不可能的。

My source code: 我的源代码:

#import "CANoe.tlb" //importing CANoe type library
#include "stdafx.h"
#include <atlbase.h> //COM Server methods
#include <iostream>

using namespace CANoe;
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
    /*This part is working perfectly: */
    CComPtr<IApplication> pApp = NULL;
    CComPtr<IMeasurement> measure = NULL;
    CComPtr<ICAPL> capl = NULL;
    CLSID clsid;
    IID iid;
    HRESULT result;

    /* Initialization COM library: */
    if (FAILED(CoInitialize(NULL))) 
    {
        cerr << "Initialization COM Library error" << endl;
        system("pause");
        return 1;
    }
    if((result = CLSIDFromProgID(L"CANoe.Application", &clsid)) != S_OK) 
    {
        cerr << "Problem with opening application" << endl;
        system("pause");
        return 2;
    }
    result = pApp.CoCreateInstance(clsid);  //Opening CANoe Application
    if(result != S_OK)
                cout << "pApp fault" << endl;

    pApp->Open(L"C:\\test\\test.cfg", FALSE, TRUE); //Opening test.cfg file
    /****************End of good part**********************/

    //pApp->Measurement->Start();//I'd like to use it in this way - compiler error: error C2039: 'Start' : is not a member of 'IDispatch'

    pApp->get_Measurement((IDispatch**)&measure);
    measure->Start();//Unhandled exception at 0x7711d78c in canoe.exe: 0xC0000005: Access violation writing location 0x7711d78c.
    CoUninitialize(); //Uninitialization COM Library
}

I attache CANoe COM Server files (it is legal from free Demo version): http://www.sendspace.com/file/5pgcou 我附加CANoe COM服务器文件(从免费演示版本合法): http//www.sendspace.com/file/5pgcou

PS Using COM Server is new for me so sorry for eventually stupid mistake. PS使用COM Server对我来说是新的,对最终的愚蠢错误感到抱歉。 I was searching for any helpful information but I didn't find anything about using this COM Interface. 我正在搜索任何有用的信息,但我没有找到任何有关使用此COM接口的信息。

Try to change your code: 尝试更改您的代码:

CComQIPtr<IMeasurement> measure;
CComPtr<IDispatch> measureDisp;

pApp->get_Measurement(&measureDisp);
measure = measureDisp;
measure->Start();

Also don't forget to check results of called methods. 另外不要忘记检查被调用方法的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM