MINGW 编译错误提示从FARPROC到void的转换无效,但 MSVC 编译好

void* PluginManager::LoadLIB(const QString i_pluginname)

{

    if (i_pluginname.size() <= 0)

    {

        return NULL;

    }

    QString lib_name = M_PLUGIN_PATH+i_pluginname;

    void* libhandle = NULL;

#ifdef WIN32

    lib_name += QString(".dll");

    libhandle = LoadLibrary(lib_name.toStdWString().c_str());

#else

    lib_name += QString(".so");

    libhandle = dlopen(lib_name.toStdString().c_str(), RTLD_LAZY);

#endif

    return libhandle;

}

 

void* PluginManager::GetSymbolAddress(const void *i_libhandle,const QString i_symbolname) const

{

    void* pSymbol = NULL;

#ifdef WIN32

    if (i_libhandle != NULL)

    {

        pSymbol = GetProcAddress((HMODULE)i_libhandle,  i_symbolname.toStdString().c_str());[W用1]

    }

#else

    if (i_libhandle != NULL)

        pSymbol = dlsym(i_libhandle, i_symbolname.toStdString().c_str());

    }

#endif

    return pSymbol;

}


 [W用1]编译到下划线标注的那句是的时候,就报了如下错误

error: invalid conversion from 'FARPROC {aka int (__attribute__((__stdcall__)) *)()}' to 'void*' [-fpermissive]

         pSymbol = GetProcAddress((HMODULE)i_libhandle, i_symbolname.toStdString().c_str());

原因分析:mingw编译不允许进行隐式转换

解决方法:

pSymbol = (void*)GetProcAddress((HMODULE)i_libhandle, i_symbolname.toStdString().c_str());

你可能感兴趣的:(C++编程)