[C++-sig] Injecting void* and HWND handling code from Py++
Niall Douglas
s_sourceforge at nedprod.com
Tue May 29 20:23:03 CEST 2012
On 27 May 2012 at 20:37, Suresh Joshi wrote:
> (2) From Python, I would like to manipulate the memory of a buffer stored
> within Foo. In my REAL code, the only accessor I can use is Address() which
> returns a void pointer, which Py++/BP flips into an opaque pointer (which I
> don't think I can use to manipulate m_buffer's memory in Python).
>
> One option is ctypes, but I frankly just don't know how to combine that with
> BP for the purpose of manipulating data behind a void*, even after having
> looked at the ctypes integration code in the Py++ docs.
>
> The other option is to do something like what I did with the fake VoidPtr()
> accessor. I could create accessors like VoidPtrAsUChar() for example, and
> then expose those using the return_addressof call policy (hopefully!). If
> this is, in fact, a valid approach, then I have the same question as
> above...
>
> Given that I can't change the Foo.hpp code, is there a clean way of
> injecting those AsUChar, AsInt, As... helper methods straight into the
> wrapper code, so that they call Address() internally and then
> reinterpret_cast the returned void* into something more useful and
> accessible in Python?
If you really, really want to do this, I would have the wrapper of
your Address method return an array-like interface e.g. like a
std::vector<>. Look into the indexing suite - a method of
implementing direct image bitmap access from python came up on this
list a few years back.
Niall
--
Technology & Consulting Services - ned Productions Limited.
http://www.nedproductions.biz/. VAT reg: IE 9708311Q.
Work Portfolio: http://careers.stackoverflow.com/nialldouglas/
More information about the Cplusplus-sig
mailing list