COM - [in] 参数为 SAFEARRAY(STRUCT)

发布于 2024-12-02 09:09:21 字数 643 浏览 0 评论 0原文

我可以使用 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技术交流群

发布评论

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

评论(1

少女七分熟 2024-12-09 09:09:21

问题出在使用

SetUsers([in] SAFEARRAY(UserEntity) input)

定义的 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

SetUsers([in] SAFEARRAY(UserEntity) input)

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

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