views:

383

answers:

3

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 bytes missing counter to 12. errcode above is the errercode returned from another function out of the same dll. How do I get the call right?

A: 

Have you tried to use the ctypes.HRESULT?

luc
+1  A: 

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.

Mark Rushakoff
I tried setting argtypes and restype, without luckas I can access other functions without problems using windll I think windll should work here too
theFloe
Okay, but the Calling Functions section *exactly* shows the same error as you had above, saying `4 bytes missing`. You're able to call other functions in that *same* DLL with `windll`?
Mark Rushakoff
Yes I'm able to call the other functions with windll. But not this one...
theFloe
A: 

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.

Nick Craig-Wood
The DLL provides it's own FormatError Function and I want to use it.
theFloe