how to reference a com exe from unmanaged c++?

自作多情 提交于 2019-12-13 05:03:37

问题


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;

and

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

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();

What am I doing wrong?


回答1:


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;
}


来源:https://stackoverflow.com/questions/16365034/how-to-reference-a-com-exe-from-unmanaged-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!