use of calldll

Jimmy Retzlaff jimmy at retzlaff.com
Fri Apr 19 09:07:16 EDT 2002


> Piero [mailto:picodello at yahoo.it] writes:
>  I use the very good calldll module to interface to Windows DLL.

I agree that it is very good. I find it even better when using the
windll module which is part of the dynwin package from the same author.
windll is a Python wrapper around calldll that simplifies looking up and
calling dll functions. You can use windll separately from the rest of
dynwin (which has many examples of using windll).

> Something can help on using VARIANT type in Python and CALLDLL

The article here describes VARIANTs:
http://msdn.microsoft.com/archive/en-us/dnarextvb/html/msdn_article4.asp

The most important part is the C struct definition right near the top.
>From a Python calldll / struct module perspective, you want to read out
the first 2 bytes (as a struct module type 'H'). This tells you how to
interpret the contained value, i.e. its data type. The possible values
are documented here:
http://www.marin.clara.net/COM/variant_type_definitions.htm

You need to translate those data types into struct module format
strings. A dictionary can be very nice here. For example:

variantTypeMappings = {
    3  : 'l', # VT_I4
    17 : 'B', # VT_UI1
    2  : 'h', # VT_I2
    # etc.
}

Then, bytes [8:8+struct.calcsize(variantTypeMappings[vt])] from the
memory buffer should be passed to struct.unpack with
variantTypeMappings[vt] as the format string.

Win32all does automatic translation to/from variants for working with
COM Automation. I don't know if that functionality is exposed for direct
use, but if it is that would be a lot simpler than rolling your own.

Jimmy





More information about the Python-list mailing list