我需要将字符串数组从 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.