나는 생성자에서 HWND 창 핸들을 사용하는 C++ 레거시 클래스에 Boost.Python 래퍼 (Py ++ 사용)를 만들었습니다. 그러나 파이썬 모듈을 사용하려고하면 모듈을 내 보낸 후에 형식 불일치 오류가 발생합니다. 여기 Boost.Python으로 HWND 바꿈 및 전달
내가 포장하고있어 C++ 클래스 :// File Foo.hpp
//
#include "Windows.h"
class Foo
{
public:
Foo(const HWND window){}
virtual ~Foo(){}
virtual int Bar(int num) { return num; }
};
Py를 ++ 출력 :
INFO Parsing source file "foo.hpp" ...
INFO gccxml cmd: ""c:\Program Files (x86)\gccxml 0.9\bin\gccxml.exe" -I"." "foo.hpp" -fxml="d:\temp\tmpdng3ts.xml""
INFO GCCXML version - 0.9(1.127)
INFO: file "generated_wrapper.cpp" - updated(0.001607 seconds)
생성 된 래퍼 :
파이썬에서#include "boost/python.hpp"
#include "foo.hpp"
namespace bp = boost::python;
struct Foo_wrapper : Foo, bp::wrapper<Foo> {
Foo_wrapper(::HWND const window)
: Foo(window)
, bp::wrapper<Foo>(){
// constructor
}
virtual int Bar(int num) {
if(bp::override func_Bar = this->get_override("Bar"))
return func_Bar(num);
else{
return this->Foo::Bar(num);
}
}
int default_Bar(int num) {
return Foo::Bar(num);
}
};
BOOST_PYTHON_MODULE(MyWrapper){
{ //::Foo
typedef bp::class_<Foo_wrapper> Foo_exposer_t;
Foo_exposer_t Foo_exposer = Foo_exposer_t("Foo", bp::init< HWND__ *>((bp::arg("window"))));
bp::scope Foo_scope(Foo_exposer);
bp::implicitly_convertible< const HWND, Foo >();
{ //::Foo::Bar
typedef int (::Foo::*Bar_function_type)(int) ;
typedef int (Foo_wrapper::*default_Bar_function_type)(int) ;
Foo_exposer.def(
"Bar"
, Bar_function_type(&::Foo::Bar)
, default_Bar_function_type(&Foo_wrapper::default_Bar)
, (bp::arg("num")));
}
}
}
나는 NOT-를 얻을 수 일치 오류 :
>>> import MyWrapper
>>> import win32gui
>>> hwnd = win32gui.GetDesktopWindow()
>>> foo = MyWrapper.Foo(hwnd)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
Boost.Python.ArgumentError: Python argument types in
Foo.__init__(Foo, int)
did not match C++ signature:
__init__(struct _object *, struct HWND__ * window)
>>>
(win32gui의) 창 핸들을 Python에서 C++ 클래스로 전달하고 상호 작용할 수있게하려면이 문제를 어떻게 해결할 수 있습니까?
환경 : 비주얼 스튜디오 2008, 1.44, GCC-XML 0.9.0, 평 ++ 1.0.0, pygccxml을 밀어 1.1.0
감사를 꿀꺽 꿀꺽 인터페이스
GetDesktopWindow
의 파일 (및 기타 기능의 많은)를 볼 수 있지만 내가 어떻게 C++의 HWND (무효 *)에'GetDesktopWindow'의 INT 출력을 변환 할 수 있습니까? – Ehsan