※ 引述《sbrhsieh (偶爾想擺爛一下)》之銘言:
: ※ 引述《cobrasgo (體重突破所有均線)》之銘言:
: : 另外之前試不起來的主因是這行
: : CMPFUNC = CFUNCTYPE(c_int, comtypes.BSTR)
: : 就是create ctype的callback function時
: : 它應該是會去檢查這個type對不對
: : 我把參數那欄改成comtypes.BSTR之後
: : 就可以work了
: : 我想簡單的說就是它對參數的格式
: : 檢查很嚴格吧
: 透過 CFUNCTYPE/WINFUNCTYPE 來建立 function wrapper type 時不會檢查 formal
: parameter 的型別,而是指定的 formal parameter 型別會決定 wrapper function
: 如何處理 actual arguments 與如何傳遞給 wrapped function。
: 把一個 Python function/callable wrapping 成 function wrapper type(比如
: 上述的 CMPFUNC)時,也不會檢查型別,因為 Python function 的 formal parameter
: 在 Python level 沒有 compile-time 型別資訊。
請問一下這段知識是從哪裡看到的啊?
我也很想了解python稍為底層的東西
總是覺得不知從何下手
直接看source code?
: : 但是還有兩個問題
: : 1) 有error
: : Traceback (most recent call last):
: : File "_ctypes/callbacks.c", line 320, in 'converting callback result'
: : TypeError: an integer is required
: : Exception in <bound method qyAPI._oiCallback of <__main__.qyAPI instance
: : at 0x00EE8C88>> ignored
: : Traceback (most recent call last):
: : File "C:\qy\2.1.5\ctypes\qyAgent.py", line 81, in go
: : self._GetUserAccount()
: : ValueError: Procedure probably called with too many arguments (942000 bytes
: : in excess)
: : 官網上對這個error的說法是1)錯誤的參數個數,或是2)錯誤的calling convention
: : 應該是第二個wrong calling convention
: : 但是這個我就沒有想法了囧
: 以參數過多來看,你使用的套件(DLL)應該是以 __stdcall 方式來調用註冊的
: callback function,那麼你在定義 wrapper function type 時,應使用
: WINFUNCTYPE。
: CMPFUNC = WINFUNCTYPE(c_int, comtypes.BSTR)
: 後來實際去 download 你提供的 API 文件來看,這個 DLL 實際上是一個 COM
: object 的實作,或許你可以考慮在你的 Python runtime 上安裝 pywin32 套件
: 或是直接安裝有內建(整合) pywin32 的 Python implementation(如 ActiveState
: 出品的 ActivePython),以操作 COM object 的方式來使用該 DLL。
我剛剛試
果然那個error不見了
但另一個error又跑出來
不過解掉了
明天再貼完整且沒error的code跟大家分享
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.25.185.67
※ 編輯: cobrasgo 來自: 114.25.185.67 (01/28 00:20)