// Wild Magic Source Code
// David Eberly
// http://www.geometrictools.com
// Copyright (c) 1998-2007
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2.1 of the License, or (at
// your option) any later version.  The license is available for reading at
// either of the locations:
//     http://www.gnu.org/copyleft/lgpl.html
//     http://www.geometrictools.com/License/WildMagicLicense.pdf
//
// Version: 4.0.1 (2007/01/15)

#include "Max9ToWm4.h"
#include "WClassDesc.h"
#include "max.h"
#include "resource.h"
#include "Wm4Main.h"
#include <cassert>

Max9ToWm4 Max9ToWm4::ThePlugin;

//----------------------------------------------------------------------------
Max9ToWm4::Max9ToWm4 ()
{
    m_hInstance = 0;
    m_bControlsInitialized = false;
    memset(m_acResourceString,0,MAX_RESOURCE_STRING*sizeof(TCHAR));
}
//----------------------------------------------------------------------------
Max9ToWm4::~Max9ToWm4 ()
{
    Wm4::Main::Terminate();
}
//----------------------------------------------------------------------------
void Max9ToWm4::SetInstance (HINSTANCE hInstance)
{
    m_hInstance = hInstance;
}
//----------------------------------------------------------------------------
HINSTANCE Max9ToWm4::GetInstance () const
{
    return m_hInstance;
}
//----------------------------------------------------------------------------
void Max9ToWm4::SetControlsInitialized ()
{
    m_bControlsInitialized = true;
}
//----------------------------------------------------------------------------
bool Max9ToWm4::GetControlsInitialized () const
{
    return m_bControlsInitialized;
}
//----------------------------------------------------------------------------
const TCHAR* Max9ToWm4::GetResourceString (unsigned int uiID) const
{
    assert(m_hInstance != 0);
    if (!m_hInstance)
    {
        return 0;
    }

    int iQuantity = LoadString(m_hInstance,uiID,(LPSTR)m_acResourceString,
        MAX_RESOURCE_STRING);
    return (iQuantity > 0 ? m_acResourceString : 0);
}
//----------------------------------------------------------------------------
BOOL WINAPI DllMain (HINSTANCE hInstance, ULONG, LPVOID)
{
    // This function is called by Windows when the DLL is loaded.
    Max9ToWm4::ThePlugin.SetInstance(hInstance);
    if (!Max9ToWm4::ThePlugin.GetControlsInitialized()) 
    {
        Max9ToWm4::ThePlugin.SetControlsInitialized();

        // initialize MAX's custom controls
        InitCustomControls(hInstance);

        // initialize Windows' controls
        InitCommonControls();

        Wm4::Main::Initialize();
    }
    return TRUE;
}
//----------------------------------------------------------------------------
__declspec(dllexport) const TCHAR* LibDescription ()
{
    // This function returns a string that describes the DLL and where the
    // users can purchase the DLL if they do not have it.
    return Max9ToWm4::ThePlugin.GetResourceString(IDS_LIBDESCRIPTION);
}
//----------------------------------------------------------------------------
__declspec(dllexport) int LibNumberClasses ()
{
    // This function returns the number of plugin classes this DLL.
    return 1;
}
//----------------------------------------------------------------------------
__declspec(dllexport) ClassDesc* LibClassDesc (int i)
{
    // This function returns descriptions of the plugins.  Only one plugin
    // exists in this DLL.
    return &WClassDesc::TheDescription;
}
//----------------------------------------------------------------------------
__declspec(dllexport) ULONG LibVersion ()
{
    // This function returns a pre-defined constant indicating the version of
    // the system under which it was compiled.  It is used to allow the system
    // to catch obsolete DLLs.
    return VERSION_3DSMAX;
}
//----------------------------------------------------------------------------
