Python ctypes ERROR: Exception: access Violation writing 0x00DEF6CC

Asked

Viewed 51 times

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.

  • Maybe just post the header of the functions carregarRegistros, atribuirCallbacks and transacao_credito already solve, but I would guess that the problem is in the atribuirCallbacks, since you should define the type of argument this function should receive before passing a callback.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.