title: Using ctypes in python to access a C# dll's methods
body: <p>I would like to implement C# code in a critical part of my python program to make it faster. It says (on Python documentation and <a href="http://www.knowledgetantra.com/component/content/article/2-python/1-call-dll-function-in-python.html]" rel="noreferrer">this site</a>) that you can load a Dynamic Link Library (and so say the PyDocs) as follows: </p>
  
  <p><code>cdll.LoadLibrary("your-dll-goes-here.dll")</code></p>
  
  <p>This is the part of my code that takes care of this feature:</p>
  
  <pre><code>from ctypes import *
  z = [0.0,0.0]
  c = [LEFT+x*(RIGHT-LEFT)/self.size, UP+y*(DOWN-UP)/self.size]
  M = 2.0
  
  iterator = cdll.LoadLibrary("RECERCATOOLS.dll")
  
  array_result = iterator.Program.ITERATE(z[0],z[1],c[0],c[1],self.iterations,M)
  
  z = complex(array_result[0],array_result[1])
  c = complex(array_result[2],array_result[3])
  last_iteration = int(round(array_result[4]))
  </code></pre>
  
  <p>And the RECERCATOOLS.dll that I use is this (C# code, not C or C++):</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using KarlsTools;
  
  public class Program
  {
      public static Array ITERATE(double z_r,double z_i,double c_r,
                          double c_i, int iterations, 
                          double limit)
      {
          Complex z = new Complex(z_r, z_i);
          Complex c = new Complex(c_r, c_i);
  
          for (double i = 1; Math.Round(i) &lt;= iterations; i++)
          {
              z = Complex.Pow(z, 2) + c;
              if (Complex.Abs(z) &lt; limit)
              {
                  double[] numbers = new double[] { Complex.Real(z),
                                                    Complex.Imag(z),
                                                    Complex.Real(c),
                                                    Complex.Imag(c),
                                                    i};
                  return numbers;
              }
          }
          double iter = iterations;
          double[] result = new double[]        { Complex.Real(z),
                                                    Complex.Imag(z),
                                                    Complex.Real(c),
                                                    Complex.Imag(c),
                                                    iter};
          return result;
      }
  }
  </code></pre>
  
  <p>To build this DLL I use "Build" command over the Visual Studio 2010 project, which only contains this file and a reference to "Karlstools", a module that allows me to use complex numbers.</p>
  
  <p>I don't know why but when I try to run my Python code, it just throws an exception:</p>
  
  <pre><code>    [...]
      array_result = iterator.Program.ITERATE(z[0],z[1],c[0],c[1],self.iterations,M)
    File "C:\Python32\lib\ctypes\__init__.py", line 353, in __getattr__
      func = self.__getitem__(name)
    File "C:\Python32\lib\ctypes\__init__.py", line 358, in __getitem__
      func = self._FuncPtr((name_or_ordinal, self))
  AttributeError: function 'Program' not found
  </code></pre>
  
  <p>I need help with this, since it keeps throwing me exceptions even with everything is set to <code>public</code> and the function as <code>static</code>, or even when if I try to access the function directly without specifying the "Program" class... I have no clue where the problem could be.</p>