I am trying to make a call from python to a dll, but I am getting an access violation. Perhaps some of them will tell me how to use ctypes correctly in the following code. GetItems is supposed to return a structure that looks like this:
struct ITEM
{
unsigned short id;
unsigned char i;
unsigned int c;
unsigned int f;
unsigned int p;
unsigned short e;
};
I'm really interested in just getting the identifier, no other fields are needed. I have my code below, what am I doing wrong? Thanks for the help.
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)
source
share