2

我需要将字符串数组从 C# 模块传递到我的 C++ COM 组件。以下是idl声明;

[id(11), helpstring("method deleteObjectsEx")] HRESULT deleteObjectsEx(
                [in] BSTR userName,
                [in] BSTR userPasswd, 
                [in] SAFEARRAY(VARIANT) varValues, 
                [in] BSTR deleteMode
                );

我们使用以下代码从 C# 调用 API

List<string> ObjectIDS = new List<string>();
ObjectIDS.Add(obj._ObjectId[0]);
ObjectIDS.Add(obj._ObjectId[1]);

/*Array ar = Array.CreateInstance(typeof(string), size);
ar.SetValue(obj._ObjectId[0], 0);
ar.SetValue(obj._ObjectId[1], 1);*/

mhubBridge.deleteObjectsEx(Encrypt(auth.UserName), 
                           Encrypt(auth.UserPassword), 
                           ObjectIDS.ToArray(),
                           obj._delMEthod);

在调用 deleteObjectsEx API 时,我得到“A first chance exception of type System.Runtime.InteropServices.SafeArrayTypeMismatchException occurred in IPDWebService.DLL IPDWS::trace::(Tuesday, 06 August 2013 13:27): Exception in deleteObjectsEx:: message - Specified array was not of the expected type.

4

2 回答 2

1

不工作

尝试使用ar数组。

mhubBridge.deleteObjectsEx(Encrypt(auth.UserName), 
                           Encrypt(auth.UserPassword), 
                           ar,
                           obj._delMEthod);

如果可行,请删除所有ObjectIDS“东西”。

或尝试:

工作

object[] ar = new object[] { obj._ObjectId[0], obj._ObjectId[1] };

并将其传递给deleteObjectsEx(...)

因为从技术上讲 aVARIANT是一个object,所以 aSAFEARRAY(VARIANT)是一个object[]

于 2013-08-06T09:39:17.940 回答
0

尝试这个:

object[] ar = new object[2];
ar [0] = obj._ObjectId[0];
ar [1] = obj._ObjectId[1];
于 2016-09-24T12:27:44.287 回答