// dui-demo.cpp : main source file
//

#include "stdafx.h"
#include "MainDlg.h"
#include "LoginDlg.h"
#include "SouiInit.h"
#include "CApp.h"
#include "CTool.h"
 
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int /*nCmdShow*/)
{
	HRESULT hRes = OleInitialize(NULL);
	SASSERT(SUCCEEDED(hRes));

	int nRet = 0;

	new CApp();


	CApp::getSingletonPtr()->Init();

	CSouiLoader Loader(hInstance);
	InitSystemRes(Loader.GetApp(), Loader.GetComMgr());
	InitUserRes(Loader.GetApp(), Loader.GetComMgr());
	new CTool();
	new SNotifyCenter();

	TCHAR szCurrentDir[MAX_PATH] = { 0 };
	GetModuleFileName(NULL, szCurrentDir, sizeof(szCurrentDir));

	LPTSTR lpInsertPos = _tcsrchr(szCurrentDir, _T('\\'));
 
	_tcscpy(lpInsertPos + 1, _T("\0"));
 
	SetCurrentDirectory(szCurrentDir);

	nRet = Run<CLoginDlg>(Loader.GetApp());

	if (CApp::getSingletonPtr()->GetOut() == 1)
	{
		nRet = Run<CMainDlg>(Loader.GetApp());
	}


	delete CApp::getSingletonPtr();
	delete CTool::getSingletonPtr();
	delete SNotifyCenter::getSingletonPtr();
	
	OleUninitialize();
	return nRet;
}
