我想使用 LoadLibrary 开发一个插件系统。
我的问题是:我希望我的函数采用 aconst char*
并LoadLibrary
采用LPCTSTR
.
我有一个好主意,(LPCSTR)path
它一直给我一个未找到模块的错误。
当前代码如下。如果我取消注释该widepath = L..
行,它工作正常。我已经阅读了使用 MFC 的解决方案,但我不想使用 MFC。
当前代码:
bool PluginLoader::Load(char *path)
{
path = "Release\\ExamplePlugin.dll";
LPCTSTR widepath = (LPCTSTR)path;
//widepath = L"Release\\ExamplePlugin.dll";
HMODULE handle = LoadLibrary(widepath);
if (handle == 0)
{
printf("Path: %s\n",widepath );
printf("Error code: %d\n", GetLastError());
return false;
}
int (*load_callback)() = (int (*)()) GetProcAddress(handle, "_plugin_start@0");
if (load_callback == 0)
{
return false;
}
return load_callback() == LOAD_SUCCESS;
}