Bellow the code that I made in python.
# A foreign function library for Python
from ctypes import *
import ctypes
# Import DLL from Delphi code
#Init = ctypes.CDLL ("ProfitDLL.dll")
#Init = ctypes.OleDLL ("ProfitDLL.dll")
#Init = ctypes.PyDLL ("ProfitDLL.dll")
Init = ctypes.WinDLL ("ProfitDLL.dll")
# Activation code
pwc_activation_key = "1234567890123456789"
# define the callback signature, the first value is return type
#TStateCallBack = CFUNCTYPE(c_int, POINTER(c_int), POINTER(c_int))
#TStateCallBack = WINFUNCTYPE(c_int, POINTER(c_int)) # specify the correct callback signature
TStateCallBack = WINFUNCTYPE(c_int, POINTER(c_int)) # specify the correct callback signature
TNewTradeCallback = WINFUNCTYPE(c_int, POINTER(c_int)) # specify the correct callback signature
TNewDailyCallback = WINFUNCTYPE(c_int, POINTER(c_int)) # specify the correct callback signature
THistoryTradeCallBack = WINFUNCTYPE(c_int, POINTER(c_int)) # specify the correct callback signature
#TProgressCallBack = WINFUNCTYPE(c_int, POINTER(c_int)) # specify the correct callback signature
TTinyBookCallBack = WINFUNCTYPE(c_int, POINTER(c_int)) # specify the correct callback signature
# ////////////////////////////////////////////////////////////////////////////////
# // WARNING: Não utilizar funções da dll dentro do CALLBACK
# ////////////////////////////////////////////////////////////////////////////////
# //Callback do stado das diferentes conexões
def StateCallback(nResult, result):
return 0
# ////////////////////////////////////////////////////////////////////////////////
# //Callback com informações marketData
def NewTradeCallback(TAssetID, assetId, price, vol, qtd, buyAgent, sellAgent, tradeType):
return 1
def NewDailyCallback(TAssetID, TAssetIDRec, date, sOpen, sHigh, sLow, sClose, sVol, sAjuste, sMaxLimit, sMinLimit, sVolBuyer, sVolSeller, nQtd, nNegocios, nContratosOpen, nQtdBuyer, nQtdSeller, nNegBuyer, nNegSeller):
return 2
def HistoryTradeCallBack(TAssetID, assetId, date, price, vol, qtd, buyAgent, sellAgent, tradeType):
return 3
#def TProgressCallBack(TAssetID, assetId, nProgress):
# return 4
def TinyBookCallBack(TAssetID, assetId, price, qtd, side):
return 5
# ////////////////////////////////////////////////////////////////////////////////
# // Functions From ProfitDLL
def MarketCallback():
#
# Initialize DLL
InitializeMarket = Init.InitializeMarket
# set the results type for auto convert and check
InitializeMarket.restype = c_short
# set the arg types for auto convert or check else you have to do StateCallback = TStateCallBack(StateCallback)
# to convert before the call. It works on built-in types. If it fails revert back to the explicit casting as above.
# now call the function
#InitializeMarket.argtypes = [c_wchar_p, c_wchar_p, c_wchar_p, c_wchar_p, c_wchar_p, c_wchar_p]
InitializeMarket.argtypes = [c_wchar_p, TStateCallBack, TNewTradeCallback, TNewDailyCallback, THistoryTradeCallBack, TTinyBookCallBack]
# now call the function
#result = InitializeMarket(pwc_activation_key, StateCallback, NewTradeCallback, NewDailyCallback, HistoryTradeCallBack, TinyBookCallBack)
result = InitializeMarket(pwc_activation_key, TStateCallBack(StateCallback), TNewTradeCallback(NewTradeCallback), TNewDailyCallback(NewDailyCallback), THistoryTradeCallBack(HistoryTradeCallBack), TTinyBookCallBack(TinyBookCallBack))
#result = InitializeMarket(pwc_activation_key, b'StateCallback', b'NewTradeCallback', b'NewDailyCallback', b'HistoryTradeCallBack', b'TinyBookCallBack')
#s = result.decode("utf8")
ValueError: Procedure probably called with not enough arguments (4 bytes missing)
I don't why I got this error, apparently everything is good, I made some changes with ctypes.CDLL, but I still having problem.