0
I’m trying to import a dll C/C++ with the lib ctypes and use a function that it has internally, when passing the parameters to this function I always come across the error:
ERROR: exception: access violation writing 0x00DEF6CC
Process finished with exit code 1
I’ve used cast
, string_buffer
and POINTER
, but I still get the same mistake anyway
Follows the code:
import ctypes
import sys
file_path = './lib/poc-pagamento-dpos.dll'
integracao_pos = ctypes.cdll.LoadLibrary(file_path)
def main():
try:
integracao_pos.carregarRegistros()
integracao_pos.atribuirCallbacks(callback=display_msg)
transacao_credito()
except OSError as e:
print("ERROR: %s" % e)
sys.exit(1)
def transacao_credito():
pNumeroControle = ctypes.create_string_buffer(b"1234567")
pValorTransacao = ctypes.create_string_buffer(b"15000")
pNumeroCupom = ctypes.create_string_buffer(b"1234567")
pTipoOperacao = ctypes.create_string_buffer(b"FA")
pNumeroParcelas = ctypes.create_string_buffer(b"2")
pValorParcela = ctypes.create_string_buffer(b"0")
integracao_pos.transacaoCartaoCreditoDPOS.argtypes = [ctypes.c_char_p, ctypes.c_char_p, ctypes.c_char_p,
ctypes.c_char_p, ctypes.c_char_p, ctypes.c_char_p]
integracao_pos.transacaoCartaoCreditoDPOS(pValorTransacao, pNumeroCupom, pNumeroControle,
pTipoOperacao, pNumeroParcelas, pValorParcela)
def incluir_zeros_esquerda(num, size):
s = str(num)
while s < size:
s = "0{}".format(s)
return s
def display_msg(msg):
print("----------------->{}".format(msg))
if __name__ == '__main__':
main()
Does anyone have any idea what I might be doing wrong?
Put the code C, only with the python code has no way of knowing the problem. Also, try to reduce your code minimally to the scope of the problem.
– João Paulo
Maybe just post the header of the functions
carregarRegistros
,atribuirCallbacks
andtransacao_credito
already solve, but I would guess that the problem is in theatribuirCallbacks
, since you should define the type of argument this function should receive before passing a callback.– Fernando Silveira