title: Calling a DLL function from Python
body: <p>I want to call a function inside a DLL from Python. But I'm getting this error:</p>
  
  <pre><code>"Attribute Error function not found"
  </code></pre>
  
  <p>This is my code:</p>
  
  <pre><code>import os
  import ctypes
  
  
  os.chdir("C:\\Program Files\\Compact Automated Testing System V2.0")    
  
  # Load DLL into memory. 
  CATSDll = ctypes.WinDLL ("CATS.dll")
  
  # Set up prototype and parameters for the desired function call. 
  CATSDllApiProto = ctypes.WINFUNCTYPE (ctypes.c_uint8,ctypes.c_double) 
  
  CATSDllApiParams = (1, "p1", 0), (1, "p2", 0), 
  
  # Actually map the call (setDACValue) to a Python name.
  CATSDllApi = CATSDllApiProto (("setDACValue", CATSDll), CATSDllApiParams)
  
  # Set up the variables and call the Python name with them. 
  p1 = ctypes.c_uint8 (1)
  p2 = ctypes.c_double (4)
  
  CATSDllApi(p1,p2)
  </code></pre>
  
  <p>But the DLL documentation shows a function <code>setDACValue</code> with <code>ChannelId</code> &amp; <code>DAC Voltage</code> as the inputs.</p>
  
  <p>The above is based on a piece of code available from StackOverflow.</p>
  
  <p>I've also tried the simple method of using cdll.LoadLibrary &amp; then calling the function, but that also gives the same error.</p>
  
  <p>Can anyone suggest me what is wrong? Thanks.</p>
  
  <p>Full Traceback:</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:\Users\AEC_FULL\Softwares\eclipse\plugins\org.python.pydev_3.9.2.201502050007\pysrc\pydevd.py", line 2235, in &lt;module&gt;
      globals = debugger.run(setup['file'], None, None)
    File "C:\Users\AEC_FULL\Softwares\eclipse\plugins\org.python.pydev_3.9.2.201502050007\pysrc\pydevd.py", line 1661, in run
      pydev_imports.execfile(file, globals, locals)  # execute the script
    File "C:\Users\AEC_FULL\Saravanan\Workspace\CATS\CATS.py", line 18, in &lt;module&gt;
      CATSDllApi = CATSDllApiProto (("setDACValue", CATSDll), CATSDllApiParams)
  AttributeError: function 'setDACValue' not found
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/9usSB.jpg" alt="Signature of the setDACValue"></p>