本文介绍了如何从非托管C ++引用COM EXE?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对非托管C ++不太熟悉,因为我只使用MFC和Dot Net。我有一个非托管的dll,我想引用一个进程外服务器。我尝试了以下操作:

I am not very familiar with unmanaged c++, as I've only worked with MFC and Dot Net. I have an unmanaged dll that I would like to reference an out of process server. I've tried the following:

#import "C:\Program Files (x86)\statconn\DCOM\bin\StatConnectorSrv.exe"
using namespace STATCONNECTORSRVLib;

#import "C:\Program Files (x86)\statconn\DCOM\bin\StatConnectorSrv.tlb"
using namespace STATCONNECTORSRVLib;

STATCONNECTORSRVLib包含对象StatConnector。但是,当我尝试实例化StatConnector时,出现不允许不完整的类型,并且intellisense告诉我StatConnector是一个结构。

STATCONNECTORSRVLib contains the object StatConnector. However when I try to instantiate StatConnector, I get an "incomplete type is not allowed", and intellisense tells me StatConnector is a struct.

StatConnector *conn = new StatConnector();

我在做什么错?

推荐答案

假设您的StatConnectorSrv.tlb包含接口 ISomething MyMethod 方法和一个协类 Something ,那么您可以这样实例化它:

Let's say your StatConnectorSrv.tlb contains an interface ISomething with a MyMethod method, and a coclass Something, then you would instantiate it like this:

#import "C:\Program Files (x86)\statconn\DCOM\bin\StatConnectorSrv.tlb"
using namespace STATCONNECTORSRVLib;

int _tmain(int argc, _TCHAR* argv[])
{
    CoInitialize(NULL);

    ISomethingPtr ptr(__uuidof(Something)); // create an instance of the Something coclass and get an ISomething pointer back
    ptr->MyMethod(parameters of the method);

    CoUninitialize();
    return 0;
}

这篇关于如何从非托管C ++引用COM EXE?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 10:13