Justin Lilly
Justin Lilly

Reputation: 147

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

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?

Upvotes: 0

Views: 632

Answers (1)

Simon Mourier
Simon Mourier

Reputation: 139187

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

Upvotes: 3

Related Questions