title: calling a function from dll in python
body: <p>I am trying to make a call from python to a dll but am getting an access violation.Can some please tell me how to use ctypes correctly in the following code.  GetItems is supposed return a struct that looks like this</p>
  
  <pre><code>struct ITEM
  {
   unsigned short id;
   unsigned char i;
   unsigned int c;
   unsigned int f;
   unsigned int p;
   unsigned short e;
  };
  </code></pre>
  
  <p>I'm really only interested in getting the id, do not need the other fields.  I have my code listed below, what am i doing wrong?  Thanks for the help.</p>
  
  <pre><code>import psutil
  from ctypes import *
  
  def _get_pid():
      pid = -1
  
      for p in psutil.process_iter():
          if p.name == 'myApp.exe':
              return p.pid
  
      return pid
  
  
  class MyDLL(object):
      def __init__(self):
          self._dll = cdll.LoadLibrary('MYDLL.dll')
          self.instance = self._dll.CreateInstance(_get_pid())
  
      @property
      def access(self):
          return self._dll.Access(self.instance)
  
      def get_inventory_item(self, index):
          return self._dll.GetItem(self.instance, index)
  
  
  if __name__ == '__main__':
  
      myDLL = MyDLL()
      myDll.get_item(5)
  </code></pre>