ATL:我想创建一个coclass,我可以用作我的类中的方法的参数。为什么我不能让这个工作? [英] ATL: I want to create a coclass that I can use as a parameter for a method in my class. Why can't I get this to work?

查看:209
本文介绍了ATL:我想创建一个coclass,我可以用作我的类中的方法的参数。为什么我不能让这个工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ATL创建了一个COM对象。我想创建一个可以从方法返回的新对象,并作为参数传递。我创建了coclass,但我不知道如何添加一个方法,它将接受它作为参数。

I've created a COM object using ATL. I want to create a new object that can be returned from a method, and passed in as a parameter. I've created the coclass, but I can't figure out how to add a method that will accept it as a parameter.

我得到的错误是MIDL2025 :语法错误:期望在IgBrush附近的类型规范。我使用Visual Studio 2008.

The error I'm getting is MIDL2025: syntax error: expecting a type specification near "IgBrush". I'm using Visual Studio 2008.

当我添加一个枚举,我回忆起IDL有很多,最终得到它接受枚举作为一个参数。没有这样的运气与coclass。

When I added an enumeration, I recall playing around with the IDL quite a bit, and eventually got it to accept the enumeration as a parameter. No such luck with the coclass.

从ATL向导提供的默认生成代码,需要什么步骤才能使其正常工作? (即,我在哪里移动和为什么移动?)

From the default generated code that the ATL wizard provides, what are the steps needed to get this to work? (ie. what do I move where and why?)

推荐答案

如果你把你使用的IDL,这将有所帮助。

It would help if you put the IDL that you are using.

要在MIDL中使用类型,必须先声明它。

To use a type in MIDL you have to declare it first.

interface IMyFactory:IDispatch
{
  ...
};

interface IMyObject:IDispatch
{
  HRESULT SetFactory([in] IMyFactory * state);
}

但我建议你传递那些参数,如IUnknown *或IDispach * (如果他们是适当的),那么最后一个资源将使用VOID *作为参数。

But I'd recommend that you pass those parameters like IUnknown* or IDispach* (if they are appropiate), then last resource will be to use VOID* as parameters.

这篇关于ATL:我想创建一个coclass,我可以用作我的类中的方法的参数。为什么我不能让这个工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆