![](/img/trans.png)
[英]How to create multiple application instances in CANoe COM Server Interface
[英]How to access sub object in CANoe COM Server Interface
我有一個很大的難以理解的COM服務器問題。 我正在嘗試將客戶端應用程序寫入CANoe(Vector的應用程序)。 他們給了CANoe.tlb,CANoe.h和CANoe_i.cpp文件,但我只使用CANoe.tlb通過#import。 所有示例都在Visual Basic中,我試圖在VC ++(控制台應用程序)中編寫它。 問題在於繼承。 即在他們寫的幫助中,主要對象是Application,只有通過這個對象才能訪問所有方法,對象事件等。 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
我確定我犯了錯誤,但我不知道在哪里。 簡單地說,我無法訪問子對象,他們的方法等。我只能訪問應用程序的方法。 例如,我想以這種方式調用方法Start from Measurement對象:pApp-> Measurement-> Start()但是這是不可能的。
我的源代碼:
#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
}
我附加CANoe COM服務器文件(從免費演示版本合法): http : //www.sendspace.com/file/5pgcou
PS使用COM Server對我來說是新的,對最終的愚蠢錯誤感到抱歉。 我正在搜索任何有用的信息,但我沒有找到任何有關使用此COM接口的信息。
嘗試更改您的代碼:
CComQIPtr<IMeasurement> measure;
CComPtr<IDispatch> measureDisp;
pApp->get_Measurement(&measureDisp);
measure = measureDisp;
measure->Start();
另外不要忘記檢查被調用方法的結果。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.