[python-win32] Recovering a DLL with ctypes from a VB project
Grzegorz Adam Hankiewicz
ghankiewicz at rastertech.es
Tue Apr 10 14:23:43 CEST 2007
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
ghankiewicz at rastertech.es *·* www.rastertech.es
<http://www.rastertech.es/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-win32/attachments/20070410/d285be44/attachment.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sig.png
Type: image/png
Size: 10038 bytes
Desc: not available
Url : http://mail.python.org/pipermail/python-win32/attachments/20070410/d285be44/attachment.png
More information about the Python-win32
mailing list