python调用COM 上

1、python下载地址

地址一:Python Windows版本下载| Python中文网 官网

地址二:Download Python | Python.org

地址三:32位和64位安装包

https://download.csdn.net/download/notfindjob/89569357

2、

方法1:使用comtypes

pip install comtypes

import comtypes.client
from ctypes import c_char_p
 
# 获取COM组件
com_object = comtypes.client.CreateObject("项目名.接口名.1") #ProgID
#com_object = comtypes.client.CreateObject("CLSID") 
# 调用COM组件的方法
str = "a123"
c_string = c_char_p(str.encode()) #//使用.encode('GBK')将其转换为字节串
print(c_string)
result = com_object.GetName(str)
#print(str)
print(result)

方法2:

pip install pywin32

import win32com.client
 
# 初始化COM组件
com_object = win32com.client.Dispatch(""项目名.接口名.1"") #ProgID
 
# 使用COM组件的方法和属性

result = com_object.GetName()
 
print(result)

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值