i have dll, use opengl draw on window. dll window hwmd.
dll:
extern "c" __declspec(dllexport) int init(hwnd hwnd); extern "c" __declspec(dllexport) void resize(hwnd hwnd, int w, int h); extern "c" __declspec(dllexport) void paint(hwnd hwnd);
the c++ qt application work properly.
#include "windows.h" #include <qapplication> #include <qwidget> #include <qglwidget> #include <qmessagebox> #include <qsplitter> #include <qlibrary> typedef void (*initprototype)(hwnd); typedef void (*paintprototype)(hwnd); typedef void (*resizeprototype)(hwnd, int, int); initprototype c_init; paintprototype c_paint; resizeprototype c_resize; bool load_opengl_library(){ qlibrary lib("engine3d"); lib.load(); c_init = (initprototype)lib.resolve("init"); c_paint = (paintprototype)lib.resolve("paint"); c_resize = (resizeprototype)lib.resolve("resize"); return true; } class myglwidget: public qglwidget { public: myglwidget(qwidget *parent = 0): qglwidget(parent){} void showevent(qshowevent* event){ c_init((hwnd)(this->winid())); } void paintevent(qpaintevent* event){ c_paint((hwnd)this->winid()); } void resizeevent(qresizeevent* event){ c_resize((hwnd)this->winid(), this->width(), this->height()); } }; int main(int argc, char *argv[]) { qapplication a(argc, argv); load_opengl_library(); myglwidget w; w.show(); return a.exec(); }
but how same in python? program crushes on sending widget.winid().
# coding=utf-8 import ctypes pyqt5 import qtwidgets, qtopengl app = qtwidgets.qapplication([]) e3d = ctypes.cdll(r"engine3d.dll") init = lambda hwnd: e3d.init(hwnd) paint = lambda hwnd: e3d.paint(hwnd) resize = lambda hwnd, w, h: e3d.paint(hwnd, w, h) class myglwidget(qtopengl.qglwidget): def __init__(self): super().__init__() def showevent(self, ev): init(self.winid()) def paintevent(self, ev): paint(self.winid()) def resizeevent(self, ev): resize(self.winid(), self.width(), self.height()) w = myglwidget() w.show() app.exec_()
print(self.winid())
it'd easier check having dll, i'll speak out blue. in c++ code got initialization code:
bool load_opengl_library(){ qlibrary lib("engine3d"); lib.load(); c_init = (initprototype)lib.resolve("init"); c_paint = (paintprototype)lib.resolve("paint"); c_resize = (resizeprototype)lib.resolve("resize"); return true; } ... int main(int argc, char *argv[]) { qapplication a(argc, argv); load_opengl_library(); myglwidget w; w.show(); return a.exec(); }
where create engine instance lib
and using load
method in python you're not doing of that:
w = myglwidget() w.show() app.exec_()
but before creating myglwidget
you're not initializing engine c++ counterpart, question is, why not?
Comments
Post a Comment