title: C++ class in Python via Ctypes
body: <p>I have this code in C++:</p>
  <pre><code>#include &lt;iostream&gt;
  
  class Foo{
  public:
      void bar(){
          std::cout &lt;&lt; &quot;Hello&quot; &lt;&lt; std::endl;
      }
  };
  extern &quot;C&quot; {
  Foo* Foo_new(){ return new Foo(); }  # I tried __declspec(dllexport) on these funcs, same error
  void Foo_bar(Foo* foo){ foo-&gt;bar(); }
  }
  </code></pre>
  <p>I compiled this into a MODULE library and tried to access this class in Python:</p>
  <pre><code>import ctypes
  
  lib = ctypes.CDLL('C:\\Users\\avishah\\CLionProjects\\Math\\lib\\libpythonclass.dll')
  
  class Foo(object):
      def __init__(self):
          self.obj = lib.Foo_new()
  
      def bar(self):
          lib.Foo_bar(self.obj)
  </code></pre>
  <p>The problem is that it fails to load the library itself:</p>
  <pre><code>Traceback (most recent call last):
    File &quot;C:/Users/avishah/PycharmProjects/Math/pythoncpp/test.py&quot;, line 4, in &lt;module&gt;
      lib = ctypes.CDLL('C:\\Users\\avishah\\CLionProjects\\Math\\lib\\libpythonclass.dll')
    File &quot;C:\Python\Python38\lib\ctypes\__init__.py&quot;, line 373, in __init__
      self._handle = _dlopen(self._name, mode)
  FileNotFoundError: Could not find module 'C:\Users\avishah\CLionProjects\Math\lib\libpythonclass.dll' (or one of its dependencies). Try using the full path with constructor syntax.
  </code></pre>
  <p>I tried many examples online but all fail with this error... One thing I noticed is the other examples all had .so files but since I'm on Windows, I use .dll files, also there is an additional need for __declspec(dllexport).</p>
  <p><strong>EDIT:</strong>
  I am using MinGW compiler. Is this related to the compiler? Should I be using MSVC compiler?</p>