COM IDL 定义中 [in, out] 和 [out, retval] 之间的差异

发布于 2024-08-08 09:53:44 字数 536 浏览 7 评论 0原文

在我使用的一些 IDL 中,我注意到有 2 个用于标记方法返回值的约定 - [in, out][out, retval]

当有多个返回值时,似乎使用[in, out],例如:

HRESULT MyMethod(
    [in] long InputParam, 
    [in, out] long* OutputParam1, 
    [in, out] long* OutputParam2
);

当只有一个返回值时,似乎使用[out, retval]返回值,例如:

HRESULT MyMethod2(
    [in] long InputParam, 
    [out, retval] long* OutputParam1
);

这是 COM IDL 约定还是只是我正在使用的代码中的约定?

从这两种符号生成的代码是否存在功能差异,或者它们是否完全可以互换?

In some of the IDL I work with I have noticed that there are 2 conventions for marking return values in methods - [in, out] and [out, retval].

It appears that [in, out] is used when there are multiple return values, for example:

HRESULT MyMethod(
    [in] long InputParam, 
    [in, out] long* OutputParam1, 
    [in, out] long* OutputParam2
);

It appears that [out, retval] is used when there is only a single return value, for example:

HRESULT MyMethod2(
    [in] long InputParam, 
    [out, retval] long* OutputParam1
);

Is this a COM IDL convention or just a convention in the code I am working with?

Is there a functional difference in the code that will be generated from the 2 notations, or are they completely interchangeable?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

余生共白头 2024-08-15 09:53:44

[in, out] 表示调用方法时传递了有效值,并且方法返回成功时(指针指向的位置)存在有效值。 [out] 表示调用方法时指向的值可以是任何值,但在方法返回成功时才有效。 [out][in, out] 参数都必须是指针 - 它们的值未更改且有效,并且有效性要求仅适用于它们指向的变量。

[out, retval] 是一个语法糖,指示在创建本机 COM 支持包装器时,应将这个参数转换为返回值。例如

HRESULT MyMethod( [out] long* OutParam1, [out, retval] long* OutParam2 );

变为

long IWrappedInterface::MyMethod( long* OutParam1 );

如果不标记[retval],则包装器将包含具有原始签名的方法:

HRESULT IWrappedInterface::MyMethod( long* OutParam1, long* OutParam2 );

只有最后一个[out]参数可以标记为[输出,retval][in, out] 参数不能标记为 [retval]

[in, out] means that a valid value is passed when the method is called and a valid value is there (where the pointer points) when the method returns success. [out] means that the value pointed to can be whatever when the method is called but it will be valid when the method returns success. Both [out] and [in, out] parameters must be pointers - their values are unchanged and valid and the validity requirements only apply to the variables they point to.

[out, retval] is a syntactic sugar to indicate that when creating a Native COM Support wrapper this very parameter should be converted to a return value. For example

HRESULT MyMethod( [out] long* OutParam1, [out, retval] long* OutParam2 );

becomes

long IWrappedInterface::MyMethod( long* OutParam1 );

If you don't mark it [retval] the wrapper will contain a method with the original signature:

HRESULT IWrappedInterface::MyMethod( long* OutParam1, long* OutParam2 );

Only the last one [out] parameter can be marked as [out, retval]. [in, out] parameters can't be marked as [retval].

偷得浮生 2024-08-15 09:53:44

另一个区别是它在 .NET 代码的 PIA 中的显示方式。

[out, ret] 将在 .NET 中显示为返回值。

[out] 将显示 .NET 中方法的参数。

Another difference is how this will show up in a PIA in .NET code.

[out, ret] will show up as a return value in .NET.

[out] will show up an argument on the method in .NET.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文