windows - How can I match python function to COM DLLs bc when the function passes 'self', the number of argument

I am writing a python program and need to interact with existing com dll objects written in C++.I can

I am writing a python program and need to interact with existing com dll objects written in C++. I can access the Dispatch interface of the dll using the comtypes module and get the correct function signature:

HRESULT FindFeatures([in, out] int* pint, [in] BSTR strDatabase, [in] BSTR strRules, [in] VARIANT Y, [in] VARIANT X, [in] double Param1, [in] double Param2, [in] double Param3, [in] int Param4,[out] VARIANT* FeaturesFound);

If I try to acccess the function by rescode = cls.FindFeatures(pointer(int(a)), "PathToDatabase", "PathToRules", np.ndarray(Y), np.ndarray(X), float(param1), float(param2), float(param3), int(1), np.zeros((20,))) I get an error code that 10 arguments expected, but 11 passed. And in the debugger it gets caught on the code in comtypes rescode = func(self, *args, **kw)

I thought maybe the comtypes wrapper is expecting it to put the output args as actual output: 'features_found = cls.FindFeatures(pointer(int(a)), "PathToDatabase", "PathToRules", np.ndarray(Y), np.ndarray(X), float(param1), float(param2), float(param3), int(1))'

it raises the following comtypes error

File "C:\minife3\envs\pywin\Lib\site-packages\comtypes\_memberspec.py", line 295, in call_with_inout
    rescode = func(self, *args, **kw)
              ^^^^^^^^^^^^^^^^^^^^^^^
_ctypes.COMError: (-2147024809, 'The parameter is incorrect.', (None, None, None, 0, None))

I am way out of my depth on this and could really use some guidance to help point me in the right direction. I'll post more of the code that I'm trying below in case I'm doing something wildly crazy.

import comtypes.client as cc
import comtypes
from comtypes.safearray import safearray_as_ndarray
from CustomLoaders import loadData
import ctypes
import numpy as np

#Weird work around to get the pointer to int into the function call and past type checking
int_type = ctypes.c_int
int_value = int_type(10)
ptr = ctypes.pointer(int_value)

#Get access to the DLL
find_featureslib = comtypes.GUID("{98B95959-2FF5-11D4-9F36-0000D11D8091}")
cc.GetModule((find_featureslib,1,0))
import comtypes.gen.COFINDFEATURESLib as FindFeaturesLib
feature_id = cc.CreateObject("COFINDFEATURES.FeatureId",None, None, FindFeaturesLib.IFeatureId)


#Get the data, x and y are 1D numpy arrays
x,y= loadData(r"PathToData.data")

#make buffer array for return data:
peaks_found = np.zeros(shape=(20,), dtype=np.int16)

with safearray_as_ndarray:
    rescode = feature_id.FindFeatures( ptr, strDataBasePath, strRulesPath,float(param1), float(param2), float(param3), int(1), peaks_found)

which I thought should match the function signature but it says I have the wrong number of arguments

or

with safearray_as_ndarray:
    peaks_found= feature_id.FindFeatures( ptr, strDataBasePath, strRulesPath,float(param1), float(param2), float(param3), int(1))

Which yields the comtypes error code mentioned above.

I'm using comtypes=1.4.10, numpy=1.26.4, python=3.11.11 I've tried a number of different things after googling my issue, reading the open issues on the comtypes github project, looking through the comtypes source, and combing StackOverflow, but it feels like I'm still fumbling in the dark.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744773179a4592885.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信