gpt4 book ai didi

c++ - COM:总是需要方法参数属性?

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:26:01 26 4
gpt4 key购买 nike

我有一个名为 ISimpleCom 的 ATL 简单对象接口(interface)。该对象实现连接点。我想知道为什么“普通”COM 方法参数必须带有前缀和属性,而事件方法却不需要?

ISimpleCom 方法:

[id(1)] HRESULT Calculate([in] VARIANT_BOOL a_bFireEvent, [out,retval] LONG* a_lTotalMarks);

_ISimpleComEvents 方法(事件“signature”,注意“a_lTotalMark”的参数没有属性):[id(1)] HRESULT TotalMarks(LONG a_lTotalMarks);

Fire_TotalMarks(12); <-- will fire the event in my case to C# manage code

最佳答案

参数属性magic为explained on MSDN here :

The [in] attribute has a converse attribute, [out], which indicates that a parameter is to be returned from the called procedure to the calling procedure. The [in] and [out] attributes are known as directional parameter attributes because they specify the direction in which parameters are passed. A parameter can be defined as [in], [out], or [in, out].

The [in] attribute identifies parameters that are marshaled by the client stub for transmission to the server.

The [in] attribute is applied to a parameter by default when no directional parameter attribute is specified.

简要如下:

  • 参数是inoutin/out,无方向的参数没有意义,所以如果省略属性, [in] 仍然适用;您不必输入 [in],但为了清楚起见最好还是这样做
  • 这些参数定义了参数值传输的方向,当涉及到编码时,以及当调用在调用者/被调用者方式上假设某种传输时的其他传输

关于c++ - COM:总是需要方法参数属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19255566/

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