how to reference a com exe from unmanaged c++?(如何从非托管 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)statconnDCOMinStatConnectorSrv.exe"
using namespace STATCONNECTORSRVLib;
和
#import "C:Program Files (x86)statconnDCOMinStatConnectorSrv.tlb"
using namespace STATCONNECTORSRVLib;
STATCONNECTORSRVLib 包含对象 StatConnector.但是,当我尝试实例化 StatConnector 时,我得到一个不允许不完整的类型",并且智能感知告诉我 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 方法,以及一个 coclass 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)statconnDCOMinStatConnectorSrv.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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何从非托管 c++ 引用 com exe?
基础教程推荐
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- CString 到 char* 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
