Beispiel #1
0
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int nCmdShow)
{  
    HRESULT hRes = ::CoInitialize(NULL);
    // If you are running on NT 4.0 or higher you can use the following call instead to 
    // make the EXE free threaded. This means that calls come in on a random RPC thread.
    //	HRESULT hRes = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
    ATLASSERT(SUCCEEDED(hRes));

    // this resolves ATL window thunking problem when Microsoft Layer for Unicode (MSLU) is used
    ::DefWindowProc(NULL, 0, 0, 0L);

    AtlInitCommonControls(ICC_COOL_CLASSES | ICC_BAR_CLASSES);	// add flags to support other controls

    hRes = _Module.Init(NULL, hInstance);
    ATLASSERT(SUCCEEDED(hRes));

    int nRet = Run(lpstrCmdLine, nCmdShow);

    _Module.Term();
    ::CoUninitialize();

    return nRet;
}
Beispiel #2
0
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR /*lpstrCmdLine*/, int /*nCmdShow*/)
{
	HRESULT hRes = ::CoInitialize(NULL);
// If you are running on NT 4.0 or higher you can use the following call instead to 
// make the EXE free threaded. This means that calls come in on a random RPC thread.
//	HRESULT hRes = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
	ATLASSERT(SUCCEEDED(hRes));


	::PRDataSource *pprdsNew = new ::PRSpoolerDataFile();	
	tstring file = _T("D:\\SUNNET\\SkyBoard\\Component\\PosterPrinter\\PrintResizer\\prpreview\\objfre_w2k_x86\\i386\\483.tmp");
	if (pprdsNew->Open( file )) {
		//this->OnNewDataSource(pprdsNew);
	} else {
		MessageBox(0, L"Fail", 0, 0);		
	}	

	// this resolves ATL window thunking problem when Microsoft Layer for Unicode (MSLU) is used
	::DefWindowProc(NULL, 0, 0, 0L);

	AtlInitCommonControls(ICC_BAR_CLASSES);	// add flags to support other controls

	hRes = _Module.Init(NULL, hInstance);
	ATLASSERT(SUCCEEDED(hRes));

	int nRet = 0;
	// BLOCK: Run application
	{
		CMainDlg dlgMain;
		nRet = dlgMain.DoModal();
	}

	_Module.Term();
	::CoUninitialize();

	return nRet;
}
Beispiel #3
0
int __stdcall wWinMain(HINSTANCE instance,
                       HINSTANCE,
                       LPWSTR /*cmdLine*/,
                       int /*cmdShow*/)
{
	{
		BOOL isx64;
		IsWow64Process(GetCurrentProcess(), &isx64);
		onx64 = isx64 == TRUE;
	}

	try
	{
		transaction = CreateTransaction(NULL, NULL, NULL, NULL, NULL, NULL, L"Taglib Handler Setup");
		if (transaction == INVALID_HANDLE_VALUE)
			throw win32_error(L"Couldn't create a transaction");
		makeGuard(CloseHandle, transaction);

		HRESULT hr;
		if (FAILED(hr = _Module.Init(0, instance)))
			throw std::exception("Initialisation failed", hr);
		makeGuard(&CAppModule::Term, _Module);

		InstallDialog dialog;
		return dialog.DoModal();
	}
	catch (std::exception& e)
	{
		MessageBoxA(msgbox, e.what(), "Fatal error, exiting", MB_ICONERROR | MB_OK);
		return -1;
	}
	catch (win32_error& e)
	{
		MessageBox(msgbox, e.what().c_str(), L"Unexpected Win32 error, exiting", MB_ICONERROR | MB_OK);
		return -2;
	}
}
Beispiel #4
0
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int nCmdShow)
{
#ifdef _DEBUG	// ATLTRACEで日本語を使うために必要
	_tsetlocale(LC_ALL, _T("japanese"));
#endif

	HRESULT hRes = ::CoInitialize(NULL);
// If you are running on NT 4.0 or higher you can use the following call instead to 
// make the EXE free threaded. This means that calls come in on a random RPC thread.
//	HRESULT hRes = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
	ATLASSERT(SUCCEEDED(hRes));

	// this resolves ATL window thunking problem when Microsoft Layer for Unicode (MSLU) is used
	::DefWindowProc(NULL, 0, 0, 0L);

	AtlInitCommonControls(ICC_BAR_CLASSES);	// add flags to support other controls

	hRes = _Module.Init(NULL, hInstance);
	ATLASSERT(SUCCEEDED(hRes));

	FILE* fp_out = freopen("result.txt", "w", stdout);

	g_atomicMegaThreadActive.store(true);
	std::thread threadMegaLoop(CMegaAppImpl::StartMegaLoop);

	int nRet = Run(lpstrCmdLine, nCmdShow);

	g_atomicMegaThreadActive.store(false);
	threadMegaLoop.join();

	fclose(fp_out);

	_Module.Term();
	::CoUninitialize();

	return nRet;
}
Beispiel #5
0
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR /*lpstrCmdLine*/, int /*nCmdShow*/)
{
	HRESULT hRes = ::OleInitialize(NULL);
	ATLASSERT(SUCCEEDED(hRes));

	// this resolves ATL window thunking problem when Microsoft Layer for Unicode (MSLU) is used
	::DefWindowProc(NULL, 0, 0, 0L);

	AtlInitCommonControls(
		ICC_WIN95_CLASSES |
		ICC_DATE_CLASSES |
		ICC_USEREX_CLASSES |
		ICC_COOL_CLASSES |
		ICC_PAGESCROLLER_CLASS |
		ICC_NATIVEFNTCTL_CLASS);

	// We use a RichEdit control
	HINSTANCE hInstRich = ::LoadLibrary(CRichEditCtrl::GetLibraryName());
	ATLASSERT(hInstRich != NULL);

	hRes = _Module.Init(NULL, hInstance);
	ATLASSERT(SUCCEEDED(hRes));

	int nRet = 0;
	// BLOCK: Run application
	{
		CTestWizard wizard;
		wizard.ExecuteWizard();
	}

	::FreeLibrary(hInstRich);

	_Module.Term();
	::OleUninitialize();

	return nRet;
}
Beispiel #6
0
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int nCmdShow) {
	HRESULT hRes = ::CoInitialize(NULL);
  ATLASSERT(SUCCEEDED(hRes));
  
  //  this object must in main/ WinMain
  crash_report::CrAutoInstallHelper helper;
  if (!InstallCrashReport(helper)) {
    return -1;
  }

	/* Create another thread */
  g_CrashThreadInfo.m_bStop = false;
  g_CrashThreadInfo.m_hWakeUpEvent = CreateEvent(NULL, FALSE, FALSE, _T("WakeUpEvent"));
  ATLASSERT(g_CrashThreadInfo.m_hWakeUpEvent!=NULL);

  DWORD dwThreadId = 0;
  g_hWorkingThread = CreateThread(NULL, 0, CrashThread, (LPVOID)&g_CrashThreadInfo, 0, &dwThreadId);
  ATLASSERT(g_hWorkingThread!=NULL);

  // this resolves ATL window thunking problem when Microsoft Layer for Unicode (MSLU) is used
  ::DefWindowProc(NULL, 0, 0, 0L);
  AtlInitCommonControls(ICC_BAR_CLASSES);	// add flags to support other controls
  hRes = _Module.Init(NULL, hInstance);
  ATLASSERT(SUCCEEDED(hRes));

  int nRet = Run(lpstrCmdLine, nCmdShow);
  _Module.Term();

  // Close another thread
  g_CrashThreadInfo.m_bStop = true;
  SetEvent(g_CrashThreadInfo.m_hWakeUpEvent);
  // Wait until thread terminates
  WaitForSingleObject(g_hWorkingThread, INFINITE);
  ::CoUninitialize();

  return nRet;
}
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int nCmdShow)
{
	HRESULT hRes = ::CoInitialize(NULL);
// If you are running on NT 4.0 or higher you can use the following call instead to 
// make the EXE free threaded. This means that calls come in on a random RPC thread.
//	HRESULT hRes = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
	ATLASSERT(SUCCEEDED(hRes));

	// this resolves ATL window thunking problem when Microsoft Layer for Unicode (MSLU) is used
	::DefWindowProc(NULL, 0, 0, 0L);

	HMODULE hInstRichEdit = ::LoadLibrary(_T("Msftedit.dll"));

	AtlInitCommonControls(ICC_BAR_CLASSES);	// add flags to support other controls
	GdiplusStartupInput		m_gdiplusStartupInput;
	ULONG_PTR				m_gdiplusToken;
	Status sta = GdiplusStartup(&m_gdiplusToken, &m_gdiplusStartupInput, NULL);		//GDI+³õʼ»¯
	

	hRes = _Module.Init(NULL, hInstance);
	ATLASSERT(SUCCEEDED(hRes));

	int nRet = Run(lpstrCmdLine, nCmdShow);

	GdiplusShutdown(m_gdiplusToken);

	if( hInstRichEdit != NULL )
	{
		FreeLibrary( hInstRichEdit );
	}

	_Module.Term();
	::CoUninitialize();

	return nRet;
}
int 
WINAPI 
_tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int nCmdShow)
{
	//NdasUiDbgCall( 1, "in, IsDebuggerPresent() = %d\n", IDebugClient2::IsKernelDebuggerEnabled() );
	NdasUiDbgCall( 1, "in, IsDebuggerPresent() = %d\n", IsDebuggerPresent() );

	OutputDebugString( _T("IsDebuggerPresent()\n") );

	// If you are running on NT 4.0 or higher you can use the following call instead to 
	// make the EXE free threaded. This means that calls come in on a random RPC thread.
	// HRESULT hRes = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);

	HRESULT hRes = ::CoInitialize(NULL);
	ATLASSERT(SUCCEEDED(hRes));

	// this resolves ATL window thunking problem when Microsoft Layer for Unicode (MSLU) is used

	::DefWindowProc( NULL, 0, 0, 0L );

	::AtlInitCommonControls( ICC_COOL_CLASSES | ICC_BAR_CLASSES );

	// add flags to support other controls

	hRes = _Module.Init(NULL, hInstance);
	ATLASSERT(SUCCEEDED(hRes));

	int ret = Run( lpstrCmdLine, nCmdShow );

	_Module.Term();
	::CoUninitialize();

	NdasUiDbgCall( 1, "*********out**********\n" );

	return ret;
}
Beispiel #9
0
extern "C" __declspec(dllexport) void LoadLuaRunTime(char* szInstallDir,char* szParam)
{
	TSTRACEAUTO();
	HRESULT hr = ::CoInitialize(NULL);
	hr = _Module.Init(NULL, gInstance);


	CMessageLoop theLoop;
	_Module.AddMessageLoop(&theLoop);

	CLRTAgent lrtAgent;
	if (lrtAgent.InitLua(szInstallDir,szParam))
	{
		TSDEBUG4CXX(_T(">>>>>theLoop.Run()"));
		theLoop.Run();
		TSDEBUG4CXX(_T("<<<<<theLoop.Run()"));
	}
	_Module.RemoveMessageLoop();
	_Module.Term();
	::CoUninitialize();
	TerminateProcess(::GetCurrentProcess(), S_OK);

	return;
}
Beispiel #10
0
int InitializeGui(HINSTANCE hInstance, LPARAM param)
{
	CoInitialize(NULL);

	AtlInitCommonControls(ICC_LISTVIEW_CLASSES | ICC_TREEVIEW_CLASSES);

	Scylla::initAsGuiApp();

	IsDllMode = false;

	HRESULT hRes = _Module.Init(NULL, hInstance);
	ATLASSERT(SUCCEEDED(hRes));

	

	int nRet = 0;
	// BLOCK: Run application
	{
		MainGui dlgMain;
		pMainGui = &dlgMain; // o_O

		CMessageLoop loop;
		_Module.AddMessageLoop(&loop);

		dlgMain.Create(GetDesktopWindow(), param);

		dlgMain.ShowWindow(SW_SHOW);

		loop.Run();
	}

	_Module.Term();
	CoUninitialize();

	return nRet;
}
Beispiel #11
0
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/) 
{
	if (dwReason == DLL_PROCESS_ATTACH) {
		_Module.Init(ObjectMap, hInstance);
		DisableThreadLibraryCalls(hInstance);

	CRegKey regCfg;
	DWORD dwSize = _MAX_PATH;
	
		if (ERROR_SUCCESS != regCfg.Open(HKEY_CURRENT_USER, _T("Software"), KEY_READ) ||
			ERROR_SUCCESS != regCfg.Open(regCfg, REG_COMPANY_KEY, KEY_READ) ||
			ERROR_SUCCESS != regCfg.Open(regCfg, REG_PRODUCT_KEY, KEY_READ) ||
			ERROR_SUCCESS != regCfg.Open(regCfg, _T("Config"), KEY_READ) ||
			ERROR_SUCCESS != regCfg.QueryValue(g_cbTRiAS, _T("TRiASName"), &dwSize) ||
			0 == dwSize)
		{
			strcpy (g_cbTRiAS, g_cbTRiASDefaultName);		// default
		}
	} 
	else if (dwReason == DLL_PROCESS_DETACH) {
		_Module.Term();
	}
	return TRUE;    // ok
}
Beispiel #12
0
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int /*nCmdShow*/)
{
  int argc = 0;
  LPWSTR* argv = CommandLineToArgvW(lpstrCmdLine, &argc);

  int nDelFlagPos = CmdLineFindFlag(argc, argv, L"-d");
  if (nDelFlagPos >= 0 && argc >= nDelFlagPos + 3)
  {
    DeleteUninst(argv[nDelFlagPos + 1], argv[nDelFlagPos + 2]);
    return 0;
  }
  
  //保证程序是唯一实例
  UniqueApp unique_uninst;
  if(!unique_uninst.Register())
  {
    //窗口激活,前置
    // activate an application with a window with a specific class name
    HWND pWndPrev, pWndChild;
    // Determine if a window with the class name exists...
    pWndPrev = FindWindow(_T("#32770"), UNINSTALL_TITLE);
    if(NULL != pWndPrev)
    {
      // If so, does it have any popups?
      pWndChild = GetLastActivePopup(pWndPrev);
      // If iconic, restore the main window
      if(IsIconic(pWndPrev))
        ShowWindow(pWndPrev,SW_RESTORE);
      // Bring the main window or its popup to the foreground
      SetForegroundWindow(pWndChild);
      // and you are done activating the other application
      return EXIT_ERROR_NOT_GET_OTHER_INSTANCE_WND;
    }
    return EXIT_ERROR_GET_OTHER_INSTANCE_WND;
  }

  InitDataReport(argc, argv);
  HRESULT hRes = ::CoInitialize(NULL);

  GDIPlusFacade::Startup(hInstance);
// If you are running on NT 4.0 or higher you can use the following call instead to 
// make the EXE free threaded. This means that calls come in on a random RPC thread.
//	HRESULT hRes = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
	ATLASSERT(SUCCEEDED(hRes));

	// this resolves ATL window thunking problem when Microsoft Layer for Unicode (MSLU) is used
	::DefWindowProc(NULL, 0, 0, 0L);

	AtlInitCommonControls(ICC_BAR_CLASSES);	// add flags to support other controls

	hRes = _Module.Init(NULL, hInstance);
	ATLASSERT(SUCCEEDED(hRes));

  int nRet = 0;
  {
    if (!CUnInstallManager::GetInstance().Init()) //安装前置条件
      goto EXIT_MAIN;
  }

	// BLOCK: Run application
	{
		CChooseUninstallDialog dlg_choose_uninstall;
		nRet = dlg_choose_uninstall.DoModal();
	}

  CUnInstallManager::GetInstance().UnInit();
EXIT_MAIN:
	_Module.Term();

  GDIPlusFacade::Shutdown();
	::CoUninitialize();

	ygdata_report::Exit(TRUE);
	if (argv)
	{
		LocalFree(argv);
		argv = NULL;
	}
	return nRet;
}
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int nCmdShow)
{
	CRecordProgram::GetInstance()->RecordCommonInfo(MY_PRO_NAME, MY_THREAD_ID_INIT, L"启动");

	DWORD pid = ::GetCurrentThreadId();
	HRESULT hRes = ::CoInitialize(NULL);
	g_strSkinDir = ::GetModulePath();
	g_strSkinDir += _T("\\Skin\\");
// If you are running on NT 4.0 or higher you can use the following call instead to 
// make the EXE free threaded. This means that calls come in on a random RPC thread.
//	HRESULT hRes = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);

	if (_tcsncmp(lpstrCmdLine, _T("-reblack"), 8) == 0)
	{
		HANDLE hEvent = OpenEventW(EVENT_ALL_ACCESS, FALSE, L"MONEYHUBEVENT_BLACKUPDATE");
		CRecordProgram::GetInstance()->RecordCommonInfo(MY_PRO_NAME, MY_THREAD_ID_INIT, L"重新创建黑名单");
		CGlobalData::GetInstance()->Init();
		int iReturn = (int)_SecuCheckPop.CheckBlackListCache();
		if( hEvent )
		{
			SetEvent(hEvent);
			CloseHandle(hEvent);
		}
		return iReturn;
	}

	if (_tcsncmp(lpstrCmdLine, _T("-rebuild"), 8) == 0)
	{
		HANDLE hEvent = OpenEventW(EVENT_ALL_ACCESS, FALSE, L"MONEYHUBEVENT_WHITEUPDATE");
		CRecordProgram::GetInstance()->RecordCommonInfo(MY_PRO_NAME, MY_THREAD_ID_INIT, L"重新创建白名单");
		CGlobalData::GetInstance()->Init();
		int iReturn = (int)_SecuCheckPop.ReBuildSercurityCache();
		if( hEvent )
		{
			SetEvent(hEvent);
			CloseHandle(hEvent);
		}
		return iReturn;
	}

	ThreadCacheDC::InitializeThreadCacheDC();
	ThreadCacheDC::CreateThreadCacheDC();

	DWORD dw;
	CloseHandle(CreateThread(NULL, 0, _threadTestDownloadMode, NULL, 0, &dw));

	Gdiplus::GdiplusStartupInput gdiplusStartupInput;
	ULONG_PTR gdiplusToken;
	Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

	if(CGlobalData::GetInstance()->IsPopAlreadyRunning() == TRUE)
	{
		mhMessageBox(NULL, _T("泡泡程序已经在运行中..."), L"财金汇", MB_OK | MB_SETFOREGROUND);
		return 0;
	}

	ATLASSERT(SUCCEEDED(hRes));

	CUserBehavior::GetInstance()->BeginFeedBack();

	_SecuCheckPop.Start();// 开启安全检测及驱动进程
	CRecordProgram::GetInstance()->RecordCommonInfo(MY_PRO_NAME, MY_THREAD_ID_INIT, L"启动安全检测及驱动进程");

	//CUSBControl::GetInstance()->BeginUSBControl();
	// this resolves ATL window thunking problem when Microsoft Layer for Unicode (MSLU) is used
	::DefWindowProc(NULL, 0, 0, 0L);

	AtlInitCommonControls(ICC_WIN95_CLASSES | ICC_PROGRESS_CLASS | ICC_BAR_CLASSES);	// add flags to support other controls

	hRes = _Module.Init(NULL, hInstance);
	ATLASSERT(SUCCEEDED(hRes));


	CRecordProgram::GetInstance()->RecordCommonInfo(MY_PRO_NAME, MY_THREAD_ID_INIT, L"运行");

	int nRet = Run(lpstrCmdLine, nCmdShow);

	_Module.Term();

	//::CoUninitialize();

	CUserBehavior::GetInstance()->CloseFeedBack();

	return nRet;
}
int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
                      _In_opt_ HINSTANCE hPrevInstance,
                      _In_ LPWSTR lpCmdLine,
                      _In_ int nCmdShow)
{
	// Attempt to mitigate http://textslashplain.com/2015/12/18/dll-hijacking-just-wont-die
	HMODULE hKernel32 = LoadLibrary(L"kernel32.dll");
	ATLASSERT(hKernel32 != NULL);

	SetDefaultDllDirectoriesFunction pfn = (SetDefaultDllDirectoriesFunction) GetProcAddress(hKernel32, "SetDefaultDllDirectories");
	if (pfn) { (*pfn)(LOAD_LIBRARY_SEARCH_SYSTEM32); }

	int exitCode = -1;
	CString cmdLine(lpCmdLine);

	if (cmdLine.Find(L"--checkInstall") >= 0) {
		// If we're already installed, exit as fast as possible
		if (!MachineInstaller::ShouldSilentInstall()) {
			exitCode = 0;
			goto out;
		}

		// Make sure update.exe gets silent
		wcscat(lpCmdLine, L" --silent");
	}

	HRESULT hr = ::CoInitialize(NULL);
	ATLASSERT(SUCCEEDED(hr));

	AtlInitCommonControls(ICC_COOL_CLASSES | ICC_BAR_CLASSES);
	hr = _Module.Init(NULL, hInstance);

	bool isQuiet = (cmdLine.Find(L"-s") >= 0);
	bool weAreUACElevated = CUpdateRunner::AreWeUACElevated() == S_OK;
	bool attemptingToRerun = (cmdLine.Find(L"--rerunningWithoutUAC") >= 0);

	if (weAreUACElevated && attemptingToRerun) {
		CUpdateRunner::DisplayErrorMessage(CString(L"Please re-run this installer as a normal user instead of \"Run as Administrator\"."), NULL);
		exitCode = E_FAIL;
		goto out;
	}

	if (!CFxHelper::CanInstallDotNet4_5()) {
		// Explain this as nicely as possible and give up.
		MessageBox(0L, L"This program cannot run on Windows XP or before; it requires a later version of Windows.", L"Incompatible Operating System", 0);
		exitCode = E_FAIL;
		goto out;
	}

	if (!CFxHelper::IsDotNet45OrHigherInstalled()) {
		hr = CFxHelper::InstallDotNetFramework(isQuiet);
		if (FAILED(hr)) {
			exitCode = hr; // #yolo
			CUpdateRunner::DisplayErrorMessage(CString(L"Failed to install the .NET Framework, try installing .NET 4.5 or higher manually"), NULL);
			goto out;
		}
	
		// S_FALSE isn't failure, but we still shouldn't try to install
		if (hr != S_OK) {
			exitCode = 0;
			goto out;
		}
	}

	// If we're UAC-elevated, we shouldn't be because it will give us permissions
	// problems later. Just silently rerun ourselves.
	if (weAreUACElevated) {
		wchar_t buf[4096];
		HMODULE hMod = GetModuleHandle(NULL);
		GetModuleFileNameW(hMod, buf, 4096);
		wcscat(lpCmdLine, L" --rerunningWithoutUAC");

		CUpdateRunner::ShellExecuteFromExplorer(buf, lpCmdLine);
		exitCode = 0;
		goto out;
	}

	exitCode = CUpdateRunner::ExtractUpdaterAndRun(lpCmdLine, false);

out:
	_Module.Term();
	::CoUninitialize();
	return exitCode;
}
Beispiel #15
0
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int nCmdShow)
{
	HRESULT hRes = ::CoInitialize(NULL);
// If you are running on NT 4.0 or higher you can use the following call instead to 
// make the EXE free threaded. This means that calls come in on a random RPC thread.
//	HRESULT hRes = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
	ATLASSERT(SUCCEEDED(hRes));
  
  // Install crash reporting
#ifdef TEST_DEPRECATED_FUNCS

  g_pCrashRptState = Install(
    CrashCallback, 
    _T("*****@*****.**"), 
    _T("Crash"));

#else

  CR_INSTALL_INFO info;
  memset(&info, 0, sizeof(CR_INSTALL_INFO));
  info.cb = sizeof(CR_INSTALL_INFO);  
  info.pszAppName = _T("CrashRpt Tests");
  info.pszAppVersion = _T("1.2.2");
  info.pszEmailSubject = _T("Error from CrashRptTests");
  info.pszEmailTo = _T("*****@*****.**");  
  info.pszUrl = _T("http://myappcom.com/crashrpt.php");
  info.pfnCrashCallback = CrashCallback; // Define crash callback function   
  // Define sending priorities
  info.uPriorities[CR_HTTP] = 3;         // Use HTTP the first
  info.uPriorities[CR_SMTP] = 2;         // Use SMTP the second
  info.uPriorities[CR_SMAPI] = 1;        // Use Simple MAPI the last   
  info.dwFlags = 0;
  info.dwFlags |= CR_INST_ALL_EXCEPTION_HANDLERS; // Install all available exception handlers
  info.dwFlags |= CR_INST_HTTP_BINARY_ENCODING;   // Use binary encoding for HTTP uploads (recommended).  
  info.pszDebugHelpDLL = NULL;           // Search for dbghelp.dll using default search sequence
  info.uMiniDumpType = MiniDumpNormal;   // Define minidump size
  info.pszPrivacyPolicyURL = _T("http://code.google.com/p/crashrpt/wiki/PrivacyPolicyTemplate");
  info.pszErrorReportSaveDir = NULL;    // Save error reports to the default location
    
  CrAutoInstallHelper cr_install_helper(&info);
  ATLASSERT(cr_install_helper.m_nInstallStatus==0); 

  if(cr_install_helper.m_nInstallStatus!=0)
  {
    TCHAR buff[256];
    crGetLastErrorMsg(buff, 256);
    MessageBox(NULL, buff, _T("crInstall error"), MB_OK);
    return FALSE;
  }

#endif //TEST_DEPRECATED_FUNCS

  /* Create another thread */
  g_CrashThreadInfo.m_pCrashRptState = g_pCrashRptState;
  g_CrashThreadInfo.m_bStop = false;
  g_CrashThreadInfo.m_hWakeUpEvent = CreateEvent(NULL, FALSE, FALSE, _T("WakeUpEvent"));
  ATLASSERT(g_CrashThreadInfo.m_hWakeUpEvent!=NULL);

  DWORD dwThreadId = 0;
  g_hWorkingThread = CreateThread(NULL, 0, CrashThread, (LPVOID)&g_CrashThreadInfo, 0, &dwThreadId);
  ATLASSERT(g_hWorkingThread!=NULL);

	// this resolves ATL window thunking problem when Microsoft Layer for Unicode (MSLU) is used
	::DefWindowProc(NULL, 0, 0, 0L);

	AtlInitCommonControls(ICC_BAR_CLASSES);	// add flags to support other controls

	hRes = _Module.Init(NULL, hInstance);
	ATLASSERT(SUCCEEDED(hRes));

	int nRet = Run(lpstrCmdLine, nCmdShow);

	_Module.Term();

  // Close another thread
  g_CrashThreadInfo.m_bStop = true;
  SetEvent(g_CrashThreadInfo.m_hWakeUpEvent);
  // Wait until thread terminates
  WaitForSingleObject(g_hWorkingThread, INFINITE);

  
#ifdef TEST_DEPRECATED_FUNCS
  // Uninstall crash reporting
  Uninstall(g_pCrashRptState);

#endif //TEST_DEPRECATED_FUNCS

	::CoUninitialize();

	return nRet;
}
Beispiel #16
0
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int nCmdShow)
{
    HRESULT hRes = ::CoInitialize(NULL);
    // If you are running on NT 4.0 or higher you can use the following call instead to 
    // make the EXE free threaded. This means that calls come in on a random RPC thread.
    //	HRESULT hRes = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
    ATLASSERT(SUCCEEDED(hRes));

    // Install crash reporting

    CR_INSTALL_INFO info;
    memset(&info, 0, sizeof(CR_INSTALL_INFO));
    info.cb = sizeof(CR_INSTALL_INFO);  
    info.pszAppName = _T("WTLDemo"); // Define application name.
    //info.pszAppVersion = _T("1.3.1");     // Define application version.
    info.pszEmailSubject = _T("WTLDemo Error Report"); // Define subject for email.
    info.pszEmailTo = _T("*****@*****.**");   // Define E-mail recipient address.  
	//info.pszSmtpProxy = _T("127.0.0.1");  // Use SMTP proxy.
	//info.pszSmtpLogin = _T("test");      // SMTP Login
	//info.pszSmtpPassword = _T("test");       // SMTP Password
    info.pszUrl = _T("http://localhost:80/crashrpt.php"); // URL for sending reports over HTTP.				
    info.pfnCrashCallback = CrashCallback; // Define crash callback function.   
    // Define delivery methods priorities. 
    info.uPriorities[CR_HTTP] = 3;         // Use HTTP the first.
    info.uPriorities[CR_SMTP] = 2;         // Use SMTP the second.
    info.uPriorities[CR_SMAPI] = 1;        // Use Simple MAPI the last.  
    info.dwFlags = 0;                    
    info.dwFlags |= CR_INST_ALL_POSSIBLE_HANDLERS; // Install all available exception handlers.    
    //info.dwFlags |= CR_INST_APP_RESTART;            // Restart the application on crash.  
    //info.dwFlags |= CR_INST_NO_MINIDUMP;          // Do not include minidump.
    //info.dwFlags |= CR_INST_NO_GUI;               // Don't display GUI.
    //info.dwFlags |= CR_INST_DONT_SEND_REPORT;     // Don't send report immediately, just queue for later delivery.
    //info.dwFlags |= CR_INST_STORE_ZIP_ARCHIVES;   // Store ZIP archives along with uncompressed files (to be used with CR_INST_DONT_SEND_REPORT)
    //info.dwFlags |= CR_INST_SEND_MANDATORY;         // Remove "Close" and "Other actions..." buttons from Error Report dialog.
	//info.dwFlags |= CR_INST_SHOW_ADDITIONAL_INFO_FIELDS; //!< Make "Your E-mail" and "Describe what you were doing when the problem occurred" fields of Error Report dialog always visible.
	info.dwFlags |= CR_INST_ALLOW_ATTACH_MORE_FILES; //!< Adds an ability for user to attach more files to crash report by clicking "Attach More File(s)" item from context menu of Error Report Details dialog.
	//info.dwFlags |= CR_INST_SEND_QUEUED_REPORTS;    // Send reports that were failed to send recently.	
	//info.dwFlags |= CR_INST_AUTO_THREAD_HANDLERS; 
    info.pszDebugHelpDLL = NULL;                    // Search for dbghelp.dll using default search sequence.
    info.uMiniDumpType = MiniDumpNormal;            // Define minidump size.
    // Define privacy policy URL.
    info.pszPrivacyPolicyURL = _T("http://code.google.com/p/crashrpt/wiki/PrivacyPolicyTemplate");
    info.pszErrorReportSaveDir = NULL;       // Save error reports to the default location.
    info.pszRestartCmdLine = _T("/restart"); // Command line for automatic app restart.
    //info.pszLangFilePath = _T("D:\\");       // Specify custom dir or filename for language file.
    //info.pszCustomSenderIcon = _T("C:\\WINDOWS\\System32\\user32.dll, 1"); // Specify custom icon for CrashRpt dialogs.
	info.nRestartTimeout = 50;

    // Install crash handlers.
    CrAutoInstallHelper cr_install_helper(&info);
    if(cr_install_helper.m_nInstallStatus!=0)
    {
        TCHAR buff[256];
        crGetLastErrorMsg(buff, 256);
        MessageBox(NULL, buff, _T("crInstall error"), MB_OK);
        return FALSE;
    }
    ATLASSERT(cr_install_helper.m_nInstallStatus==0); 

    CString sLogFile = GetAppDir() + _T("\\*.log");
    CString sIniFile = _T("\\\\?\\") + GetAppDir() + _T("\\dummy.ini");

    int nResult = crAddFile2(sLogFile, NULL, _T("Dummy Log File"), CR_AF_MAKE_FILE_COPY|CR_AF_ALLOW_DELETE);
    ATLASSERT(nResult==0);
    
    nResult = crAddFile2(sIniFile, NULL, _T("Dummy INI File"), 0);
    ATLASSERT(nResult==0);

    nResult = crAddScreenshot2(CR_AS_PROCESS_WINDOWS|CR_AS_USE_JPEG_FORMAT|CR_AS_ALLOW_DELETE, 10);
    //nResult = crAddScreenshot(CR_AS_MAIN_WINDOW);
    ATLASSERT(nResult==0);
	
	nResult = crAddProperty(_T("AnExampleProperty"),_T("Property value"));
    ATLASSERT(nResult==0);

    nResult = crAddProperty(_T("VideoCard"),_T("nVidia GeForce 9800"));
    ATLASSERT(nResult==0);
		
	nResult = crAddProperty(_T("HDDSerialNumber"),_T("1234512345098765"));
    ATLASSERT(nResult==0);

	nResult = crAddProperty(_T("MACAddress"),_T("11.11.11.11"));
    ATLASSERT(nResult==0);

	nResult = crAddProperty(_T("UserName"),_T("TheUserName"));
    ATLASSERT(nResult==0);

    nResult = crAddRegKey(_T("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer"), _T("regkey.xml"), CR_AR_ALLOW_DELETE);
    ATLASSERT(nResult==0);

    nResult = crAddRegKey(_T("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"), _T("regkey.xml"), CR_AR_ALLOW_DELETE);
    ATLASSERT(nResult==0);

    /* Create another thread */
    g_CrashThreadInfo.m_bStop = false;
    g_CrashThreadInfo.m_hWakeUpEvent = CreateEvent(NULL, FALSE, FALSE, _T("WakeUpEvent"));
    ATLASSERT(g_CrashThreadInfo.m_hWakeUpEvent!=NULL);

    DWORD dwThreadId = 0;
    g_hWorkingThread = CreateThread(NULL, 0, CrashThread, (LPVOID)&g_CrashThreadInfo, 0, &dwThreadId);
    ATLASSERT(g_hWorkingThread!=NULL);

    // this resolves ATL window thunking problem when Microsoft Layer for Unicode (MSLU) is used
    ::DefWindowProc(NULL, 0, 0, 0L);

    AtlInitCommonControls(ICC_BAR_CLASSES);	// add flags to support other controls

    hRes = _Module.Init(NULL, hInstance);
    ATLASSERT(SUCCEEDED(hRes));

    int nRet = Run(lpstrCmdLine, nCmdShow);

    _Module.Term();

    // Close another thread
    g_CrashThreadInfo.m_bStop = true;
    SetEvent(g_CrashThreadInfo.m_hWakeUpEvent);
    // Wait until thread terminates
    WaitForSingleObject(g_hWorkingThread, INFINITE);

    ::CoUninitialize();

    return nRet;
}
Beispiel #17
0
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int /*nCmdShow*/)
{
	HRESULT hRes = ::OleInitialize(NULL);

	//HRESULT hRes = ::CoInitialize(NULL);
// If you are running on NT 4.0 or higher you can use the following call instead to 
// make the EXE free threaded. This means that calls come in on a random RPC thread.
//	HRESULT hRes = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
	ATLASSERT(SUCCEEDED(hRes));

	// this resolves ATL window thunking problem when Microsoft Layer for Unicode (MSLU) is used
	::DefWindowProc(NULL, 0, 0, 0L);

	AtlInitCommonControls(ICC_BAR_CLASSES | ICC_DATE_CLASSES);	// add flags to support other controls

	hRes = _Module.Init(NULL, hInstance);
	ATLASSERT(SUCCEEDED(hRes));

	AtlAxWinInit();

	int nRet = 0;
	try
	{	CMainDlg dlgMain;

	//DebugFileOut debugfile(CString((::ExeDirectory() + "debug.txt").c_str()));
	//	basic_debugbuf debugbuf(2048);
	//	std::cout.rdbuf(&debugfile);
	//	cout<< "Test Me" << endl;
	//
	//
	//	Yaml storage ;
	//	ParseIniFile("C:\\Program Files\\MTConnect\\Agent\\Agent.cfg", storage );

	// BLOCK: Run application


	std::string cfgfilename;
	std::string destinationfolder("C:\\Program Files\\MTConnect\\Agent\\");
	options_description desc("Allowed options");
		AtlTrace(StdStringFormat("AgentCfg=%s\n",lpstrCmdLine).c_str() );
	desc.add_options()
		("-f", value<std::string>(), "ConfigFile")
		("-p", value<std::string>(), "HTTP Port")
		("-d", value<std::string>(), "Destination folder")
		("-restart", "Restart Agent Service")
		;
	if(__argc > 1)
	{
		try {
			variables_map vm;
			std::vector<std::string> args = split_winmain(lpstrCmdLine);
			store(command_line_parser(args).options(desc).run(), vm);
			if (vm.count("-f")) { cfgfilename= vm["-f"].as<std::string>();}
			if (vm.count("-p")) { dlgMain.HttpPort() = vm["-p"].as<std::string>();}
			if (vm.count("-d")) { destinationfolder= vm["-d"].as<std::string>();}

		}
		catch(std::exception e)
		{
			AtlTrace(e.what());
		}
		AtlTrace(StdStringFormat("AgentCfg CfgFile=%s\n",cfgfilename.c_str()).c_str() );
		AtlTrace(StdStringFormat("AgentCfg Destinationfolder=%s\n",destinationfolder.c_str()).c_str() );
	// FIXME: error checking
		std::string contents;
		ReplaceAll(cfgfilename,"\"", "");
		ReplaceAll(destinationfolder,"\"", "");
		ReadFile(cfgfilename, contents);
		AtlTrace(contents.c_str());
		dlgMain.UpdateLists(contents);
		dlgMain.WriteCfgFile(destinationfolder);
	}

	else
	{

		nRet = dlgMain.DoModal();
	}
	}
	catch(...)
	{

		OutputDebugString("_tWinMain Exception \n ");
	}

	_Module.Term();
	::CoUninitialize();

	return nRet;
}
Beispiel #18
0
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE, LPTSTR lpstrCmdLine, int nCmdShow)
{
	CString strDir;
	GetCurrentDirectory(MAX_PATH, strDir.GetBuffer(MAX_PATH));
	strDir.ReleaseBuffer();

	unsigned int i, nCount;

	IniOptions ini(strDir + _T("\\psdl-editor.ini"));

	ini.SetSection("Files");
	config.files.strBrowseDir = ini.GetString("Browse_Dir");

	ini.SetSection("TexturePaths");
	nCount = ini.GetInt("Count");
	for (i = 1; i <= nCount; ++i)
	{
		CString strKey;
		strKey.Format("%u", i);
		config.directories.texturePaths.push_back(ini.GetString(strKey));
	}

	ini.SetSection("Tools");
	config.tools.strMM2Dir = ini.GetString("MM2_Dir", DEFAULT_MM2_DIR);
	config.tools.strMM2Exe = ini.GetString("MM2_Exe", DEFAULT_MM2_EXE);
	config.tools.strSDLViewExe = ini.GetString("SDLView_Exe");

	ini.SetSection("Recent");
	nCount = ini.GetInt("Count");
	for (i = 1; i <= nCount; ++i)
	{
		CString strKey;
		strKey.Format("%u", i);
		config.files.aRecentFiles.push(ini.GetString(strKey));
	}

	::DefWindowProc(NULL, 0, 0, 0L);

	HRESULT hRes = _Module.Init(NULL, hInstance);
	ATLASSERT(SUCCEEDED(hRes));

	int nRet = Run(lpstrCmdLine, nCmdShow);

	_Module.Term();

	ini.SetSection("Files");
	ini.WriteString("Browse_Dir", config.files.strBrowseDir);

	ini.SetSection("TexturePaths");
	nCount = config.directories.texturePaths.size();
	ini.WriteString(NULL);
	ini.WriteInt("Count", nCount);
	for (i = 1; i <= nCount; ++i)
	{
		CString strKey;
		strKey.Format("%u", i);
		ini.WriteString(strKey, config.directories.texturePaths[i-1].c_str());
	}

	ini.SetSection("Tools");
	ini.WriteString("MM2_Dir", config.tools.strMM2Dir);
	ini.WriteString("MM2_Exe", config.tools.strMM2Exe);
	ini.WriteString("SDLView_Exe", config.tools.strSDLViewExe);

	ini.SetSection("Recent");
	nCount = config.files.aRecentFiles.size();
	ini.WriteString(NULL);
	ini.WriteInt("Count", nCount);
	for (i = 1; i <= nCount; ++i)
	{
		CString strKey;
		strKey.Format("%u", i);
		ini.WriteString(strKey, config.files.aRecentFiles.top().c_str());
		config.files.aRecentFiles.pop();
	}

	return nRet;
}
Beispiel #19
0
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, 
	LPSTR lpCmdLine, int nCmdShow)
{
	USES_CONVERSION;

	//
	// Resolve UNICOWS's thunk (required)
	//

	::DefWindowProc (NULL, 0, 0, 0);

	//
	// Load the application name
	//

	::LoadString (_Module .GetResourceInstance (),
		IDR_NWNEXPLORER, g_szAppName, _countof (g_szAppName));

	//
	// Test for FMOD
	//

	g_hFMODLibrary = ::LoadLibrary (_T ("FMOD.DLL"));

	//
	// Initialize FMOD
	//

	if (g_hFMODLibrary != NULL)
	{
		if (FSOUND_GetVersion () < FMOD_VERSION)
		{
			//FIXME
		}
		if (!FSOUND_Init (44100, 32, FSOUND_INIT_GLOBALFOCUS))
		{
			//FIXME
			FSOUND_Close ();
			return 0;
		}
	}

	//
	// Create our image lists
	//

	{
		CDC dcMem;
		dcMem .CreateCompatibleDC (NULL);
		if (dcMem .GetDeviceCaps (BITSPIXEL) > 8)
		{
			g_ilSmall .Create (16, 16, ILC_COLOR16 | ILC_MASK, 16, 16);
			g_ilLarge .Create (24, 24, ILC_COLOR16 | ILC_MASK, 16, 16);
			CBitmap bmSmall;
			bmSmall .LoadBitmap (IDB_TOOLBAR_16_256COLOR);
			g_ilSmall .Add (bmSmall, RGB (255, 0, 255));
			CBitmap bmLarge;
			bmLarge .LoadBitmap (IDB_TOOLBAR_24_256COLOR);
			g_ilLarge .Add (bmLarge, RGB (255, 0, 255));
		}
		else
		{
			g_ilSmall .Create (16, 16, ILC_COLOR | ILC_MASK, 16, 16);
			g_ilLarge .Create (24, 24, ILC_COLOR | ILC_MASK, 16, 16);
			CBitmap bmSmall;
			bmSmall .LoadBitmap (IDB_TOOLBAR_16_16COLOR);
			g_ilSmall .Add (bmSmall, RGB (255, 0, 255));
			CBitmap bmLarge;
			bmLarge .LoadBitmap (IDB_TOOLBAR_24_16COLOR);
			g_ilLarge .Add (bmLarge, RGB (255, 0, 255));
		}
		g_ilSmall .SetBkColor (::GetSysColor (COLOR_3DFACE));
		g_ilLarge .SetBkColor (::GetSysColor (COLOR_3DFACE));
	}

	//
	// Enable leak checking
	//

#if defined (_DEBUG)
	_CrtSetDbgFlag (_CrtSetDbgFlag (_CRTDBG_REPORT_FLAG) | _CRTDBG_LEAK_CHECK_DF);
#endif

	//
	// Initialize ATL
	//

	_Module.Init (ObjectMap, hInstance);

	//
	// Initialize the printer
	//

	g_sPrinter .OpenDefaultPrinter ();
	g_sDevMode .CopyFromPrinter (g_sPrinter);

	//
	// Validate the version of the common controls
	//

	DWORD dwComCtlMajor, dwComCtlMinor;
	if (!GetDllVersion (TEXT ("comctl32.dll"), 
	    dwComCtlMajor, dwComCtlMinor) || dwComCtlMajor < 5 ||
		(dwComCtlMajor == 5 && dwComCtlMinor < 80))
	{
		::MessageBox (NULL, 
			_T ("You are running an old version of comctl32.dll.\r\n")
			_T ("Please download a new version from:\r\n\r\n")
			_T ("http://www.torlack.com/other/50comupd.exe")
			, g_szAppName, MB_OK | MB_ICONHAND);
		return 0;
	}

	//
	// Initialize the common controls
	//

    INITCOMMONCONTROLSEX icex;    
	typedef WINCOMMCTRLAPI BOOL WINAPI _x (LPINITCOMMONCONTROLSEX); 
	_x *px;
	HINSTANCE hComCtl = LoadLibraryA ("comctl32.dll");
	px = (_x *) GetProcAddress (hComCtl, "InitCommonControlsEx");
	bool fWorked = false;
	if (px != NULL)
	{
		icex .dwSize = sizeof (INITCOMMONCONTROLSEX);
		icex .dwICC = ICC_WIN95_CLASSES | ICC_DATE_CLASSES | 
			ICC_USEREX_CLASSES | ICC_COOL_CLASSES;
		fWorked = (*px) (&icex) != 0;
	}
	if (!fWorked)
	{
		::MessageBox (NULL, 
	        _T ( "Unable to initialize COMCTL32.DLL"), 
			g_szAppName, MB_OK | MB_ICONHAND);
		return 0;
	}

	//
	// Create the message loop
	//

	CMyMessageLoop theLoop;
	_Module .AddMessageLoop (&theLoop);

	//
	// Create the window
	//

	CMainWnd sMainWnd;
	g_hWndMain = sMainWnd .Create ();
	if (g_hWndMain == NULL)
	{
		CString str (MAKEINTRESOURCE (IDS_ERR_MAIN_WINDOW));
		::MessageBox (NULL, str, g_szAppName, MB_OK | MB_ICONHAND);
		return 0;
	}

	//
	// Pump messages
	//

	theLoop .Run ();
	_Module .RemoveMessageLoop ();

	//
	// Delete the palettes
	//

	for (int i = 0; i < _countof (g_apPalettes); i++)
	{
		if (g_apPalettes [i])
			delete [] g_apPalettes [i];
	}

	//
	// Close up printer (Not required, but keeps Purify happy)
	//

	g_sPrinter .ClosePrinter ();
	g_sDevMode .Detach ();

	//
	// Close FMOD
	//

	if (g_hFMODLibrary != NULL)
	{
		FSOUND_Close ();
	}

	//
	// Terminate the module
	//

	_Module .Term ();
	return 0;
}
Beispiel #20
0
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int nCmdShow)
{
	//MessageBox(NULL, lpstrCmdLine, "Command line", MB_OK);
	HRESULT hRes = ::CoInitialize(NULL);
// If you are running on NT 4.0 or higher you can use the following call instead to 
// make the EXE free threaded. This means that calls come in on a random RPC thread.
//	HRESULT hRes = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
	ATLASSERT(SUCCEEDED(hRes));

	// this resolves ATL window thunking problem when Microsoft Layer for Unicode (MSLU) is used
	::DefWindowProc(NULL, 0, 0, 0L);

	AtlInitCommonControls(ICC_BAR_CLASSES);	// add flags to support other controls

	hRes = _Module.Init(NULL, hInstance);
	ATLASSERT(SUCCEEDED(hRes));

	// don't allow multiple instances, wait for previous to terminate
	HANDLE mutex = ::CreateMutex(NULL, TRUE, _T("MoleculesInitMTX"));
	if(mutex && ::GetLastError() == ERROR_ALREADY_EXISTS)
	{
		DWORD state = WaitForSingleObject(mutex, 500);
		if(state == WAIT_TIMEOUT || state == WAIT_FAILED)
		{
			_Module.Term();
			::CoUninitialize();
			return 0;
		}
	}

	// find out where our binary (.scr) is located
	// this is used to locate molecules folder later
	std::unique_ptr<TCHAR[]> mod(new TCHAR[MAX_PATH]);
	::GetModuleFileName(NULL, mod.get(), MAX_PATH-1);
	*(_tcsrchr(mod.get(), '\\')+1) = '\0';
	TCHAR drive;
	if(islower((int)mod[0]))
		drive = _toupper(mod[0]);
	else
		drive = mod[0];
	int drv = (int)drive-64;
	_chdrive(drv);
	_tchdir(mod.get());

	int nRet = 0;
  TCHAR szTokens[] = _T("-/");
  HWND hwndParent = NULL;

	// check reason for a call
	ECallReason cr = eSettings; // when no parameter given, show settings
  LPCTSTR lpszToken = _Module.FindOneOf(::GetCommandLine(), szTokens);
  if (lpszToken != NULL)
  {
		// XXX this flag is no longer used by windows?
    //if(_tcsnicmp(lpszToken, _T("c"), 1) == 0)
    //{
			// settings (configuration dialog)
		//	cr = eSettings;
     // hwndParent = GetForegroundWindow();
    //}
    if(_tcsnicmp(lpszToken, _T("p "), 2) == 0)
    {
			// preview
			cr = ePreview;
      int n = 0;
      _stscanf_s(lpszToken+1, _T("%i%n"), &hwndParent, &n);
      lpszToken += n+1;
    }
    else if(_tcsnicmp(lpszToken, _T("s"), 1) == 0)
    {
			// normal screen saver mode
			cr = eRun;
    }
    // lpszToken = _Module.FindOneOf(lpszToken, szTokens);
  }

	switch (cr)
	{
	default:
	case eRun:
		nRet = Run(lpstrCmdLine, nCmdShow);
		break;
	case ePreview:
		nRet = Preview(hwndParent);
		break;
	case eSettings:
#ifdef DEBUG
		// in debug builds run saver instead of settings when launched
		nRet = Run(lpstrCmdLine, nCmdShow);
#else
		nRet = Settings(hwndParent);
#endif
		break;
	}

	_Module.Term();
	::CoUninitialize();

	return nRet;
}
Beispiel #21
0
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int nCmdShow)
{
	// 防止服务进程开启输入法
	ImmDisableIME(-1);

	{
		WCHAR user_name[20] = {0};
		DWORD size = _countof(user_name);
		GetUserName(user_name, &size);
		if (!_wcsicmp(user_name, L"SYSTEM"))
		{
			return 1;
		}
	}

	HRESULT hRes = ::CoInitialize(NULL);
	// If you are running on NT 4.0 or higher you can use the following call instead to 
	// make the EXE free threaded. This means that calls come in on a random RPC thread.
	//HRESULT hRes = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
	ATLASSERT(SUCCEEDED(hRes));

	// this resolves ATL window thunking problem when Microsoft Layer for Unicode (MSLU) is used
	::DefWindowProc(NULL, 0, 0, 0L);

	AtlInitCommonControls(ICC_BAR_CLASSES);	// add flags to support other controls

	hRes = _Module.Init(NULL, hInstance);
	ATLASSERT(SUCCEEDED(hRes));

	if (!wcscmp(L"/userdir", lpstrCmdLine))
	{
		CreateDirectory(WeaselUserDataPath().c_str(), NULL);
		WeaselServerApp::explore(WeaselUserDataPath());
		return 0;
	}
	if (!wcscmp(L"/weaseldir", lpstrCmdLine))
	{
		WeaselServerApp::explore(WeaselServerApp::install_dir());
		return 0;
	}

	// command line option /q stops the running server
	bool quit = !wcscmp(L"/q", lpstrCmdLine) || !wcscmp(L"/quit", lpstrCmdLine);
	// restart if already running
	{
		weasel::Client client;
		if (client.Connect())  // try to connect to running server
		{
			client.ShutdownServer();
		}
		if (quit)
			return 0;
	}

	bool check_updates = !wcscmp(L"/update", lpstrCmdLine);
	if (check_updates)
	{
		WeaselServerApp::check_update();
	}

	CreateDirectory(WeaselUserDataPath().c_str(), NULL);

	int nRet = 0;
	try
	{
		WeaselServerApp app;
		nRet = app.Run();
	}
	catch (...)
	{
		// bad luck...
		nRet = -1;
	}

	_Module.Term();
	::CoUninitialize();

	return nRet;
}
Beispiel #22
0
int __cdecl wmain(DWORD argc, LPWSTR *argv)
{
	NdasUiDbgCall( 1, "in\n" );

	CCoInitialize coinit(COINIT_MULTITHREADED);

	//
	// Service Debugging support
	//
	DWORD dwStartupDelay = NdasServiceConfig::Get(nscDebugStartupDelay);
	if (dwStartupDelay > 0)
	{
		::Sleep(dwStartupDelay);
	}

	BOOL fDebugBreak = NdasServiceConfig::Get(nscDebugInitialBreak);
	if (fDebugBreak) 
	{
		::DebugBreak();
	}

#ifdef RUN_WPP
	WPP_INIT_TRACING(L"NDASSVC");
#endif

	XTL::XtlTraceSetTraceLevel(TRACE_LEVEL_ERROR);

	//
	// WSA Startup
	//
	WSADATA wsaData = {0};
	AutoWSA autoWSA = ::WSAStartup(MAKEWORD(2,2), &wsaData);
	if (autoWSA.IsInvalid())
	{
		_tprintf(_T("WSAStartup failed with error %d\n"), ::GetLastError());
		return -1;
	}

	//
	// NdasComm initialization
	//
	AutoNdasComm autoNdasComm = ::NdasCommInitialize();
	if (autoNdasComm.IsInvalid())
	{
		_tprintf(_T("Initialization of ndascomm failed with error %d\n"), ::GetLastError());
		return -1;
	}

	if ( (argc > 1) &&
		((*argv[1] == '-') || (*argv[1] == '/')) )
	{
		if ( lstrcmpi( _T("install"), argv[1]+1 ) == 0 )
		{
			// Install the service with current image path
			BOOL success = CNdasService::InstallService();
			if (!success) 
			{
				_tprintf(
					_T("%s (%s) service installed.\n"),
					CNdasService::GetServiceName(),
					CNdasService::GetServiceDisplayName());
			}
			else 
			{
				_tprintf(
					_T("Service install failure (%s (%s)) - Error %d\n"), 
					CNdasService::GetServiceName(),
					CNdasService::GetServiceDisplayName(),
					::GetLastError());
			}
		}
		else if ( lstrcmpi(_T("remove"), argv[1]+1 ) == 0 ||
			lstrcmpi(_T("uninstall"), argv[1]+1) == 0)
		{
			if (CNdasService::RemoveService()) 
			{
				_tprintf(
					_T("%s (%s) service removed successfully.\n"),
					CNdasService::GetServiceName(),
					CNdasService::GetServiceDisplayName());
			}
			else 
			{
				_tprintf(
					_T("Service removal failure (%s (%s)) - Error %d\n"),
					CNdasService::GetServiceName(),
					CNdasService::GetServiceDisplayName(),
					::GetLastError());
			}

		}
		else if ( lstrcmpi( _T("debug"), argv[1]+1 ) == 0 )
		{
			_Module.Init(NULL, NULL);
			int ret = CNdasService::ServiceDebugMain(argc, argv);
			_Module.Term();
			return ret;
		}
	}
	else
	{
		// if it doesn't match any of the above parameters
		// the service control manager may be starting the service
		// so we must call StartServiceCtrlDispatcher
				
		// this is just to be friendly
		_tprintf( _T("%s -install          to install the service\n"), argv[0]);
		_tprintf( _T("%s -remove           to remove the service\n"), argv[0]);
		_tprintf( _T("%s -debug <params>   to run as a console app for debugging\n"), argv[0]);
		_tprintf( _T("\nStartServiceCtrlDispatcher being called.\n"));
		_tprintf( _T("This may take several seconds.  Please wait.\n"));
	
		_Module.Init(NULL, NULL);

		SERVICE_TABLE_ENTRY entry[2] = {0};
		CNdasService::GetServiceTableEntry(&entry[0]);
		if (!::StartServiceCtrlDispatcher(entry))
		{
			_tprintf(
				_T("StartServiceCtrlDispatcher failed - Error %d\n"), 
				::GetLastError());
		}

		_Module.Term();

	}

#ifdef RUN_WPP
	WPP_CLEANUP();
#endif

	NdasUiDbgCall( 1, "*********out**********\n" );

	return 0;
}
int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
                      _In_opt_ HINSTANCE hPrevInstance,
                      _In_ LPWSTR lpCmdLine,
                      _In_ int nCmdShow)
{
	// Attempt to mitigate http://textslashplain.com/2015/12/18/dll-hijacking-just-wont-die
	SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_SYSTEM32);

	int exitCode = -1;
	CString cmdLine(lpCmdLine);

	if (cmdLine.Find(L"--checkInstall") >= 0) {
		// If we're already installed, exit as fast as possible
		if (!MachineInstaller::ShouldSilentInstall()) {
			exitCode = 0;
			goto out;
		}

		// Make sure update.exe gets silent
		wcscat(lpCmdLine, L" --silent");
	}

	HRESULT hr = ::CoInitialize(NULL);
	ATLASSERT(SUCCEEDED(hr));

	AtlInitCommonControls(ICC_COOL_CLASSES | ICC_BAR_CLASSES);
	hr = _Module.Init(NULL, hInstance);

	bool isQuiet = (cmdLine.Find(L"-s") >= 0);
	bool weAreUACElevated = CUpdateRunner::AreWeUACElevated() == S_OK;
	bool explicitMachineInstall = (cmdLine.Find(L"--machine") >= 0);

	if (explicitMachineInstall || weAreUACElevated) {
		exitCode = MachineInstaller::PerformMachineInstallSetup();
		if (exitCode != 0) goto out;
		isQuiet = true;

		// Make sure update.exe gets silent
		if (explicitMachineInstall) {
			wcscat(lpCmdLine, L" --silent");
			printf("Machine-wide installation was successful! Users will see the app once they log out / log in again.\n");
		}
	}

	if (!CFxHelper::CanInstallDotNet4_5()) {
		// Explain this as nicely as possible and give up.
		MessageBox(0L, L"This program cannot run on Windows XP or before; it requires a later version of Windows.", L"Incompatible Operating System", 0);
		exitCode = E_FAIL;
		goto out;
	}

	if (!CFxHelper::IsDotNet45OrHigherInstalled()) {
		hr = CFxHelper::InstallDotNetFramework(isQuiet);
		if (FAILED(hr)) {
			exitCode = hr; // #yolo
			CUpdateRunner::DisplayErrorMessage(CString(L"Failed to install the .NET Framework, try installing .NET 4.5 or higher manually"), NULL);
			goto out;
		}
	
		// S_FALSE isn't failure, but we still shouldn't try to install
		if (hr != S_OK) {
			exitCode = 0;
			goto out;
		}
	}

	// If we're UAC-elevated, we shouldn't be because it will give us permissions
	// problems later. Just silently rerun ourselves.
	if (weAreUACElevated) {
		wchar_t buf[4096];
		HMODULE hMod = GetModuleHandle(NULL);
		GetModuleFileNameW(hMod, buf, 4096);

		CUpdateRunner::ShellExecuteFromExplorer(buf, lpCmdLine);
		exitCode = 0;
		goto out;
	}

	exitCode = CUpdateRunner::ExtractUpdaterAndRun(lpCmdLine, false);

out:
	_Module.Term();
	::CoUninitialize();
	return exitCode;
}
Beispiel #24
0
int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
	UNREFERENCED_PARAMETER(hPrevInstance);
	UNREFERENCED_PARAMETER(lpCmdLine);

 	// TODO: Place code here.
	HRESULT hRes = CoInitialize(NULL);


	//初始化皮肤路径
	WCHAR buffer[MAX_PATH] = {0};
	GetModuleFileName(GetModuleHandle(0), buffer, MAX_PATH);
	PathRemoveFileSpec(buffer);
	CString strSkin;
	strSkin.Format(L"%s\\skin\\default\\",buffer);
	CResourceMgr::SetSkinPath(strSkin);


	//消息循环
	hRes = _Module.Init(NULL, hInstance, &LIBID_ATLLib);
	CMessageLoop theLoop;
	_Module.AddMessageLoop( &theLoop );

	//主窗口
	//CMainWnd wndMain;
	//wndMain.CreateMainWnd();

	//test shadewnd
	CShadeWnd wnd;
	
	CGpImage* pMask = new CGpImage;
	pMask->SetFile(L"shadow.png");
	pMask->SetDrawType(XDRAWTYPE_9PART);
	pMask->SetTileRect(CRect(20,20,850,610));
	wnd.SetMask(pMask);
	wnd.SetMaskMargin(CRect(15,15,15,15));

	wnd.CreateLayerdWnd();
	wnd.ShowWindow(SW_SHOW);
	wnd.CenterWindow();

	CGpImage* pBkg = new CGpImage;
	pBkg->SetFile(L"bar.png");
	pBkg->SetDrawType(XDRAWTYPE_9PART);
	pBkg->SetTileRect(CRect(20,20,50,50));
	wnd.GetRootFrame()->SetBackground(pBkg);



	wnd.SetCalcRgn(FALSE);
	wnd.GetRootFrame()->SetNCHittest(HTCAPTION);


	wnd.UpdateUI();

	//end test

	int nRet = theLoop.Run();

	_Module.RemoveMessageLoop();

	CoUninitialize();

	return nRet;
}
Beispiel #25
0
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int nCmdShow)
{
#ifdef __EXPIRATION__
	// Program Expiration routines
	CTime expirationTime(2010,	// year
		2,					// month
		30,					// date
		23,					// hour 24
		59,					// minute
		59);				// second
	CTime currentTime = CTime::GetCurrentTime();

    CTimeSpan leftTime = expirationTime - currentTime;   

	// 사용 기간이 남았을 경우
	if(leftTime.GetTotalSeconds() > 0)
    {
		 CString msg;
		 msg = L"";
		 msg += L"This is a trial version of BTools2\n";
		 msg += expirationTime.Format(L"Expiration date :\n %Y-%m-%d  %H:%M:%S\n\n");
		 msg += leftTime.Format(L"%D day(s) and\n %H:%M:%S left" );
     
		 // 사용 기간이 3일 미만 남았을 경우
		 if(leftTime.GetDays() < 7)
		 {
			 msg = leftTime.Format(L"This software will expire after %D day(s)");// %H Hour(s) %M Minute(s)");
			 //AtlMessageBox(NULL, msg.GetBuffer(), L"Expiration Warning");
		 }
		 //AfxMessageBox(msg);
    }
    else // 사용 기간이 만료된 경우
    {
		CString msg("This is a trial version of BTools2\n"
				"If you want to use this software more\n"
				"Please contact to me.\[email protected]\n"
				"Thank you for your interest\n");

		msg += expirationTime.Format(L"Expiration date :\n %Y-%m-%d  %H:%M\n\n");
		msg += leftTime.Format(L"%D day(s) and\n %H:%M:%S passed" );
        //msg.Format(L"This software is submitted for the Windows Mobile Contest");
		//AtlMessageBox(NULL, msg.GetBuffer(), L"Warning");
		return FALSE;
	 }

#endif

#ifdef __TSTORE_ARM__0
	// ARM
	T_RETURN ret;
	TAPPID *APPID = TSTORE_APPLICATION_ID;

	bool aSuccess=true;

	T_RETURN res; 
	ARM_PLUGIN_Initialize(&res,APPID);
	if (res.code == ARM_SUCCESS) 
	{
		ARM_PLUGIN_CheckLicense(&res); 
		if (res.code == ARM_SUCCESS) 
		{ 
			ARM_PLUGIN_RequestLicense(&res); 
			if (res.code !=ARM_SUCCESS) 
			{ //실패시 구현 
				aSuccess=false;
				TCHAR wszMsg[1024];
				if(ret.pMsg)
				{
					ansi_to_unicode(ret.pMsg, strlen(ret.pMsg), wszMsg, 1024);
					::AtlMessageBox(NULL, wszMsg, L"[ARM]Request License");
				}
			}
		
		} 
		else 
		{//실패시 메시 구현 
			aSuccess=false;

			TCHAR wszMsg[1024];

			switch(res.code)
			{
			case CLICENSE_DENY:
			case CLICENSE_NOT_EXIST:
			case CLICENSE_EXPIRED:
			case CLICENSE_INVALID:
				{
					if(ret.pMsg)
					{
						ansi_to_unicode(ret.pMsg, strlen(ret.pMsg), wszMsg, 1024);
						::AtlMessageBox(NULL, wszMsg, L"[ARM]Check License");
					}
				}

			default:
				;
			}
		} 
	} 
	else 
	{ 
		aSuccess=false; 
	} 
	ARM_PLUGIN_Uninitialize(&res); 


	//if (! aSuccess) return 0;//PostQuitMessage(0); 

#endif

	//CAboutDlg aboutDlg;	aboutDlg.DoModal();
    //
	HRESULT hRes = CBTools2Frame::ActivatePreviousInstance(hInstance, lpstrCmdLine);

	if(FAILED(hRes) || S_FALSE == hRes)
	{
		return hRes;
	}

	hRes = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
	ATLASSERT(SUCCEEDED(hRes));

	AtlInitCommonControls(ICC_DATE_CLASSES);
	SHInitExtraControls();

	hRes = _Module.Init(NULL, hInstance);
	ATLASSERT(SUCCEEDED(hRes));

	int nRet = CBTools2Frame::AppRun(lpstrCmdLine, nCmdShow);

	_Module.Term();
	::CoUninitialize();

	return nRet;
}
Beispiel #26
0
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int nCmdShow)
{
    g_RunningUnderWine = running_under_wine();
#ifdef PPA_INCLUDE_CHECK_UPDATE
    if (_tcsstr(lpstrCmdLine, _T(PEERS_OPTION_NO_UPDATE)) == NULL) {
        string updatePath = Text::fromT(AutoUpdate::getUpdateTargetPath());
        //TODO нужно еще exists(wstring), чтобы строку не преобразовывать
        if (File::exists(updatePath) && File::getSize(updatePath) > 0) {
            if (AutoUpdate::execute()) {
                return AutoUpdate::EXIT_TO_UPDATE;
            }
        }
    }

    //TODO else вывести сообщение если архив обновления еще есть.
#endif
#ifndef _DEBUG
    SingleInstance dcapp(_T("{DOMODC-AEE8350A-B49A-4753-AB4B-E55479A48351}"));
#else
    SingleInstance dcapp(_T("{DOMODC-AEE8350A-B49A-4753-AB4B-E55479A48350}"));
#endif
    // !SMT!-UI  displaying abort message will disable generating exceptioninfo.txt
    signal(SIGABRT, AbortSignalHandler);
#ifndef SMT_CUSTOM
    _set_abort_behavior(0, _WRITE_ABORT_MSG);
#endif

    bool multipleInstances = false;
    bool magnet = false;
    bool delay = false;

#ifdef _DEBUG
    g_DisableSplash = true;
#endif
    if(_tcsstr(lpstrCmdLine, _T("/nologo"))!=NULL || _tcsstr(lpstrCmdLine, _T("/startup"))!=NULL) {
        g_DisableSplash = true;
        nCmdShow = SW_SHOWMINIMIZED;
    }
    if(_tcsstr(lpstrCmdLine, _T("/wine"))!=NULL)
        g_RunningUnderWine = true;
    if(_tcsstr(lpstrCmdLine, _T("/q"))!=NULL)
        multipleInstances = true;
    if(_tcsstr(lpstrCmdLine, _T("/magnet"))!=NULL)
        magnet = true;
    if(_tcsstr(lpstrCmdLine, _T("/c")) != NULL) {
        multipleInstances = true;
        delay = true;
    }

    if(dcapp.IsAnotherInstanceRunning()) {
        // Allow for more than one instance...
        bool multiple = false;
        if (multipleInstances == false && magnet == false) {
            if (::MessageBox(NULL, _T(APPNAME) _T(" уже запущена, или еще не закончила операцию закрытия...\nВы уверены, что хотите загрузить еще одну копию программы?"),
                             _T(APPNAME) _T(" ") _T(VERSIONSTRING), MB_YESNO | MB_ICONQUESTION | MB_DEFBUTTON2 | MB_TOPMOST) == IDYES) {
                multiple = true;
            }
        } else {
            multiple = true;
        }

        if(delay == true) {
            Thread::sleep(2500);		// let's put this one out for a break
        }

        if(multiple == false || magnet == true) {
            HWND hOther = NULL;
            EnumWindows(searchOtherInstance, (LPARAM)&hOther);

            if (hOther != NULL) {
                // pop up
                ::SetForegroundWindow(hOther);
                //if (IsIconic(hOther)) {
                // ::ShowWindow(hOther, SW_RESTORE); // !SMT!-f - disable, it unlocks password-protected instance
                //}
                sendCmdLine(hOther, lpstrCmdLine);
            }
            return FALSE;
        }
    }

    srand((unsigned) time(NULL));
    // For SHBrowseForFolder, UPnP
    HRESULT hRes = ::CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
    // before next function call
    Util::initialize();
#ifdef _DEBUG
    InitSymInfo(Text::toT(Util::getDataPath()).c_str());
#endif
    LPTOP_LEVEL_EXCEPTION_FILTER pOldSEHFilter = NULL;
    pOldSEHFilter = SetUnhandledExceptionFilter(&DCUnhandledExceptionFilter);

    WSADATA wsaData;
    WSAStartup(MAKEWORD(2, 2), &wsaData);

    AtlInitCommonControls(ICC_COOL_CLASSES | ICC_BAR_CLASSES | ICC_LISTVIEW_CLASSES | ICC_TREEVIEW_CLASSES | ICC_PROGRESS_CLASS | ICC_STANDARD_CLASSES |
                          ICC_TAB_CLASSES | ICC_UPDOWN_CLASS | ICC_USEREX_CLASSES);	// add flags to support other controls

    hRes = _Module.Init(NULL, hInstance);
    ATLASSERT(SUCCEEDED(hRes));

    /* !PPA!
    try {
            File f(WinUtil::getAppName(), File::READ, File::OPEN);
            TigerTree tth(TigerTree::calcBlockSize(f.getSize(), 1));
            size_t n = 0;
            size_t n2 = DEBUG_BUFSIZE;
            while( (n = f.read(buf, n2)) > 0) {
                    tth.update(buf, n);
                    n2 = DEBUG_BUFSIZE;
            }
            tth.finalize();
            strcpy(::tth, tth.getRoot().toBase32().c_str());
            WinUtil::tth = Text::toT(::tth);
    } catch(const FileException&) {
            dcdebug("Failed reading exe\n");
    }
    */

    HINSTANCE hInstRich = ::LoadLibrary(_T("RICHED20.DLL"));

    int nRet = Run(lpstrCmdLine, nCmdShow);

    if ( hInstRich ) {
        ::FreeLibrary(hInstRich);
    }

    // Return back old VS SEH handler
    if (pOldSEHFilter != NULL) {
        SetUnhandledExceptionFilter(pOldSEHFilter);
    }

    _Module.Term();
    ::CoUninitialize();
    ::WSACleanup();
#ifdef _DEBUG
    UninitSymInfo();
#endif
    return nRet;
}
Beispiel #27
0
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int nCmdShow)
{
	HRESULT hRes = ::CoInitialize(NULL);
// If you are running on NT 4.0 or higher you can use the following call instead to 
// make the EXE free threaded. This means that calls come in on a random RPC thread.
//	HRESULT hRes = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
	ATLASSERT(SUCCEEDED(hRes));

#ifdef _DEBUG
	// ATLTRACEで日本語を使うために必要
	_tsetlocale( LC_ALL, _T("japanese") );
#endif

	// this resolves ATL window thunking problem when Microsoft Layer for Unicode (MSLU) is used
	::DefWindowProc(NULL, 0, 0, 0L);

	AtlInitCommonControls(ICC_BAR_CLASSES);	// add flags to support other controls

    // リッチエディットコントロール初期化
    HINSTANCE hRich = LoadLibrary(CRichEditCtrl::GetLibraryName());
    if(hRich == NULL){
        AtlMessageBox(NULL, _T("リッチエディットコントロール初期化失敗"),
            _T("エラー"), MB_OK | MB_ICONERROR);
        return 0;
    }

	hRes = _Module.Init(NULL, hInstance);
	ATLASSERT(SUCCEEDED(hRes));
	
	int nRet = 0;
	try {

		CVersionControl::Run();

		CSettings::LoadSettings();

		CSocket::Init();

		WinHTTPWrapper::InitWinHTTP();

		CSettings::s_SSLFilter = InitSSL();

		nRet = Run(lpstrCmdLine, nCmdShow);

		if (CSettings::s_SSLFilter)
			TermSSL();

		WinHTTPWrapper::TermWinHTTP();

		CSocket::Term();

		CSettings::SaveSettings();
	}
	catch (std::exception& e) {
		ERROR_LOG << e.what();
	}

	FreeLibrary(hRich);

	_Module.Term();
	::CoUninitialize();

	return nRet;
}
Beispiel #28
0
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int nCmdShow)
{
	HRESULT hRes = ::CoInitialize(NULL);
// If you are running on NT 4.0 or higher you can use the following call instead to 
// make the EXE free threaded. This means that calls come in on a random RPC thread.
//	HRESULT hRes = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
	ATLASSERT(SUCCEEDED(hRes));

  // Install crash reporting
#ifdef TEST_DEPRECATED_FUNCS

  g_pCrashRptState = Install(
    CrashCallback, 
    _T("*****@*****.**"), 
    _T("Crash"));

#else

  CString szSubject;
  szSubject.Format(_T("%s %s Error Report"), APP_NAME, APP_VERSION);

  CR_INSTALL_INFO info;
  memset(&info, 0, sizeof(CR_INSTALL_INFO));
  info.cb = sizeof(CR_INSTALL_INFO);  
  info.pszAppName = APP_NAME;
  info.pszAppVersion = APP_VERSION;
  info.pszEmailSubject = szSubject;
  info.pszEmailTo = _T("*****@*****.**");    
  info.pfnCrashCallback = CrashCallback;    
  info.uPriorities[CR_SMTP] = 1;
  info.uPriorities[CR_SMAPI] = 0;  
    
  int nInstResult = crInstall(&info);
  ATLASSERT(nInstResult==0);
  nInstResult;

#endif //TEST_DEPRECATED_FUNCS

  /* Create another thread */
  g_CrashThreadInfo.m_pCrashRptState = g_pCrashRptState;
  g_CrashThreadInfo.m_bStop = false;
  g_CrashThreadInfo.m_hWakeUpEvent = CreateEvent(NULL, FALSE, FALSE, _T("WakeUpEvent"));
  ATLASSERT(g_CrashThreadInfo.m_hWakeUpEvent!=NULL);

  DWORD dwThreadId = 0;
  g_hWorkingThread = CreateThread(NULL, 0, CrashThread, (LPVOID)&g_CrashThreadInfo, 0, &dwThreadId);
  ATLASSERT(g_hWorkingThread!=NULL);

	// this resolves ATL window thunking problem when Microsoft Layer for Unicode (MSLU) is used
	::DefWindowProc(NULL, 0, 0, 0L);

	AtlInitCommonControls(ICC_BAR_CLASSES);	// add flags to support other controls

	hRes = _Module.Init(NULL, hInstance);
	ATLASSERT(SUCCEEDED(hRes));

	int nRet = Run(lpstrCmdLine, nCmdShow);

	_Module.Term();

  // Close another thread
  g_CrashThreadInfo.m_bStop = true;
  SetEvent(g_CrashThreadInfo.m_hWakeUpEvent);
  // Wait until thread terminates
  WaitForSingleObject(g_hWorkingThread, INFINITE);

  // Uninstall crash reporting
  
#ifdef TEST_DEPRECATED_FUNCS

  Uninstall(g_pCrashRptState);

#else
  
  int nUninstResult = crUninstall();
  ATLASSERT(nUninstResult==0);
  nUninstResult;

#endif //TEST_DEPRECATED_FUNCS

	::CoUninitialize();

	return nRet;
}
Beispiel #29
0
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int nCmdShow)
{
    HRESULT hRes = ::CoInitialize(NULL);
// If you are running on NT 4.0 or higher you can use the following call instead to
// make the EXE free threaded. This means that calls come in on a random RPC thread.
//	HRESULT hRes = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
    ATLASSERT(SUCCEEDED(hRes));

    // this resolves ATL window thunking problem when Microsoft Layer for Unicode (MSLU) is used
    ::DefWindowProc(NULL, 0, 0, 0L);

    AtlInitCommonControls(ICC_BAR_CLASSES);	// add flags to support other controls

    hRes = _Module.Init(NULL, hInstance);
    ATLASSERT(SUCCEEDED(hRes));

    int nRet = 0;//Run(lpstrCmdLine, nCmdShow);

    CString ProgramFile;
    CString lpszArgument(lpstrCmdLine);

    TCHAR szFilePath[MAX_URI], szIniPath[MAX_URI];
    GetModuleFileName(NULL, szFilePath, MAX_URI);
    (_tcsrchr(szFilePath, _T('\\')))[1] = 0;

    _tcsncpy_s(szIniPath, MAX_URI, szFilePath, MAX_URI);
    _tcsncat_s(szIniPath, MAX_URI, _T("mloader.ini"), MAX_URI);

    TCHAR *mainpath = _tcsstr(szFilePath, _T("\\codecs\\Real"));
    if(mainpath) mainpath[1] = 0;
    _tcsncat_s(szFilePath, MAX_URI, _T("mplayer.exe"), MAX_URI);

    ProgramFile = szFilePath;

    if(IsFileExist(szIniPath)) {
        TCHAR temp[MAX_URI];
        GetPrivateProfileString(_T("Command"), _T("Program_Path"), _T(""), temp, MAX_URI, szIniPath);
        if(_tcslen(temp) > 3) ProgramFile = temp;
    }

    int index = lpszArgument.Find(_T("/command:Screensize(full)"));
    if(index >= 0)
        lpszArgument.Delete(index, _tcslen(_T("/command:Screensize(full)")));

    index = lpszArgument.Find(_T("\""));
    if(index >= 0) {
        int len = lpszArgument.Find(_T("\""), index+1);
        if(len > index) {
            CString url = lpszArgument.Mid(index+1, len-index-1);
            if(url.Find(_T("http://")) >= 0) {
                std::string surl;
                if(GetRealURL(url.GetBuffer(), 4096, surl))
                    url = surl.c_str();
                if(url.Find(_T("rtsp://")) >= 0)
                    lpszArgument = _T("\"") + url + _T("\"");
            }
        }
    }

    ShellExecute(0, _T("open"), ProgramFile,  lpszArgument, NULL, SW_SHOW);

    _Module.Term();
    ::CoUninitialize();

    return nRet;
}
Beispiel #30
0
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int nCmdShow) {
#ifndef _DEBUG
	SingleInstance dcapp(_T("{AIRDC-AEE8350A-B49A-4753-AB4B-E55479A48351}"));
#else
	SingleInstance dcapp(_T("{AIRDC-AEE8350A-B49A-4753-AB4B-E55479A48350}"));
#endif

	if(dcapp.IsAnotherInstanceRunning()) {
		// Allow for more than one instance...
				bool multiple = false;
		if(_tcslen(lpstrCmdLine) == 0) {
			if (::MessageBox(NULL, _T("There is already an instance of AirDC++ running.\nDo you want to launch another instance anyway?"), 
				_T(APPNAME) _T(" ") _T(VERSIONSTRING), MB_YESNO | MB_ICONQUESTION | MB_DEFBUTTON2 | MB_TOPMOST) == IDYES) {
					multiple = true;
			}
		}

		if(multiple == false) {
			HWND hOther = NULL;
			EnumWindows(searchOtherInstance, (LPARAM)&hOther);

			if( hOther != NULL ) {
				// pop up
				::SetForegroundWindow(hOther);

				if( IsIconic(hOther)) {
					// restore
					::ShowWindow(hOther, SW_RESTORE);
				}
				sendCmdLine(hOther, lpstrCmdLine);
			}
			return FALSE;
		}
	}
	
	
	// For SHBrowseForFolder, UPnP_COM
	HRESULT hRes = ::CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); 
#ifdef _DEBUG
	EXTENDEDTRACEINITIALIZE(Util::getPath(Util::PATH_RESOURCES).c_str());
#endif
	LPTOP_LEVEL_EXCEPTION_FILTER pOldSEHFilter = NULL;
	pOldSEHFilter = SetUnhandledExceptionFilter(&DCUnhandledExceptionFilter);
	
	AtlInitCommonControls(ICC_COOL_CLASSES | ICC_BAR_CLASSES | ICC_LISTVIEW_CLASSES | ICC_TREEVIEW_CLASSES | ICC_PROGRESS_CLASS | ICC_STANDARD_CLASSES |
		ICC_TAB_CLASSES | ICC_UPDOWN_CLASS | ICC_USEREX_CLASSES);	// add flags to support other controls
	
	hRes = _Module.Init(NULL, hInstance);
	ATLASSERT(SUCCEEDED(hRes));
	
	try {		
		File f(WinUtil::getAppName(), File::READ, File::OPEN);
		TigerTree tth(TigerTree::calcBlockSize(f.getSize(), 1));
		size_t n = 0;
		size_t n2 = DEBUG_BUFSIZE;
		while( (n = f.read(buf, n2)) > 0) {
			tth.update(buf, n);
			n2 = DEBUG_BUFSIZE;
		}
		tth.finalize();
		strcpy(::tth, tth.getRoot().toBase32().c_str());
		WinUtil::tth = Text::toT(::tth);
	} catch(const FileException&) {
		dcdebug("Failed reading exe\n");
	}	

	HINSTANCE hInstRich = ::LoadLibrary(_T("MSFTEDIT.DLL"));
	if (hInstRich == NULL) {
		MessageBox(NULL, _T("AirDC++ isn't supported in operating systems older than Microsoft Windows XP3"), _T(APPNAME) _T(" ") _T(VERSIONSTRING), MB_OK | MB_ICONEXCLAMATION);
		return FALSE;
	}

	int nRet = Run(lpstrCmdLine, nCmdShow);
 
	if ( hInstRich ) {
		::FreeLibrary(hInstRich);
	}
	
	// Return back old VS SEH handler
	if (pOldSEHFilter != NULL)
		SetUnhandledExceptionFilter(pOldSEHFilter);

	_Module.Term();
	::CoUninitialize();

#ifdef _DEBUG
	EXTENDEDTRACEUNINITIALIZE();
#endif

	return nRet;
}