Index: src/OFPlugin.h ================================================================== --- src/OFPlugin.h +++ src/OFPlugin.h @@ -58,27 +58,27 @@ + (OFString *)pathForName: (OFString *)name; /** * @brief Creates a new OFPlugin by loading the plugin with the specified path. * - * @param path The path to the plugin file. The suffix is appended - * automatically. + * @param path The path to the plugin file. If `nil` is specified, the main + * binary is returned as a plugin. * @return An new, autoreleased OFPlugin * @throw OFLoadPluginFailedException The plugin could not be loaded */ -+ (instancetype)pluginWithPath: (OFString *)path; ++ (instancetype)pluginWithPath: (nullable OFString *)path; /** * @brief Initializes an already allocated OFPlugin by loading the plugin with * the specified path. * - * @param path The path to the plugin file. The suffix is appended - * automatically. + * @param path The path to the plugin file. If `nil` is specified, the main + * binary is returned as a plugin. * @return An initialized OFPlugin * @throw OFLoadPluginFailedException The plugin could not be loaded */ -- (instancetype)initWithPath: (OFString *)path; +- (instancetype)initWithPath: (nullable OFString *)path; /** * @brief Returns the address for the specified symbol, or `nil` if not found. * * @param symbol The symbol to return the address for Index: src/OFPlugin.m ================================================================== --- src/OFPlugin.m +++ src/OFPlugin.m @@ -72,15 +72,18 @@ #ifndef OF_WINDOWS _handle = dlopen( [path cStringWithEncoding: [OFLocale encoding]], RTLD_LAZY); #else - if ([OFSystemInfo isWindowsNT]) - _handle = LoadLibraryW(path.UTF16String); - else - _handle = LoadLibraryA( - [path cStringWithEncoding: [OFLocale encoding]]); + if (path != nil) { + if ([OFSystemInfo isWindowsNT]) + _handle = LoadLibraryW(path.UTF16String); + else + _handle = LoadLibraryA([path + cStringWithEncoding: [OFLocale encoding]]); + } else + _handle = GetModuleHandle(NULL); #endif if (_handle == NULL) { #ifndef OF_WINDOWS OFString *error = [OFString