Calling Function in DLL on Windows

Geoff Talvola gtalvola at NameConnector.com
Fri Jun 2 16:42:54 EDT 2000


dsavitsk wrote:

> i need to call a DLL from within a python program. in VB i would declare the
> function like...
>
> Declare Function LoadSFW Lib "Sfwlnk32" (ByVal strPath As String, ByVal
> strConfig As String) As Long
>
> then use it later like...
>
> intErrorCode = LoadSFW("C:\SFW", 6)
>
> i don't know how to do this in Python, so any quick explanation would be
> helpful.

I can think of 3 ways:

 - if it's a COM DLL, use the win32com package.
 - you could write your own extension module.
 - the easiest way is to use Sam Rushing's calldll and windll modules.

For simple stuff, the windll module makes it super-easy.  For example, this puts
up a message box using the Win32 MessageBox function which lives in user32.dll:

from windll import module, cstring
user32 = module('user32')
user32.MessageBox(0, cstring('This is a really easy way to call a DLL'),
                  cstring('Wowee'), 0x30)

Calldll lets you call more complicated functions.

You can download them from http://www.nightmare.com/software.html and you'll
need both the calldll package and the DynWin package, which contains the windll
module.

The "Python Programming on Win32" book contains information like this, and is
really useful if you're using Python in a serious way on Windows.

--


- Geoff Talvola
  Parlance Corporation
  gtalvola at NameConnector.com






More information about the Python-list mailing list