0

I am using Windows 10 and Visual Studio 2015 with Python 3.4.4 (from the Python Software Foundation)

I want to call some functions in a DLL I wrote. I have tried several approaches found on this forum but get one type of error or another. I have worked from examples but may be misunderstanding something. I have set my path to include the folder containing the DLL. Does anyone know what is going wrong?

Here is the output from the most recent try (my DLL is in the last folder in the path):

Python 3.4 interactive window [PTVS 2.2.31124.00-14.0]
Type $help for a list of commands.
>>> from ctypes import *
>>> from builtins import print
>>> import os                       # needed for os.system()
>>> import ctypes
>>> from ctypes.util import find_library
>>> os.system("path")
0PATH=C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\NativeBinaries\x86;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;w:\eddy2;C:\Program Files (x86)\Common Files\Seagate\SnapAPI\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\SlikSvn\bin;C:\Program Files (x86)\Common Files\Acronis\SnapAPI\;C:\Program Files (x86)\Skype\Phone\;C:\Program Files\Microsoft\Web Platform Installer\;C:\Program Files\Git\cmd;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Program Files (x86)\Windows Live\Shared;C:\Users\eddyq\.dnx\bin;C:\Program Files\Microsoft DNX\Dnvm\;C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit\;W:\Dropbox\DSI (His)\Windows Apps\Debug

>>> os.system("where DsiLibrary_dll.dll")
W:\Dropbox\DSI (His)\Windows Apps\Debug\DsiLibrary_dll.dll
0
>>> print (find_library('DsiLibrary_dll'))          #this does print the location of the DLL
W:\Dropbox\DSI (His)\Windows Apps\Debug\DsiLibrary_dll.dll
>>> nidaq_cdecl   = ctypes.CDLL('DsiLibrary_dll')   #this gives an error "%1 is not a valid Win32 application"
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python34\lib\ctypes\__init__.py", line 351, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: [WinError 193] %1 is not a valid Win32 application
>>> nidaq  = ctypes.cdll.LoadLibrary(find_library('DsiLibrary_dll'))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python34\lib\ctypes\__init__.py", line 429, in LoadLibrary
    return self._dlltype(name)
  File "C:\Python34\lib\ctypes\__init__.py", line 351, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: [WinError 193] %1 is not a valid Win32 application
>>>
2
  • Have you done a positive DLL test via calls from another environment ( calling from c et al ) ? Commented Jan 1, 2016 at 21:48
  • Using LoadLibrary in C works. Commented Jan 1, 2016 at 22:25

1 Answer 1

1

This works now, I was apparently mixing a 32 bit library with a 64 bit Python.

nidaq = ctypes.cdll.LoadLibrary(find_library('DsiLibrary_dll'))

Thanks to everyone for your help.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.