Python ctypes and not enough arguments (4 bytes missing)

前端 未结 3 414
情话喂你
情话喂你 2021-01-03 07:40

The function i\'m trying to call is:

void FormatError (HRESULT hrError,PCHAR pszText);

from a custom dll using windll.

c_p          


        
相关标签:
3条回答
  • 2021-01-03 08:02

    At the very least, you'll get more descriptive errors if you properly set up the argtypes and the restype.

    Try doing it this way:

    windll.thedll.FormatError.argtypes = [ctypes.HRESULT, ctypes.c_char_p]
    windll.thedll.FormatError.restype  = None
    

    There's also a very good chance you are using the wrong calling convention -- check out the Calling Functions section and the Loading Libraries section for details on how to use a different calling convention.

    0 讨论(0)
  • 2021-01-03 08:03

    Actually I think you want to use FormatError as provided by ctypes

    http://docs.python.org/library/ctypes.html#ctypes.FormatError

    ctypes.FormatError([code])

    Windows only: Returns a textual description of the error code. If no error code is specified, the last error code is used by calling the Windows api function GetLastError.

    0 讨论(0)
  • 2021-01-03 08:05

    Have you tried to use the ctypes.HRESULT?

    0 讨论(0)
提交回复
热议问题