const std::wstring& BorderlessWindow::window_class() { static const std::wstring window_class_name = []{ WNDCLASSEX wcx{}; wcx.cbSize = sizeof(wcx); wcx.style = CS_HREDRAW | CS_VREDRAW; wcx.hInstance = module_handle(); wcx.lpfnWndProc = &BorderlessWindow::WndProc; wcx.lpszClassName = L"BorderlessWindowClass"; wcx.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_WINDOW + 1); wcx.hCursor = LoadCursor(module_handle(), IDC_ARROW); const HRESULT result = RegisterClassEx(&wcx); if (FAILED(result)) throw std::runtime_error("failed to register window class"); return wcx.lpszClassName; }(); return window_class_name; }
int module_unload( const char *file_name ) { module_loaded_t *module; module = module_handle( file_name ); if ( module ) { module_int_unload( module ); return 0; } return -1; /* not found */ }
inline HBITMAP test_bitmap() { HBITMAP bitmap = (HBITMAP)::LoadImageW( module_handle("shell32.dll"), L"#145", IMAGE_BITMAP, LR_DEFAULTSIZE, LR_DEFAULTSIZE, LR_SHARED); if (bitmap == NULL) BOOST_THROW_EXCEPTION( boost::enable_error_info(washer::last_error()) << boost::errinfo_api_function("LoadImage")); return bitmap; }
int module_load(const char* file_name, int argc, char *argv[]) { module_loaded_t *module; const char *error; int rc; MODULE_INIT_FN initialize; #ifdef HAVE_EBCDIC #define file ebuf #else #define file file_name #endif module = module_handle( file_name ); if ( module ) { Debug( LDAP_DEBUG_ANY, "module_load: (%s) already loaded\n", file_name, 0, 0 ); return -1; } /* If loading a backend, see if we already have it */ if ( !strncasecmp( file_name, "back_", 5 )) { char *name = (char *)file_name + 5; char *dot = strchr( name, '.'); if (dot) *dot = '\0'; rc = backend_info( name ) != NULL; if (dot) *dot = '.'; if ( rc ) { Debug( LDAP_DEBUG_CONFIG, "module_load: (%s) already present (static)\n", file_name, 0, 0 ); return 0; } } else { /* check for overlays too */ char *dot = strchr( file_name, '.' ); if ( dot ) *dot = '\0'; rc = overlay_find( file_name ) != NULL; if ( dot ) *dot = '.'; if ( rc ) { Debug( LDAP_DEBUG_CONFIG, "module_load: (%s) already present (static)\n", file_name, 0, 0 ); return 0; } } module = (module_loaded_t *)ch_calloc(1, sizeof(module_loaded_t) + strlen(file_name)); if (module == NULL) { Debug(LDAP_DEBUG_ANY, "module_load failed: (%s) out of memory\n", file_name, 0, 0); return -1; } strcpy( module->name, file_name ); #ifdef HAVE_EBCDIC strcpy( file, file_name ); __atoe( file ); #endif /* * The result of lt_dlerror(), when called, must be cached prior * to calling Debug. This is because Debug is a macro that expands * into multiple function calls. */ if ((module->lib = lt_dlopenext(file)) == NULL) { error = lt_dlerror(); #ifdef HAVE_EBCDIC strcpy( ebuf, error ); __etoa( ebuf ); error = ebuf; #endif Debug(LDAP_DEBUG_ANY, "lt_dlopenext failed: (%s) %s\n", file_name, error, 0); ch_free(module); return -1; } Debug(LDAP_DEBUG_CONFIG, "loaded module %s\n", file_name, 0, 0); #ifdef HAVE_EBCDIC #pragma convlit(suspend) #endif if ((initialize = lt_dlsym(module->lib, "init_module")) == NULL) { #ifdef HAVE_EBCDIC #pragma convlit(resume) #endif Debug(LDAP_DEBUG_CONFIG, "module %s: no init_module() function found\n", file_name, 0, 0); lt_dlclose(module->lib); ch_free(module); return -1; } /* The imported init_module() routine passes back the type of * module (i.e., which part of slapd it should be hooked into) * or -1 for error. If it passes back 0, then you get the * old behavior (i.e., the library is loaded and not hooked * into anything). * * It might be better if the conf file could specify the type * of module. That way, a single module could support multiple * type of hooks. This could be done by using something like: * * moduleload extension /usr/local/openldap/whatever.so * * then we'd search through module_regtable for a matching * module type, and hook in there. */ rc = initialize(argc, argv); if (rc == -1) { Debug(LDAP_DEBUG_CONFIG, "module %s: init_module() failed\n", file_name, 0, 0); lt_dlclose(module->lib); ch_free(module); return rc; } if (rc >= (int)(sizeof(module_regtable) / sizeof(struct module_regtable_t)) || module_regtable[rc].proc == NULL) { Debug(LDAP_DEBUG_CONFIG, "module %s: unknown registration type (%d)\n", file_name, rc, 0); module_int_unload(module); return -1; } rc = (module_regtable[rc].proc)(module, file_name); if (rc != 0) { Debug(LDAP_DEBUG_CONFIG, "module %s: %s module could not be registered\n", file_name, module_regtable[rc].type, 0); module_int_unload(module); return rc; } module->next = module_list; module_list = module; Debug(LDAP_DEBUG_CONFIG, "module %s: %s module registered\n", file_name, module_regtable[rc].type, 0); return 0; }
BorderlessWindow::BorderlessWindow() : hwnd(CreateWindow(window_class().c_str(), L"Borderless Window", static_cast<DWORD>(Style::aero_borderless), 0, 0, 1280, 720, nullptr, nullptr, module_handle(), nullptr)) { if (!hwnd) throw std::runtime_error("failed to create window"); static_assert(sizeof(LONG_PTR) == sizeof(this), "sanity check on LONG_PTR size failed!"); // store pointer to this class instance in window's user data, so we may retrieve it in the Window Procedure SetWindowLongPtr(hwnd.get(), GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this)); set_borderless(borderless); set_borderless_shadow(borderless_shadow); show(); }