0

I'm searching for a way to use DLL in Python, I found ctypes that should fix it but I can't get to make it work...

Do I need to install DLL first? (by executing it on windows with 'regsvr32..file..') If yes, how... The DLL files I got are 'Files' not 'programms' and I can't launch them (not found by the executor in system32)

If not, I first can't see the DLL files I added to system32 (thought it could help to put them there) in my Python's browser and if they are somewhere else, it gives me the error [WinError 193] %1 is not a valid Win32 application.

My script:

import ctypes

malib = ctypes.WinDLL("D:\Documents\Python Scripts\ClaymoreProtocol.dll")

malib.SetClaymoreKeyboardMode(1) #SetClaymoreKeyboardMode is a function of the dll

(https://www.asus.com/campaign/aura/us/SDK.html the link for the SDK i'm trying to use)

R.Reus
  • 1
  • 1
  • 2
  • First, did you read the docs on [the three Windows calling conventions](https://docs.python.org/3/library/ctypes.html#loading-dynamic-link-libraries)? If you open a library with WinDLL instead of CDLL but it uses the C rather than stdcall convention, it won't work. – abarnert Mar 25 '18 at 01:35
  • Second, you only need to install if you want to find it automatically (e.g., `ctypes.windll.ClaymoreProtocol`) instead of by relative or absolute path. I think (I haven't done this for a while on Windows, so I may be wrong) that you need to copy it somewhere on the PATH for that to work, not just register it in-place. But at any rate, your code is using an absolute path, so that isn't an issue. – abarnert Mar 25 '18 at 01:37
  • Also, don't use unescaped backslashes in path strings. I'm pretty sure you're getting lucky here and that isn't an issue, but read [here](https://stackoverflow.com/questions/2953834/windows-path-in-python) for how to do it right. – abarnert Mar 25 '18 at 01:38
  • Yes i went to this page whatever method I use it doesn't work. Still the same error. (thanks for the advices for path/install) – R.Reus Mar 25 '18 at 12:06
  • Find out that this works (with WinDLL) using python 2.7 and not python 3.6 – R.Reus Mar 25 '18 at 17:47
  • Next guess then: Your library, Python 2.7, and Python 3.6—any chance two of them are 32-bit versions and one is 64-bit, or vice-versa? – abarnert Mar 25 '18 at 17:48
  • Seems that 2.7 can communicate throught 32 and 64 bit with windows but didn't find any int about it in 3.6 – R.Reus Mar 25 '18 at 18:18
  • I don't know what that last reply means. There are 32-bit and 64-bit installers for both Python 2.7 and Python 3.6. If you, say, install a 32-bit Python 3.6, and then try to open a 64-bit DLL, it will fail. If you install a 64-bit Python 2.7, and try to open the same 64-bit DLL, it will succeed. But that's not because of 3.6 vs. 2.7, it's because of 32-bit vs. 64-bit. – abarnert Mar 25 '18 at 18:21
  • I don't know then sorry – R.Reus Mar 25 '18 at 18:28

0 Answers0