02-26-2014
01:12 PM
- last edited on
08-14-2024
03:22 PM
by
Content Cleaner
I'm attempting to call Labview defined functions found in a DLL from Python. I based my code on some sample code I found in a white paper. When I hit an error when trying to load the DLL, I tried using the sample code, and that hit the same errror.
Here's the white paper: https://forums.ni.com/t5/Example-Code/Advanced-Scripting-in-Perl-Python-and-Tcl/ta-p/3984352
Here's the sample python code provided by NI (simpledll.dll is on the white paper page):
from ctypes import *
#Load the DLL
dll = cdll.LoadLibrary("SimpleDLL.dll")
x = 5
y = 3
#Create sum as a c style integer
sum = c_int(0)
string = create_string_buffer("", 20)
#Function Prototype: int addNumbers (int x, int y, int *sum, char *string)
#Call the Function
#Pass pointers using the byref keyword
returnValue = dll.addNumbers(x, y, byref(sum), byref(string))
#Print Results
print ("Sum: ", sum, "\n")
print ("String: ", repr(string.raw), "\n")
print ("returnValue: ", returnValue, "\n")
This is the error I get when I run the script:
Traceback (most recent call last):
File "C:\Users\trevor.apple\Desktop\TestDLL\CallSimpleDLL.py", line 4, in <module>
dll = cdll.LoadLibrary("SimpleDLL.dll")
File "C:\Python33\lib\ctypes\__init__.py", line 431, in LoadLibrary
return self._dlltype(name)
File "C:\Python33\lib\ctypes\__init__.py", line 353, in __init__
self._handle = _dlopen(self._name, mode)
OSError: [WinError 193] %1 is not a valid Win32 application
I definitely have both files in the same directory, and I've also tried including the full file path to the dll in the load call. Please advise.
02-26-2014 07:01 PM
Well, you probably have the 64 bit version of Python installed and created the DLL in the 32 Bit version of LabVIEW. That can't work. Both DLL and calling process need to be the same bitness.