COM - [in] 参数为 SAFEARRAY(STRUCT)
我可以使用 SAFEARRAY(BSTR) 作为输入来调用 COM 接口方法。如果我定义一个简单的(仅包含一些 BSTR-s 字段)STRUCT 来传递到 COM 我得到 "[System.ArgumentException] = {"参数不正确。 (来自 HRESULT 的异常:0x80070057 (E_INVALIDARG))”
未对我的 COM 服务器进行调用,因为客户端的参数似乎与服务器上的预期参数不匹配:E_INVALIDARG
这是我在 IDL 中的声明:
typedef enum UserEntityType
{
User,
Group,
IPAddress
} UserEntityType;
[
uuid(4786F77E-BA5F-4806-B224-12AA8601A5B1)
]
typedef struct UserEntity
{
UserEntityType EntityType;
BSTR Value;
} UserEntity;
[id(9)] HRESULT SetUsers([in] SAFEARRAY(UserEntity) input);
异常抛出于C# 4 客户端调用 SetUsers() 时的运行时。
I am able to call a COM interface method using SAFEARRAY(BSTR) as input. If I define instead a simple (containing only some BSTR-s fields) STRUCT to pass into the COM I get
"[System.ArgumentException] = {"The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))"
The call to my COM server is not made because as it seems the arguments from client does not match the expected arguments on server: E_INVALIDARG
Here is my declaration in IDL:
typedef enum UserEntityType
{
User,
Group,
IPAddress
} UserEntityType;
[
uuid(4786F77E-BA5F-4806-B224-12AA8601A5B1)
]
typedef struct UserEntity
{
UserEntityType EntityType;
BSTR Value;
} UserEntity;
[id(9)] HRESULT SetUsers([in] SAFEARRAY(UserEntity) input);
The exception is thrown at run-time when a C# 4 client calls SetUsers().
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题出在使用
定义的 exe COM 服务器的 C# 客户端中。
为了解决这个问题(至少对于 .NET 4.0),必须更改导入的 COM 服务器的以下属性:Embed Interop Types = False
The problem was in the C# client that was using the exe COM server where
was defined.
In order to fix this (at least for .NET 4.0) one has to change the following property of the imported COM server: Embed Interop Types = False