On Mon, May 28, 2012 at 6:37 AM, Suresh Joshi <sure...@gmail.com> wrote:
> Hello all!
>
> I had a question about how to handle void* and HWNDs from within Python
> using Boost::Python and Py++. Reading through the Py++ documentation, I'm
> loving how I can slice and dice my classes/wrappers and seemingly do
> whatever I want with them, but there's still A LOT I haven't figured out.
>
> I've found a previous set of similar questions here:
> http://boost.2283326.n4.nabble.com/Wrapping-and-Passing-HWND-with-Boost-Python-td4598953.html
> but didn't fully understand the automated implementation details.
>
> All the relevant code is posted at the end, but my main questions were as
> follows.
>
> (1) Using the win32gui Python library, HWNDs are passed around as ints
> describing the address of the window. These can be reinterpret_cast'ed into
> HWNDs in C++ and that seems to work fine. However, using Py++, how can I
> automatically inject a reinterpret_cast into Foo's constructor, or the
> initializer list of a constructor wrapper?
>
> I've found these commands,
> .add_declaration_code(...)
> .add_registration_code(...)
> .add_wrapper_code(...)
> but they don't place code where I need it to go.
>
> So, is there a command that I should be using? My goal is to not touch my
> Foo.hpp code (as in, no added code, no helper code), so I would like
> everything to stay within the Boost::Python generated wrapper code
> (FooWrapper.cpp).

What you can do is to generate global function, which takes HWND as
integer, does casting and returns your object (via std::auto_ptr).
Then, you can add registration code, that use
boost::python::make_constructor function to create your class.

> (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?

I think Py++ repository contains ctypes + boost.python integration
code example. It worse to check it.

Regards,
Roman.
_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig

Reply via email to