gpt4 book ai didi

c++ - COM:如何将特定类型的 COM 对象指定为 idl 中的参数

转载 作者:行者123 更新时间:2023-11-28 03:40:46 25 4
gpt4 key购买 nike

目前我有一些代码看起来像这样

void calc_run(Calculation *c, Input *i);

STDMETHODIMP CCalculation::run(IUnknown* input)
{
calc_run(calc,((CMyInputClass*)input)->get_input());
return S_OK;
}

换句话说,CCalculation::run 需要一个指向 CMyInputClass 的指针,但目前它需要 IUnknown 和向下转换。

大概这是不好的。

但是我怎样才能更准确地向 COM 指定我想要的对象呢?我尝试更改 .c.h.idl 文件,但编译器无法识别 CMyInputClass*作为 idl 中的类型规范。

interface ICalculation : IDispatch{
[id(2), helpstring("method run")] HRESULT run([in] CMyInputClass* input);

正确的做法是什么?

最佳答案

COM 方式是引入 CMyInputClass 将实现的 COM 接口(interface),并在 run() 声明中使用该接口(interface):

interface ICalculationInput : IUnknown {
//some methods here
};

interface ICalculation : IDispatch{
[id(2), helpstring("method run")] HRESULT run([in] ICalculationInput* input);
};

关于c++ - COM:如何将特定类型的 COM 对象指定为 idl 中的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9329000/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com