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?

懵懂的女人 提交于 2019-12-12 01:17:16

问题


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.

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

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.

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?)


回答1:


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

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

interface IMyFactory:IDispatch
{
  ...
};

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

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.



来源:https://stackoverflow.com/questions/698273/atl-i-want-to-create-a-coclass-that-i-can-use-as-a-parameter-for-a-method-in-my

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