Hello.

I have an old VB project using a dynamic library. I thought it would be good to use this from Python through ctypes. However, the information of function names in the dll is stripped. If I open the dll with the dependency viewer I get something like:

    4 (0x0004) Function N/A Entry point 0x0006C3A8
    6 (0x0006) Function N/A Entry point 0x00001000
    ...
up to entry 1081.

However, the VB project using this DLL contains a "Public declare" file which only uses 22 functions, and they are in the form:

    Public Declare Function DllGetVersion _
                            Lib "LIBDLL" _
                            Alias "#2" _
                            () _
                            As String

where the only thing changing is the name of the function, the alias number and the type of parameters (this function doesn't require any). The aliases start with "#1" and go up to "#21".

Now, how do I relate this into Python? I can access the DLL:

    dll = ctypes.windll.LIBDLL

    prototype = ctypes.WINFUNCTYPE(ctypes.wintypes.LPCSTR)
    GetDllVersion = prototype(dll[6])
    print "GetDllVersion: '%s'" % repr(GetDllVersion())

So I thought the alias #2 thingy specifies the order inside the DLL, which would be function 6, since that is the second one. But the result I'm getting is

    GetDllVersion: ''  \x07\x10D''

The respective VB code would be:

    MsgBox ("Version " & DllGetVersion)

Which outputs:

    Version 1.3.0 (Build 403)

Far different from what I'm getting in python. So how can I use the VB declaration file to access the DLL the same way? Unfortunately the DLL doesn't expose the names, so I can only access functions with the attribute getter using an index.

I tried to search for the function using a loop over all the functions, but that seems to hang up on nearly every second function. Besides, I might be doing something wrong with the return value.

Any suggestions?

--
Rastertech España S.A.
Grzegorz Adam Hankiewicz
Jefe de Producto TeraVial

C/ Perfumería 21. Nave I. Polígono industrial La Mina
28770 Colmenar Viejo. Madrid (España)

Tel. +34 918 467 390 (Ext.18)   ·   Fax +34 918 457 889
[EMAIL PROTECTED]   ·   www.rastertech.es

_______________________________________________
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to