Python ctypes and not enough arguments (4 bytes missing)

The function I'm trying to call is:

void FormatError (HRESULT hrError,PCHAR pszText);

from a custom dll using windll.

c_p = c_char_p()
windll.thedll.FormatError(errcode, c_p)

Results in:

ValueError: Procedure probably called with not enough arguments (4 bytes missing)

Using cdll instead increases the counter, which is not in bytes, to 12. errcode above is errercode returned from another function from the same DLL. How to get the right to call?

+3
source share
3 answers

At the very least, you will get more descriptive errors if you configure argtypesand correctly restype.

Try this as follows:

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

, - " " " " , .

+2
0

, , FormatError ctypes

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

ctypes.FormatError([])

Windows: . , api Windows GetLastError.

0

Source: https://habr.com/ru/post/1718257/


All Articles