COM - [in] parameter as SAFEARRAY(STRUCT)

杀马特。学长 韩版系。学妹 提交于 2019-12-24 03:03:50

问题


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().


回答1:


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



来源:https://stackoverflow.com/questions/7244835/com-in-parameter-as-safearraystruct

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!