python - 如何将安全数组从 python 传递到 COM?
问题描述
我需要将布尔值列表作为 VT_ARRAY 传递给 COM。
from win32com.client import Dispatch, VARIANT
import pythoncom
api = Dispatch("MyAPI")
controller = api.CreateInterface()
first = VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_BOOL, [True, False, True])
second = VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_BOOL, [True, False, True])
controller.MyMethod(first, second)
COM接口的C++代码为:
if ( first->vt == ( VT_ARRAY | VT_BOOL ) && second->vt == ( VT_ARRAY | VT_BOOL ) )
{
CComSafeArray<BOOL> first_safe( first->parray ); //fails here
CComSafeArray<BOOL> second_safe( second->parray );
在 python 端出现 COM 异常失败:
pywintypes.com_error: (-2147023170, 'The remote procedure call failed.', None, None)
解决方案
推荐阅读
- c - fork() 和地址空间
- reactjs - 您可以将同一个 AWS 用户池连接到 React Native 和 React App 吗?
- html - 居中网格项目
- c++ - 从非实例化的上下文中引用特定的模板特化:实例化与否?
- hadoop - Hadoop集群kerberized时无法访问HDFS
- javascript - 如何在 MERN 堆栈中定义模式和快速路由器?
- javascript - Onclick 中的三元
- nginx - nginx 在使用 proxy_pass 功能时返回 404 结果
- python - 如何使用索引字典构建 DataFrame?
- java - 在 Java 中创建新的 JAXBContext 实例时出现 NullPointerException