Re: Writing to memory buffer in a .dll?
Thomas Heller <[email protected]> Wed, 04 Sep 2013 12:29:56 +0200
| Newsgroups | gmane.comp.python.ctypes |
|---|---|
| Message-ID | <[email protected]> |
Am 30.08.2013 22:47, schrieb Brad Basler: > I am attempting to use Python w/ctypes to control an embedded > programming tool (see UM0151, STMicroelectronics). > > I had this working before as a basic test, but not really realizing what > I'm doing differently now. I do not seem to be writing to the code image. > > Here's the function prototype I am trying to interface with. > Prototype: char far *EGetImagePtr(DWORD dwAreaId, long *MemSize) > > This returns a pointer that is allocated on the heap by the .dll > > I can read from this buffer, but I don't appear to be able to write to it. > > > where my function was defined by: > EPRCore.dll_eprcore.EGetImagePtr.argtypes = > [ctypes.c_uint,ctypes.c_void_p] > > EPRCore.dll_eprcore.EGetImagePtr.restype = > ctypes.POINTER(ctypes.c_char) > > > > > ptr = self.myEPR.EGetImagePtr(self.memHandle,ctypes.byref(self.memSize)) > ptr[0x8112] = 0x00; > ptr[0x8113] = 0x01; > ptr[0x8114] = 0x02; > ptr[0x8115] = 0x03; Well, if ptr is really a POINTER(c_char) instance then the above lines should raise an error: >>> p[0] = 0x00 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: one character string expected >>> Thomas ------------------------------------------------------------------------------ Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more! Discover the easy way to master current and previous Microsoft technologies and advance your career. Get an incredible 1,500+ hours of step-by-step tutorial videos with LearnDevNow. Subscribe today and save! http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk