int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPSTR lpCmdLine, int nCmdShow) { ModelLoader* modelLoader; bool screenSaver = isScreenSaver(); int retValue; STARTUPINFO startupInfo; bool fromConsole = false; //HMODULE hThumbs = LoadLibrary("LDViewThumbs.dll"); //if (hThumbs != NULL) //{ // PFNDLLREGISTERSERVER pDllRegisterServer = // (PFNDLLREGISTERSERVER)GetProcAddress(hThumbs, "DllRegisterServer"); // CoInitialize(NULL); // if (pDllRegisterServer != NULL) // { // pDllRegisterServer(); // } //} memset(&startupInfo, 0, sizeof(startupInfo)); startupInfo.cb = sizeof(startupInfo); GetStartupInfo(&startupInfo); if (startupInfo.lpTitle != NULL && stringHasCaseInsensitivePrefix(startupInfo.lpTitle, "command line ") && strcasestr(startupInfo.lpTitle, "ldview") != NULL) { runningWithConsole(); fromConsole = true; } #ifdef _DEBUG int _debugFlag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG); _debugFlag |= _CRTDBG_LEAK_CHECK_DF; _CrtSetDbgFlag(_debugFlag); _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_DEBUG); if (!fromConsole) { createConsole(); } // MessageBox(NULL, "Attach a debugger now...", "Debug", MB_OK); #endif // _DEBUG bool udok = setupUserDefaults(lpCmdLine, screenSaver, isRemovableDrive(hInstance)); setupLocalStrings(); if (TCUserDefaults::boolForKey(DEBUG_COMMAND_LINE_KEY, false, false)) { std::string message = "Command Line:\n"; message += lpCmdLine; MessageBox(NULL, message.c_str(), "LDView", MB_OK); } if (!udok && !TCUserDefaults::longForKey("IniFailureShown", 0, 0)) { UCCHAR message[2048]; UCSTR iniPath = mbstoucstring(TCUserDefaults::getIniPath()); sucprintf(message, COUNT_OF(message), TCLocalStrings::get(_UC("IniFailure")), iniPath); CUIWindow::messageBoxUC(NULL, message, _UC("LDView"), MB_OK); delete iniPath; TCUserDefaults::setLongForKey(1, "IniFailureShown", false); } if (screenSaver) { if (strncasecmp(lpCmdLine, "/p", 2) == 0 || strncasecmp(lpCmdLine, "-p", 2) == 0 || strncasecmp(lpCmdLine, "p", 1) == 0) { // preview mode return doPreview(hInstance, lpCmdLine); } if (strncasecmp(lpCmdLine, "/c", 2) == 0 || strncasecmp(lpCmdLine, "-c", 2) == 0 || strncasecmp(lpCmdLine, "c", 1) == 0 || strlen(lpCmdLine) == 0) { SSConfigure *configure; configure = new SSConfigure(hInstance); #ifdef _DEBUG _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_DEBUG); createConsole(); #endif // _DEBUG configure->run(); // configure mode return 1; } // This shouldn't be necessary, but I've received a report of a whole // bunch of copies of the LDView screensaver running at once. This // might not fix things entirely, but it will at least prevent it // from launching multiple times concurrently. CreateMutex(NULL, FALSE, "LDView Screensaver"); if (GetLastError() == ERROR_ALREADY_EXISTS) { return 0; } } #ifdef _LOG_PERFORMANCE LARGE_INTEGER frequency; if (QueryPerformanceFrequency(&frequency)) { debugPrintf("Frequency: %I64d\n", frequency.QuadPart); } #endif // _LOG_PERFORMANCE OleInitialize(NULL); //Win7JumpListStuff(); modelLoader = new ModelLoader(CUIWindow::getLanguageModule(), nCmdShow, screenSaver); retValue = mainLoop(); modelLoader->release(); return retValue; } // WinMain