예제 #1
0
bool CPlugin::Load(const char * FileName)
{
    // Already loaded, so unload first.
    if (m_LibHandle != NULL)
    {
        UnloadPlugin();
    }

    // Try to load the plugin DLL
    //Try to load the DLL library
    m_LibHandle = pjutil::DynLibOpen(FileName, bHaveDebugger());
    if (m_LibHandle == NULL)
    {
        return false;
    }

    // Get DLL information
    void(CALL *GetDllInfo) (PLUGIN_INFO * PluginInfo);
    LoadFunction(GetDllInfo);
    if (GetDllInfo == NULL) { return false; }

    GetDllInfo(&m_PluginInfo);
    if (!ValidPluginVersion(m_PluginInfo)) { return false; }
    if (m_PluginInfo.Type != type()) { return false; }

    LoadFunction(CloseDLL);
    LoadFunction(RomOpen);
    LoadFunction(RomClosed);
    _LoadFunction("PluginLoaded", PluginOpened);
    LoadFunction(DllConfig);
    LoadFunction(DllAbout);

    LoadFunction(SetSettingInfo3);
    if (SetSettingInfo3)
    {
        PLUGIN_SETTINGS3 info;
        info.FlushSettings = (void(*)(void * handle))CSettings::FlushSettings;
        SetSettingInfo3(&info);
    }

    LoadFunction(SetSettingInfo2);
    if (SetSettingInfo2)
    {
        PLUGIN_SETTINGS2 info;
        info.FindSystemSettingId = (uint32_t(*)(void * handle, const char *))CSettings::FindSetting;
        SetSettingInfo2(&info);
    }

    LoadFunction(SetSettingInfo);
    if (SetSettingInfo)
    {
        PLUGIN_SETTINGS info;
        info.dwSize = sizeof(PLUGIN_SETTINGS);
        info.DefaultStartRange = GetDefaultSettingStartRange();
        info.SettingStartRange = GetSettingStartRange();
        info.MaximumSettings = MaxPluginSetting;
        info.NoDefault = Default_None;
        info.DefaultLocation = g_Settings->LoadDword(Setting_UseFromRegistry) ? SettingType_Registry : SettingType_CfgFile;
        info.handle = g_Settings;
        info.RegisterSetting = (void(*)(void *, int, int, SettingDataType, SettingType, const char *, const char *, uint32_t))&CSettings::RegisterSetting;
        info.GetSetting = (uint32_t(*)(void *, int))&CSettings::GetSetting;
        info.GetSettingSz = (const char * (*)(void *, int, char *, int))&CSettings::GetSettingSz;
        info.SetSetting = (void(*)(void *, int, uint32_t))&CSettings::SetSetting;
        info.SetSettingSz = (void(*)(void *, int, const char *))&CSettings::SetSettingSz;
        info.UseUnregisteredSetting = NULL;

        SetSettingInfo(&info);
    }

    if (RomClosed == NULL)
    {
        return false;
    }

    if (!LoadFunctions())
    {
        return false;
    }
    WriteTrace(PluginTraceType(), TraceDebug, "Functions loaded");

    if (PluginOpened)
    {
        WriteTrace(PluginTraceType(), TraceDebug, "Before Plugin Opened");
        PluginOpened();
        WriteTrace(PluginTraceType(), TraceDebug, "After Plugin Opened");
    }
    return true;
}
예제 #2
0
bool CPlugin::Load(const char * FileName)
{
    // Already loaded, so unload first.
    if (m_hDll != NULL)
    {
        UnloadPlugin();
    }

    // Try to load the plugin DLL
    //Try to load the DLL library
    if (bHaveDebugger())
    {
        m_hDll = LoadLibrary(FileName);
    }
    else
    {
        UINT LastErrorMode = SetErrorMode(SEM_FAILCRITICALERRORS);
        m_hDll = LoadLibrary(FileName);
        SetErrorMode(LastErrorMode);
    }

    if (m_hDll == NULL)
    {
        return false;
    }

    // Get DLL information
    void(__cdecl *GetDllInfo) (PLUGIN_INFO * PluginInfo);
    LoadFunction(GetDllInfo);
    if (GetDllInfo == NULL) { return false; }

    GetDllInfo(&m_PluginInfo);
    if (!ValidPluginVersion(m_PluginInfo)) { return false; }
    if (m_PluginInfo.Type != type()) { return false; }

    CloseDLL = (void(__cdecl *)(void)) GetProcAddress((HMODULE)m_hDll, "CloseDLL");
    RomOpen = (void(__cdecl *)(void)) GetProcAddress((HMODULE)m_hDll, "RomOpen");
    RomClosed = (void(__cdecl *)(void)) GetProcAddress((HMODULE)m_hDll, "RomClosed");
    PluginOpened = (void(__cdecl *)(void)) GetProcAddress((HMODULE)m_hDll, "PluginLoaded");
    DllConfig = (void(__cdecl *)(void *)) GetProcAddress((HMODULE)m_hDll, "DllConfig");
    DllAbout = (void(__cdecl *)(void *)) GetProcAddress((HMODULE)m_hDll, "DllAbout");

    SetSettingInfo3 = (void(__cdecl *)(PLUGIN_SETTINGS3 *))GetProcAddress((HMODULE)m_hDll, "SetSettingInfo3");
    if (SetSettingInfo3)
    {
        PLUGIN_SETTINGS3 info;
        info.FlushSettings = (void(*)(void * handle))CSettings::FlushSettings;
        SetSettingInfo3(&info);
    }

    SetSettingInfo2 = (void(__cdecl *)(PLUGIN_SETTINGS2 *))GetProcAddress((HMODULE)m_hDll, "SetSettingInfo2");
    if (SetSettingInfo2)
    {
        PLUGIN_SETTINGS2 info;
        info.FindSystemSettingId = (uint32_t(*)(void * handle, const char *))CSettings::FindSetting;
        SetSettingInfo2(&info);
    }

    SetSettingInfo = (void(__cdecl *)(PLUGIN_SETTINGS *))GetProcAddress((HMODULE)m_hDll, "SetSettingInfo");
    if (SetSettingInfo)
    {
        PLUGIN_SETTINGS info;
        info.dwSize = sizeof(PLUGIN_SETTINGS);
        info.DefaultStartRange = GetDefaultSettingStartRange();
        info.SettingStartRange = GetSettingStartRange();
        info.MaximumSettings = MaxPluginSetting;
        info.NoDefault = Default_None;
        info.DefaultLocation = g_Settings->LoadDword(Setting_UseFromRegistry) ? SettingType_Registry : SettingType_CfgFile;
        info.handle = g_Settings;
        info.RegisterSetting = (void(*)(void *, int, int, SettingDataType, SettingType, const char *, const char *, uint32_t))&CSettings::RegisterSetting;
        info.GetSetting = (uint32_t(*)(void *, int))&CSettings::GetSetting;
        info.GetSettingSz = (const char * (*)(void *, int, char *, int))&CSettings::GetSettingSz;
        info.SetSetting = (void(*)(void *, int, uint32_t))&CSettings::SetSetting;
        info.SetSettingSz = (void(*)(void *, int, const char *))&CSettings::SetSettingSz;
        info.UseUnregisteredSetting = NULL;

        SetSettingInfo(&info);
    }

    if (RomClosed == NULL)
        return false;

    if (!LoadFunctions())
    {
        return false;
    }
    WriteTrace(PluginTraceType(), TraceDebug, "Functions loaded");

    if (PluginOpened)
    {
        WriteTrace(PluginTraceType(), TraceDebug, "Before Plugin Opened");
        PluginOpened();
        WriteTrace(PluginTraceType(), TraceDebug, "After Plugin Opened");
    }
    return true;
}