/*************************************************************************
 * <_xZkqqHx_iDhEiDeAiDeDiDiLjGlM_xHqqkZx_>	Module.cpp
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iClBiCmMiDhGiDiJiDePiDeDiDjD_xHqqkZx_DLL_xZkqqHx_iCmMiDiCiDfHiDiFiBfLiDiLiCpAjCoIiLgAiClHiCoJiDfMiBfLiDfIiBeC_xHqqkZx_
 *			_xZkqqHx_iIoKiCmCiCmMiDhGiDiJiDePiDeDiDjD_xHqqkZx_DLL_xZkqqHx_iCmJiCmNiBeBiIoKiCmCiClOiCkPiDiCiDfHiDiFiBfLiDiLiCkKiKnMiCnMiCoKiCnMiClHiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	01.08.10 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/

/*
The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in
compliance with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/

Software distributed under the License is distributed on an "AS IS"
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
License for the specific language governing rights and limitations
under the License.

The Original Code is "SVG Export" plug-in for DynamicDraw.

The Initial Developer of the Original Code is FUKUSHIRO Masayuki.

Copyright (C) 2001,2002  FUKUSHIRO Masayuki ( yt3m-fksr@asahi-net.or.jp ), 
HIROSAWA Masashi ( hirosawa@cam.hi-ho.ne.jp ). 
All Rights Reserved.

Contributor(s):

Alternatively, the contents of this file may be used under the terms
of the GNU General Public License Version 2 (the "GPL"), in which case
the provisions of the GPL are applicable instead of those above.  If you
wish to allow use of your version of this file only under the terms of
the GPL and not to allow others to use your version of this file under
the MPL, indicate your decision by deleting the provisions above and
replace them with the notice and other provisions required by the
GPL.

Alternatively, the contents of this file may be used under the terms
of the New BSD License (the "BSDL"), in which case the provisions
of the BSDL are applicable instead of those above.  If you wish
to allow use of your version of this file only under the terms of
the BSDL and not to allow others to use your version of this file under
the MPL, indicate your decision by deleting the provisions above and
replace them with the notice and other provisions required by the BSDL.

If you do not delete the provisions above, a recipient may use
your version of this file under any of the MPL, the GPL or the BSDL.
*/

#include "stdafx.h"
#include "MpgExtern.h"	// For Global.
#include "Module.h"		// This header.


// A CLSID for the plug-in module.
// Each plug-in module must have a unique CLSID.
// You can get the unique CLSID using 'guidgen.exe'.
// Caution!
// This CLSID must be different from the value of PG_COMPONENT_CLSID.
#ifdef _DEBUG
// {8EB02CB2-970E-4157-B5F3-73551C2FFF29}
static const GUID PG_MODULE_CLSID = FMpgGuid(0x8eb02cb2, 0x970e, 0x4157, 0xb5, 0xf3, 0x73, 0x55, 0x1c, 0x2f, 0xff, 0x29);
#else
// {9856F2F6-55CC-46FB-AE1C-B1208C622F79}
static const GUID PG_MODULE_CLSID = FMpgGuid(0x9856f2f6, 0x55cc, 0x46fb, 0xae, 0x1c, 0xb1, 0x20, 0x8c, 0x62, 0x2f, 0x79);
#endif

// Specification of the applications that this plug-in is supporting.
// The value is a combination of the following.
// FD_APPMODE_DYNAMICDRAW	:Dynamic Draw.
// FD_APPMODE_CHIPEDITOR	:Chip Editor.
// FD_APPMODE_ARROWEDITOR	:Arrow Editor.
// FD_APPMODE_HISTORYVIEWER	:History Manager.
// FD_APPMODE_HISTORICDRAW	:Dynamic Draw Professional.

// If this plug-in supports Dynamic Draw only, the following value is set.
static const WORD PG_MODULE_APP = FD_APPMODE_DYNAMICDRAW|FD_APPMODE_HISTORYVIEWER|FD_APPMODE_HISTORICDRAW;

#ifdef _DEBUG
static const wchar_t* PG_MODULE_NAME = L"SVG Export (Debug)";
#else
static const wchar_t* PG_MODULE_NAME = L"SVG Export";
#endif

#ifdef PG_JP

// _xZkqqHx_iDfEiDhMiBfLiDgHiClHiCoJiMlOiMoKiOkPjFmKiOhBiCpAjHpBiLjDiBeC_xHqqkZx_
// _xZkqqHx_jDpKjGhLiMoKiCpAiDfEiDhMiBfLiDgHiClHiCoJiPoKiNiHiCmNiBeB_xHqqkZx_MAKELANGID(LANG_JAPANESE, SUBLANG_DEFAULT)_xZkqqHx_iBeC_xHqqkZx_
// _xZkqqHx_jEhKjHpBiCmMiNmFiMoDiCmN_xHqqkZx_ 0 _xZkqqHx_iCpAjDpMiCoKiCoJiClBiCmGiBeCjEhKjHpBiCkK_xHqqkZx_ 0 _xZkqqHx_iCmMiCnNiCmMiPoKiNiHiCmNiBeBjBfDiCmEiCmMiMlOiMoKiCpAiDfEiDhMiBfLiDgHiBeC_xHqqkZx_
// _xZkqqHx_iJhAiMoKiCkKiDfEiDhMiBfLiDgHiClDiCoKiCmEiCkCiCoKiCmOiBeBiCmHiCmMiMlOiMoKiCmFiCoAiJhAiMoKiCmNjCmKiCoJiCmMiCmF_xHqqkZx_ 0 _xZkqqHx_iCmMiCnNiCpAjAnNjCoIiClFiCmEiCoAjHmHiCkCiBeC_xHqqkZx_
// _xZkqqHx_iDeBiDhGiDiKiCmMiMlOiMoK_xHqqkZx_ID_xZkqqHx_iCmN_xHqqkZx_ IMpgMolipMain::GetAppLangId() _xZkqqHx_iCmFiOoGjDlOiCmFiCkLiCoJiBeC_xHqqkZx_
static LANGID PG_MODULE_SUPPORT_LANG[] = { MAKELANGID(LANG_JAPANESE, SUBLANG_DEFAULT), 0 };

// _xZkqqHx_iDiCiDfHiDiFiBfLiDiLiCmMiDfEiDhMiBfLiDgHiPoOjFpBiBeC_xHqqkZx_
static const wchar_t* PG_MODULE_SUPPORT_INFO =
	L"http://www.cam.hi-ho.ne.jp/~hirosawa/DynamicDraw/\r\n"
	L"hirosawa@cam.hi-ho.ne.jp";

#else//PG_JP

// _xZkqqHx_iDfEiDhMiBfLiDgHiClHiCoJiMlOiMoKiOkPjFmKiOhBiCpAjHpBiLjDiBeC_xHqqkZx_
// _xZkqqHx_jDpKjGhLiMoKiCpAiDfEiDhMiBfLiDgHiClHiCoJiPoKiNiHiCmNiBeB_xHqqkZx_MAKELANGID(LANG_JAPANESE, SUBLANG_DEFAULT)_xZkqqHx_iBeC_xHqqkZx_
// _xZkqqHx_jEhKjHpBiCmMiNmFiMoDiCmN_xHqqkZx_ 0 _xZkqqHx_iCpAjDpMiCoKiCoJiClBiCmGiBeCjEhKjHpBiCkK_xHqqkZx_ 0 _xZkqqHx_iCmMiCnNiCmMiPoKiNiHiCmNiBeBjBfDiCmEiCmMiMlOiMoKiCpAiDfEiDhMiBfLiDgHiBeC_xHqqkZx_
// _xZkqqHx_iJhAiMoKiCkKiDfEiDhMiBfLiDgHiClDiCoKiCmEiCkCiCoKiCmOiBeBiCmHiCmMiMlOiMoKiCmFiCoAiJhAiMoKiCmNjCmKiCoJiCmMiCmF_xHqqkZx_ 0 _xZkqqHx_iCmMiCnNiCpAjAnNjCoIiClFiCmEiCoAjHmHiCkCiBeC_xHqqkZx_
// _xZkqqHx_iDeBiDhGiDiKiCmMiMlOiMoK_xHqqkZx_ID_xZkqqHx_iCmN_xHqqkZx_ IMpgMolipMain::GetAppLangId() _xZkqqHx_iCmFiOoGjDlOiCmFiCkLiCoJiBeC_xHqqkZx_
static LANGID PG_MODULE_SUPPORT_LANG[] = { 0 };

// Support.
static const wchar_t* PG_MODULE_SUPPORT_INFO =
	L"http://www.dynamicdraw.com/\r\n"
	L"yt3m-fksr@asahi-net.or.jp";

#endif//PG_JP

#if defined(_AFXEXT)
// When MFC Extension DLL is used.

static AFX_EXTENSION_MODULE MpaModuleDLL = { NULL, NULL };

/*************************************************************************
 * <Function>	DllMain
 *
 * <Summary>	Main function of the DLL.
 *
 * <Parameters>	See Windows API specification.
 *
 * <Details>	When MFC Extension DLL is used.
 *
 * <History>	01.08.30 Fukushiro M. Creation
 *************************************************************************/
extern "C" int APIENTRY DllMain (HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
	// Remove this if you use lpReserved
	UNREFERENCED_PARAMETER(lpReserved);

	// Registration of the module handle.
	FMpgGetModule()->Main(hInstance, dwReason);

	if (dwReason == DLL_PROCESS_ATTACH)
	{
		TRACE("PlugIn Initializing!\n");
		
		// Extension DLL one-time initialization.
		if (!AfxInitExtensionModule(MpaModuleDLL, hInstance))
			return 0;

		// Insert this DLL into the resource chain
		// NOTE: If this Extension DLL is being implicitly linked to by
		//  an MFC Regular DLL (such as an ActiveX Control)
		//  instead of an MFC application, then you will want to
		//  remove this line from DllMain and put it in a separate
		//  function exported from this Extension DLL.  The Regular DLL
		//  that uses this Extension DLL should then explicitly call that
		//  function to initialize this Extension DLL.  Otherwise,
		//  the CDynLinkLibrary object will not be attached to the
		//  Regular DLL's resource chain, and serious problems will
		//  result.

		new CDynLinkLibrary(MpaModuleDLL);
	}
	else if (dwReason == DLL_PROCESS_DETACH)
	{
		TRACE("PlugIn Terminating!\n");
		// Terminate the library before destructors are called
		AfxTermExtensionModule(MpaModuleDLL);
	}
	return 1;   // ok
} // DllMain.

#elif !defined(_AFX)
// When MFC is not used.

/*************************************************************************
 * <Function>	DllMain
 *
 * <Summary>	Main function of the DLL.
 *
 * <Parameters>	See Windows API specification.
 *
 * <Details>	When MFC is not used.
 *
 * <History>	01.08.02 Fukushiro M. Creation
 *************************************************************************/
extern "C" BOOL APIENTRY DllMain (	HANDLE hModule,
									DWORD ul_reason_for_call,
									LPVOID lpReserved)
{
	// Registration of the module handle.
	return FMpgGetModule()->Main(hModule, ul_reason_for_call);
} // DllMain.
#endif //!defined(_AFX)

// When Standard MFC DLL or static MFC library is used,
// you don't have to define DllMain.

IMpgMolipBase* FFGetMolipBaseI ()
{
	return FMpgGetModule()->GetMolipBaseI();
}

void FFThrowMiscException (const _TCHAR* tcpFile, long lLine)
{
	CStringW wstr;
	wstr.Format(L"Error %s:%d", (const wchar_t*)TStrToWStr(tcpFile), lLine);
	FFGetMolipBaseI()->GetUtilErrI()->ThrowMiscException((const wchar_t*)wstr);
} // FFThrowMiscException.

CString FFLoadString (int id)
{
	CString str;
	str.LoadString(id);
	return str;
} // FFLoadString.


// Definition for MolipSDK.
// The following must be described at the end of the 'MpaModule.cpp' only.
#include "MpgMolipSdk.cpp"
