/*static*/void *ui_assoc_object::GetGoodCppObject(PyObject *&self, ui_type *ui_type_check) { // first, call is_uiobject, which may modify the "self" pointer. // this is to support a Python class instance being passed in, // and auto-convert it to the classes AttachedObject. if (ui_type_check && !is_uiobject(self, ui_type_check)) { TRACE("GetGoodCppObject fails RTTI\n"); return PyErr_Format(PyExc_TypeError, "object is not a %s", ui_type_check->tp_name); } ui_assoc_object *s = (ui_assoc_object *)self; if (s->assoc==NULL) RETURN_ERR("The object has been destroyed."); #ifdef _DEBUG // These sorts of errors are C developers problems, and // should not be possible to be triggered by Python. // Therefore we restrict the type checking code to debug if (!s->CheckCppObject(ui_type_check)) return NULL; #endif // _DEBUG return s->assoc; }
// @pymethod <o PyCMenu>|win32ui|LoadMenu|Creates and loads a menu resource from a DLL. PyObject *PyCMenu::load_menu(PyObject *self, PyObject *args) { int id; PyObject *dllObj = NULL; HMODULE hMod = NULL; // @pyparm int|id||The Id of the menu to load. // @pyparm <o PyDLL>|dll|None|The DLL to load from. if (!PyArg_ParseTuple(args, "i|O", &id, &dllObj)) return NULL; if (dllObj && dllObj!=Py_None) { // passed a DLL object. if (!is_uiobject(dllObj, &dll_object::type)) RETURN_TYPE_ERR("passed object must be a PyDLL object"); hMod = ((dll_object *)dllObj)->GetDll(); } else hMod = AfxFindResourceHandle( MAKEINTRESOURCE(id), RT_MENU ); HMENU hMenu = ::LoadMenu(hMod, MAKEINTRESOURCE(id)); if (!hMenu) RETURN_API_ERR("LoadMenu"); return ui_assoc_object::make(PyCMenu::type, hMenu); }