[python-win32] Wrapper Windows Installer API functions, ctypes, .dll

Marcus Low marcus at internetnowasp.net
Sun Feb 24 12:26:25 CET 2008


I love this community, you guys are really patient. Backslashes......
If you want to use single backslashed, you probably need to use "r" in front 
of the string

http://docs.python.org/ref/strings.html

I strongly recommend anyone new to python to get :-

1. learning python from Mark lutz
2. python on win32 , mark hammond

Its money well spent, you will be asking less questions that you wish u 
didnt ask.

----- Original Message ----- 
From: "Tim Roberts" <timr at probo.com>
To: "Python-Win32 List" <python-win32 at python.org>
Sent: Saturday, February 23, 2008 2:54 AM
Subject: Re: [python-win32] Wrapper Windows Installer API functions, ctypes, 
.dll


Erik Fløisbonn wrote:
> Hello, I am creating a .dll that I load in python with ctypes. The
> .dll calls Windows Installer API functions (like MsiEnumProducts). I
> am having trouble calling these functions from python. When I import
> the msilib (or _msi) that comes with python, the function calls work.
> But when I do not import them, the call does not work and I get the
> following error message:
>
> WindowsError: [Error 182] The operatingsystem can not run %1
>
> (Original message is in norwegian: WindowsError: [Error 182]
> Operativsystemet kan ikke kjøre %1)
>
> I am wondering why the function calls are not working when I do not
> import the msi module, and why they work when I do import the module.
>
> I am running Windows Vista and python 2.5.1. I am compiling the source
> code with cl (from the windows SDK) like this:
>
> cl /LD msi.c msi.def  "C:\Program Files\Microsoft
> SDKs\Windows\v6.0\Lib\Msi.lib"
>
> My python file looks like this:
>
> from ctypes import *
> # import msilib (everything works when I uncomment this)
> print cdll.LoadLibrary("C:\Users\Erik\Documents\INF5660\Msi.dll").test(2)

You can't write normal strings with single backslashes!  You happened to
get lucky here, because 'u', 'e', 'd', 'i', and 'm' aren't recognized
escape codes, but if your name had been "Tom", this would not work.

You can write this in one of three ways:
   print
cdll.LoadLibrary("C:\\Users\\Erik\\Documents\\INF5660\\Msi.dll").test(2)
   print
cdll.LoadLibrary(r"C:\Users\Erik\Documents\INF5660\Msi.dll").test(2)
   print cdll.LoadLibrary("C:/Users/Erik/Documents/INF5660/Msi.dll").test(2)

However, this is not causing your immediate problem.

You might try dumping the imports for your DLL, to see if it needs a DLL
that it's not finding.  You can use the "depends" tool for that, or just
"link /dump /exports msi.dll".

-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.

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




More information about the python-win32 mailing list