作者cobrasgo (体重突破所有均线)
看板Python
标题[问题] ctype注册callback function
时间Mon Jan 24 18:54:59 2011
小弟目前在写程式呼叫期货商的API
但是碰到了问题
程式如下
import ctypes
from ctypes import *
import traceback
class qyAPI:
def __init__(self):
self._qyDllPath = "SKOrderLib.dll"
self._account = ""
self._passwd = ""
self._apiInit()
def _apiInit(self):
try:
self._qyAPI = windll.LoadLibrary(self._qyDllPath)
self._SKOrderLib_Initialize = self._qyAPI.SKOrderLib_Initialize
self._RegisterOnOpenInterestCallBack = self._qyAPI.RegisterOnOpenInterestCallBack
#initialization
ret = self._SKOrderLib_Initialize(self._account, self._passwd)
print "init result is ", ret
CMPFUNC = CFUNCTYPE(c_int, POINTER(c_char_p))
cb = CMPFUNC(self._oiCallback)
#register a callback to get open interest status
ret = self._RegisterOnOpenInterestCallBack(addressof(cb))
print "oi result is ", ret
except:
traceback.print_exc()
def _oiCallback(self, returnString):
print "_oiCallback start"
print returnString
print "_oiCallback end"
qyAPI()
raw_input()
=================
其中的dll我放到
http://www.badongo.com/file/25000608
不过帐密这个就不方便po上来
所以可能在测试上面的程式时会有问题…
呼叫RegisterOnOpenInterestCallBack这个function,需要传一个callback function
但是我这样写似乎是有问题的
callback function并没有进去
请问我要register callback function的话
要怎麽写呢?
若是有资讯不足的地方
我会再补上来
谢谢
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 220.130.51.128
※ 编辑: cobrasgo 来自: 220.130.51.128 (01/24 19:10)