MIDL (Constant) References

2019-07-17 04:39发布

Are there no constant references in MIDL method declarations????

eg.

[id(1), helpstring("My Method")]
HRESULT MyMethod(
    [in] IID & const rclsid
);

for

HRESULT MyMethod(
    IID const &rclsid
);

标签: windows com midl
1条回答
Viruses.
2楼-- · 2019-07-17 05:06

MIDL doesn't really support reference parameters, it only supports "in" and "out" parameters. So if you DO pass in a reference, it's just syntactic sugar for a pointer to the value (the issue is observability - if you have a callback function or interface in our method signature, changes to a reference would be observable from the callback, but changes to an [out] parameter aren't visible until the function returns.

In addition, the difference between "& const" and "const &" are lost. If you look at the definition of REFGUID, you'll see that they only use one form of "const" for C++ code:

#ifdef __midl_proxy
#define __MIDL_CONST
#else
#define __MIDL_CONST const
#endif

#ifndef _REFGUID_DEFINED
#define _REFGUID_DEFINED
#ifdef __cplusplus
#define REFGUID const GUID &
#else
#define REFGUID const GUID * __MIDL_CONST
#endif
#endif
查看更多
登录 后发表回答