Ejemplo n.º 1
0
int main(int argc,char *argv[])
{
	if (!AfxWinInit(::GetModuleHandle(NULL),NULL,::GetCommandLine(),0))
	{
		cerr << "Can't initialise MFC !" << endl;
		return -1;
	}

	service serv(argv[0]);

	int ret;
	if ((ret = serv.options(argc,argv)) <= 0)
		return ret;

	serv.run(argc,argv);

	return 0;
}
Ejemplo n.º 2
0
int WINAPI _tWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine,
                      int nCmdShow )
/**********************************/
{
    if( !AfxWinInit( hInstance, hPrevInstance, lpCmdLine, nCmdShow ) ) {
        return( -1 );
    }
    AfxInitThread();
    
    CWinApp *pApp = AfxGetApp();
    ASSERT( pApp != NULL );
    int nExitCode;
    if( !pApp->InitInstance() ) {
        nExitCode = -1;
    } else {
        nExitCode = pApp->Run();
    }
    AfxTermThread( hInstance );
    return( nExitCode );
}
Ejemplo n.º 3
0
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
	int nRetCode = 0;	

	// initialize MFC and print and error on failure
	if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0) || ::OleInitialize(NULL) != S_OK)
	{
		// TODO: change error code to suit your needs
		_tprintf(_T("Fatal Error: MFC or COM initialization failed\n"));
		nRetCode = 1;
	}
	else
	{
		PrintBanner();
		ValidateIISSetup();
		ValidateIISxpressFiles();
	}

	::OleUninitialize();

	return nRetCode;
}
Ejemplo n.º 4
0
/*
 *	函数介绍:程序入口函数  
 *  输入参数:argv[1]为-install是安装服务,-remove时删除服务,argv[2]安装时为服务控制台显示服务名称
    删除时为注册服务名称,此程序为AlertService
 *  输出参数:无
 *  返回值:
 */
int _tmain(int argc, _TCHAR* argv[])
{
	int nRetCode = 0;
	if(WriteIniFileString("testsection","testkey","testvalue","alert.ini"))
	{
		DeleteIniFileSection("testsection","alert.ini");
	}
	if(WriteIniFileString("testsection","testkey","testvalue","TxtTemplate.ini"))
	{
		DeleteIniFileSection("testsection","TxtTemplate.ini");
	}
	if(WriteIniFileString("testsection","testkey","testvalue","smsconfig.ini"))
	{
		DeleteIniFileSection("testsection","smsconfig.ini");
	}
	if(WriteIniFileString("testsection","testkey","testvalue","general.ini"))
	{
		DeleteIniFileSection("testsection","general.ini");
	}
	if(WriteIniFileString("testsection","testkey","testvalue","itsmConfig.ini"))
	{
		DeleteIniFileSection("testsection","itsmConfig.ini");
	}
	if(WriteIniFileString("testsection","testkey","testvalue","watchsheetcfg.ini"))
	{
		DeleteIniFileSection("testsection","watchsheetcfg.ini");
	}
	if(WriteIniFileString("testsection","testkey","testvalue","email.ini"))
	{
		DeleteIniFileSection("testsection","email.ini");
	}
	if(WriteIniFileString("testsection","testkey","testvalue","emailAdress.ini"))
	{
		DeleteIniFileSection("testsection","emailAdress.ini");
	}
	if(WriteIniFileString("testsection","testkey","testvalue","smsphoneset.ini"))
	{
		DeleteIniFileSection("testsection","smsphoneset.ini");
	}
	if(WriteIniFileString("testsection","testkey","testvalue","interfacedll.ini"))
	{
		DeleteIniFileSection("testsection","interfacedll.ini");
	}
	if(WriteIniFileString("testsection","testkey","testvalue","OfbizConfig.ini"))
	{
		DeleteIniFileSection("testsection","OfbizConfig.ini");
	}

#if 1
    try
	{
		if(hasrun())
			return 0;

		CAlertMain alertmain;
		
		alertmain.Init();
		
		//MSG msg;
		//BOOL bRet=TRUE;
		//while((bRet=::GetMessage(&msg,NULL,0,0))!=0)
		//{
		//	if(bRet==-1)
		//	{
		//		continue;
		//	}

		//	TranslateMessage(&msg);
		//	::DispatchMessage(&msg);
		//}
		MSG msg;
		while(::GetMessage(&msg,NULL,0,0))
		{
			TranslateMessage(&msg);
			::DispatchMessage(&msg);
			switch(msg.message)
			{
				case WM_QUIT:
					exit(1);
					break;
				default:
					break;
			}
		}
	}
	catch(...)
	{
	}
#else
//   argc = 2;
//	argv[1] = "-remove";
//	argv[2] = "AlertService";
//#if 1
//    RunThread(NULL);
//#else

	// initialize MFC and print and error on failure
	if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
	{
		// TODO: change error code to suit your needs
		cerr << _T("Fatal Error: MFC initialization failed") << endl;
		nRetCode = 1;
	}

	g_strRootPath= FuncGetInstallRootPath();
	SERVICE_TABLE_ENTRY Table[] = 
	{
		{"AlertService7",StartAlertService},
		{NULL,        NULL}
	};
	CString outStr = "parameter required in the command line";
	if(argc <= 1)
	{
		
		cout << (LPCTSTR)outStr << endl;
	}
	else
	{
		if(_stricmp(argv[1],"-install") == 0)
		{
			InstallService(argv[2]);
		}
		else if(_stricmp(argv[1],"-remove") == 0)
		{
			StopService(argv[2]);
		}
		else
		{
			cout << outStr << endl;
		}
	}



	if(!StartServiceCtrlDispatcher(Table))
    { 
		g_strMessage.Format("StartServiceCtrlDispatcher error = %d\r\n", GetLastError());
		WriteLogFile(g_strMessage);
    } 	
#endif
	//CAlertMain::pSender.Release();
	return nRetCode;
}
Ejemplo n.º 5
0
int main(int argc, char* argv[])
{
	ShowBanner();

	if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
	{
		cerr << _T("MFC Failed to initialize.\n");
		return 1;
	}

	if (argc < 2 || !ParseOptions(argc, argv) || pszURL == NULL)
		ShowUsage();

	int nRetCode = 0;

	CTearSession session(_T("TEAR - MFC Sample App"), dwAccessType);
	CHttpConnection* pServer = NULL;
	CHttpFile* pFile = NULL;
	try
	{
		// check to see if this is a reasonable URL

		CString strServerName;
		CString strObject;
		INTERNET_PORT nPort;
		DWORD dwServiceType;

		if (!AfxParseURL(pszURL, dwServiceType, strServerName, strObject, nPort) ||
			dwServiceType != INTERNET_SERVICE_HTTP)
		{
			cerr << _T("Error: can only use URLs beginning with http://") << endl;
			ThrowTearException(1);
		}

		if (bProgressMode)
		{
			cerr << _T("Opening Internet...");
			VERIFY(session.EnableStatusCallback(TRUE));
		}

		pServer = session.GetHttpConnection(strServerName, nPort);

		pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_GET,
			strObject, NULL, 1, NULL, NULL, dwHttpRequestFlags);
		pFile->AddRequestHeaders(szHeaders);
		pFile->SendRequest();

		DWORD dwRet;
		pFile->QueryInfoStatusCode(dwRet);

		// if access was denied, prompt the user for the password

		if (dwRet == HTTP_STATUS_DENIED)
		{
			DWORD dwPrompt;
			dwPrompt = pFile->ErrorDlg(NULL, ERROR_INTERNET_INCORRECT_PASSWORD,
				FLAGS_ERROR_UI_FLAGS_GENERATE_DATA | FLAGS_ERROR_UI_FLAGS_CHANGE_OPTIONS, NULL);

			// if the user cancelled the dialog, bail out

			if (dwPrompt != ERROR_INTERNET_FORCE_RETRY)
			{
				cerr << _T("Access denied: Invalid password\n");
				ThrowTearException(1);
			}

			pFile->SendRequest();
			pFile->QueryInfoStatusCode(dwRet);
		}

		CString strNewLocation;
		pFile->QueryInfo(HTTP_QUERY_RAW_HEADERS_CRLF, strNewLocation);

		// were we redirected?
		// these response status codes come from WININET.H

		if (dwRet == HTTP_STATUS_MOVED ||
			dwRet == HTTP_STATUS_REDIRECT ||
			dwRet == HTTP_STATUS_REDIRECT_METHOD)
		{
			CString strNewLocation;
			pFile->QueryInfo(HTTP_QUERY_RAW_HEADERS_CRLF, strNewLocation);

			int nPlace = strNewLocation.Find(_T("Location: "));
			if (nPlace == -1)
			{
				cerr << _T("Error: Site redirects with no new location") << endl;
				ThrowTearException(2);
			}

			strNewLocation = strNewLocation.Mid(nPlace + 10);
			nPlace = strNewLocation.Find('\n');
			if (nPlace > 0)
				strNewLocation = strNewLocation.Left(nPlace);

			// close up the redirected site

			pFile->Close();
			delete pFile;
			pServer->Close();
			delete pServer;

			if (bProgressMode)
			{
				cerr << _T("Caution: redirected to ");
				cerr << (LPCTSTR) strNewLocation << endl;
			}

			// figure out what the old place was
			if (!AfxParseURL(strNewLocation, dwServiceType, strServerName, strObject, nPort))
			{
				cerr << _T("Error: the redirected URL could not be parsed.") << endl;
				ThrowTearException(2);
			}

			if (dwServiceType != INTERNET_SERVICE_HTTP)
			{
				cerr << _T("Error: the redirected URL does not reference a HTTP resource.") << endl;
				ThrowTearException(2);
			}

			// try again at the new location
			pServer = session.GetHttpConnection(strServerName, nPort);
			pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_GET,
				strObject, NULL, 1, NULL, NULL, dwHttpRequestFlags);
			pFile->AddRequestHeaders(szHeaders);
			pFile->SendRequest();

			pFile->QueryInfoStatusCode(dwRet);
			if (dwRet != HTTP_STATUS_OK)
			{
				cerr << _T("Error: Got status code ") << dwRet << endl;
				ThrowTearException(2);
			}
		}

		cerr << _T("Status Code is ") << dwRet << endl;

		TCHAR sz[1024];
		while (pFile->ReadString(sz, 1023))
		{
			if (bStripMode)
				StripTags(sz);
			cout << sz;
		}

	// NOTE: Since HTTP servers normally spit back plain text, the
	// above code (which reads line by line) is just fine.  However,
	// other data sources (eg, FTP servers) might provide binary data
	// which should be handled a buffer at a time, like this:

#if 0
		while (nRead > 0)
		{
			sz[nRead] = '\0';
			if (bStripMode)
				StripTags(sz);
			cout << sz;
			nRead = pFile->Read(sz, 1023);
		}
#endif

		pFile->Close();
		pServer->Close();
	}
	catch (CInternetException* pEx)
	{
		// catch errors from WinINet

		TCHAR szErr[1024];
		pEx->GetErrorMessage(szErr, 1024);

		cerr << _T("Error: (") << pEx->m_dwError << _T(") ");
		cerr << szErr << endl;

		nRetCode = 2;
		pEx->Delete();
	}
	catch (CTearException* pEx)
	{
		// catch things wrong with parameters, etc

		nRetCode = pEx->m_nErrorCode;
		TRACE1("Error: Exiting with CTearException(%d)\n", nRetCode);
		pEx->Delete();
	}

	if (pFile != NULL)
		delete pFile;
	if (pServer != NULL)
		delete pServer;
	session.Close();

	return nRetCode;
}
Ejemplo n.º 6
0
// Our main test program
int 
main(int argc,TCHAR* argv[], TCHAR* /*envp[]*/)
{
  int nRetCode = 0;

  HMODULE hModule = ::GetModuleHandle(NULL);
  InitializeCriticalSection(&std_stream);

  if(hModule == NULL)
  {
    _tprintf(_T("Fatal Error: GetModuleHandle failed\n"));
    nRetCode = 1;
  }
  else
  {
    // initialize MFC and print and error on failure
    if (!AfxWinInit(hModule, NULL, ::GetCommandLine(), 0))
    {
      _tprintf(_T("Fatal Error: MFC initialization failed\n"));
      nRetCode = 1;
    }
    else
    {
      printf("TESTPROGAM: MARLIN SERVER\n");
      printf("=========================\n");
      printf("\n");
      printf("Version string: %s\n",MARLIN_SERVER_VERSION);
      printf("----------------------------------\n");
      printf("\n");

      // See if we must do the standalone WebServiceServer test
      // Or that we should do the flat HTTPServer tests
      if(argc >= 2)
      {
        if(_stricmp(argv[1],"/ws") == 0)
        {
          CString contract = "http://interface.marlin.org/testing/";
          printf("WebServiceServer test for \"%s\"\n",contract.GetString());
          printf("----------------------------------------------------------------\n");
          printf("\n");

          // Test the Interface
          nRetCode = TestWebServiceServer(NULL,contract,logLevel);
        }
      }
      else
      {
        HTTPServer*   server  = nullptr;
        LogAnalysis*  logfile = nullptr;

        if(StartServer(server,logfile))
        {
          // Fire up all of our test sites
          int errors = 0;

          // Individual tests
          errors += Test_CrackURL();
          errors += Test_HTTPTime();
          errors += TestThreadPool(server->GetThreadPool());

          // HTTP tests
          errors += TestBaseSite(server);
          errors += TestSecureSite(server);
          errors += TestClientCertificate(server,true);
          errors += TestCookies(server);
          errors += TestFormData(server);
          errors += TestJsonData(server);
          errors += TestInsecure(server);
          errors += TestPushEvents(server);
          errors += TestBodySigning(server);
          errors += TestBodyEncryption(server);
          errors += TestMessageEncryption(server);
          errors += TestReliable(server);
          errors += TestReliableBA(server);
          errors += TestToken(server);
          errors += TestSubSites(server);
          errors += TestFilter(server);
          errors += TestPatch(server);
          errors += TestCompression(server);
          errors += TestAsynchrone(server);
          errors += TestWebSocket(server);

         // Test the WebServiceServer program generation
         CString contract = "http://interface.marlin.org/testing/";
         errors += TestJsonServer(server,contract,logLevel);
         errors += TestWebServiceServer(server,contract,logLevel);

          // See if we should wait for testing to occur
          if(errors)
          {
            printf("\n"
                   "SERVER (OR PROGRAMMING) IN ERROR STATE!!\n"
                   "%d sites not correctly started\n"
                   "\n",errors);
          }
          else
          {
            printf("\n"
                   "Server running....\n"
                   "Waiting to be called by test clients...\n"
                   "\n");
            // Wait for key to occur
            WaitForKey();
          }

          // Try to stop the WebSocket
//           errors += StopWebSocket();
// 
          // Try to stop the subsites
          errors += StopSubsites(server);

          // Testing the errorlog function
          server->ErrorLog(__FUNCTION__,5,"Not a real error message, but a test to see if it works :-)");

          printf("Stopping the server\n");
          server->StopServer();

          // See if the server is indeed in stopped state
          printf("The server is %s\n",server->GetIsRunning() ? "still running!\n" : "stopped.\n");

          // Remember for a cmd shell
          nRetCode = errors;
        }
        else
        {
          totalErrors = 1;
          printf("HTTPServer in error state in : Error %lu: %s\n"
                 ,server->GetLastError()
                 ,(LPCTSTR)GetLastErrorAsString(GetLastError()));
        }
        CleanupServer(server,logfile);
      }
    }
    printf("\n");
    printf("SUMMARY OF ALL SERVER TESTS\n");
    printf("===========================\n");
    if(totalErrors)
    {
      printf("ERRORS: %d\n",nRetCode += totalErrors);
    }
    else
    {
      printf("ALL OK !!!! YIPEEEE!!!!\n");
    }
    WaitForKey();
    WaitForKey();
  }
  DeleteCriticalSection(&std_stream);

  return nRetCode;
}
Ejemplo n.º 7
0
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID)
{
	if (dwReason == DLL_PROCESS_ATTACH)
	{
#ifdef _AFX_OLE_IMPL
		BOOL bRegister = !coreDLL.bInitialized;

		// shared initialization
		AFX_MODULE_STATE* pModuleState = _AfxGetOleModuleState();
		pModuleState->m_hCurrentInstanceHandle = hInstance;
		pModuleState->m_hCurrentResourceHandle = hInstance;
		pModuleState->m_pClassInit = pModuleState->m_classList.GetHead();
		pModuleState->m_pFactoryInit = pModuleState->m_factoryList.GetHead();
#endif

		// initialize this DLL's extension module
		VERIFY(AfxInitExtensionModule(coreDLL, hInstance));

#ifdef _AFX_OLE_IMPL
		AfxWinInit(hInstance, NULL, &afxChNil, 0);

		// Register class factories in context of private module state
		if (bRegister)
			COleObjectFactory::RegisterAll();
#endif

#ifdef _AFX_OLE_IMPL
		// restore previously-saved module state
		VERIFY(AfxSetModuleState(AfxGetThreadState()->m_pPrevModuleState) ==
			_AfxGetOleModuleState());
		DEBUG_ONLY(AfxGetThreadState()->m_pPrevModuleState = NULL);
#endif

		// wire up this DLL into the resource chain
		CDynLinkLibrary* pDLL = new CDynLinkLibrary(coreDLL, TRUE);
		ASSERT(pDLL != NULL);
		pDLL->m_factoryList.m_pHead = NULL;

		// load language specific DLL
		// the DLL must be in the "system directory"
		static const char szPrefix[] = "\\MFC42";
		static const char szLOC[] = "LOC";
		static const char szDLL[] = ".DLL";
		char szLangDLL[_MAX_PATH+14]; // Note: 8.3 name
		GetSystemDirectoryA(szLangDLL, _countof(szLangDLL));
		lstrcatA(szLangDLL, szPrefix);

		// try MFC42LOC.DLL
		lstrcatA(szLangDLL, szLOC);
		lstrcatA(szLangDLL, szDLL);
		HINSTANCE hLangDLL = LoadLibraryA(szLangDLL);
		AFX_MODULE_STATE* pState = AfxGetModuleState();
		pState->m_appLangDLL = hLangDLL;

#ifdef _AFX_OLE_IMPL
		// copy it to the private OLE state too
		pModuleState->m_appLangDLL = hLangDLL;
#endif
	}
	else if (dwReason == DLL_PROCESS_DETACH)
	{
		// free language specific DLL
		AFX_MODULE_STATE* pState = AfxGetModuleState();
		if (pState->m_appLangDLL != NULL)
		{
			::FreeLibrary(pState->m_appLangDLL);
			pState->m_appLangDLL = NULL;
		}

		// free the DLL info blocks
		CDynLinkLibrary* pDLL;
		while ((pDLL = pState->m_libraryList) != NULL)
			delete pDLL;
		ASSERT(pState->m_libraryList.IsEmpty());

		// cleanup module state for this process
		AfxTermExtensionModule(coreDLL);

#ifdef _AFX_OLE_IMPL
		// set module state for cleanup
		ASSERT(AfxGetThreadState()->m_pPrevModuleState == NULL);
		AfxGetThreadState()->m_pPrevModuleState =
			AfxSetModuleState(_AfxGetOleModuleState());
#endif

		// cleanup module state in OLE private module state
		AfxTermExtensionModule(coreDLL, TRUE);

		// free any local data for this process/thread
		AfxTermLocalData(NULL, TRUE);
	}
	else if (dwReason == DLL_THREAD_DETACH)
	{
		AfxTermThread();
	}

	return TRUE;    // ok
}
BOOL CMFCOpenGLApp::InitInstance()
{
	// 如果一个运行在 Windows XP 上的应用程序清单指定要
	// 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式,
	//则需要 InitCommonControlsEx()。否则,将无法创建窗口。
	INITCOMMONCONTROLSEX InitCtrls;
	InitCtrls.dwSize = sizeof(InitCtrls);
	// 将它设置为包括所有要在应用程序中使用的
	// 公共控件类。
	InitCtrls.dwICC = ICC_WIN95_CLASSES;
	InitCommonControlsEx(&InitCtrls);

	CWinApp::InitInstance();


	AfxEnableControlContainer();

	// 创建 shell 管理器,以防对话框包含
	// 任何 shell 树视图控件或 shell 列表视图控件。
	CShellManager *pShellManager = new CShellManager;

	// 标准初始化
	// 如果未使用这些功能并希望减小
	// 最终可执行文件的大小,则应移除下列
	// 不需要的特定初始化例程
	// 更改用于存储设置的注册表项
	// TODO: 应适当修改该字符串,
	// 例如修改为公司或组织名
	//SetRegistryKey(_T("UIC Music Visulization"));

	//!!!!MFC初始化
	if(!AfxWinInit(::GetModuleHandle(NULL),NULL,::GetCommandLine(),0))
   {
     //??_Module.LogEvent(_T("MFC初始化错误!"), EVENTLOG_ERROR_TYPE );
     return 1;
   }

	CMFCOpenGLDlg dlg;
	m_pMainWnd = &dlg;
	INT_PTR nResponse = dlg.DoModal();
	if (nResponse == IDOK)
	{
		// TODO: 在此放置处理何时用
		//  “确定”来关闭对话框的代码
	}
	else if (nResponse == IDCANCEL)
	{
		// TODO: 在此放置处理何时用
		//  “取消”来关闭对话框的代码
	}

	// 删除上面创建的 shell 管理器。
	if (pShellManager != NULL)
	{
		delete pShellManager;
	}

	// 由于对话框已关闭,所以将返回 FALSE 以便退出应用程序,
	//  而不是启动应用程序的消息泵。
	return FALSE;
}
Ejemplo n.º 9
0
int AFXAPI AfxWinMain(HINSTANCE hInstance, 
					  HINSTANCE hPrevInstance,	
					  LPTSTR lpCmdLine, 
					  int nCmdShow)
{
	char szLogFileName[_MAX_DIR];
	if (GetRecommandLogFileName(szLogFileName) == false) 
		return FALSE;

	InitLog(MLOGSTYLE_DEBUGSTRING|MLOGSTYLE_FILE, szLogFileName);

	// Wrap WinMain in a structured exception handler (different from C++
	// exception handling) in order to make sure that all access violations
	// and other exceptions are displayed - regardless of when they happen.
	// This should be done for each thread, if at all possible, so that exceptions
	// will be reliably caught, even inside the debugger.
#ifdef SUPPORT_EXCEPTIONHANDLING
	char szDumpFileName[_MAX_DIR]; 
	strcpy(szDumpFileName, szLogFileName);
	strcat(szDumpFileName, ".dmp");
	__try {
#endif
		// The code inside the __try block is the MFC version of AfxWinMain(),
		// copied verbatim from the MFC source code.
		ASSERT(hPrevInstance == NULL);

		int nReturnCode = -1;
		CWinApp* pApp = AfxGetApp();

		// AFX internal initialization
		if (!AfxWinInit(hInstance, hPrevInstance, lpCmdLine, nCmdShow))
			goto InitFailure;

		// App global initializations (rare)
		ASSERT_VALID(pApp);
		if (!pApp->InitApplication())
			goto InitFailure;
		ASSERT_VALID(pApp);

		// Perform specific initializations
		if (!pApp->InitInstance())
		{
			if (pApp->m_pMainWnd != NULL)
			{
				TRACE(_T("Warning: Destroying non-NULL m_pMainWnd\n"));
				pApp->m_pMainWnd->DestroyWindow();
			}
			nReturnCode = pApp->ExitInstance();
			goto InitFailure;
		}
		ASSERT_VALID(pApp);

		nReturnCode = pApp->Run();
		ASSERT_VALID(pApp);

InitFailure:
#ifdef _DEBUG
		// Check for missing AfxLockTempMap calls
		if (AfxGetModuleThreadState()->m_nTempMapLock != 0)
		{
			TRACE(_T("Warning: Temp map lock count non-zero (%ld).\n"),
				AfxGetModuleThreadState()->m_nTempMapLock);
		}
		AfxLockTempMaps();
		AfxUnlockTempMaps(-1);
#endif

		AfxWinTerm();
		return nReturnCode;

#ifdef SUPPORT_EXCEPTIONHANDLING
	}
//	__except(MFilterException(GetExceptionInformation())){
	__except(CrashExceptionDump(GetExceptionInformation(), szDumpFileName)){
		
//		char szFileName[_MAX_DIR];
//		GetModuleFileName(NULL, szFileName, _MAX_DIR);
//		WinExec(szFileName, SW_SHOW);	// Launch again
		//MMatchServer::GetInstance()->CheckMemoryTest();
		//MGetServerStatusSingleton()->Dump();
	}
#endif
	return 0;
}
Ejemplo n.º 10
0
// Here is the entry point for the Plugin..this gets called first.
int initaltacast(struct winampDSPModule *this_mod)
{
	char filename[512],*p;
	char	directory[1024] = "";
	char currentDir[1024] = "";
	

	memset(filename, '\000', sizeof(filename));
	GetModuleFileName(this_mod->hDllInstance,filename,sizeof(filename));
	strcpy(currentDir, filename);
	char *pend;
	pend = strrchr(currentDir, '\\');
	if (pend) {
		*pend = '\000';
	}
	p = filename+lstrlen(filename);
	while (p >= filename && *p != '\\') p--;
	p++;

	char	logFile[1024] = "";
	memset(logFile, '\000', sizeof(logFile));
	char *p2 = strchr(p, '.');
	if (p2) {
		strncpy(logFile, p, p2-p);
	}
	else {
		strcpy(logFile, p);
	}

	char tmpfile[MAX_PATH] = "";
	sprintf(tmpfile, "%s\\.tmp", currentDir);

	FILE *filep = fopen(tmpfile, "w");
	if (filep == 0) {
		char path[MAX_PATH] = "";

		SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, path);
		strcpy(currentDir, path);
	}
	else {
		fclose(filep);
	}
    LoadConfigs(currentDir, logFile);


	ghwnd_winamp = this_mod->hwndParent;

    AfxWinInit( this_mod->hDllInstance, NULL, "", SW_HIDE);

    mainWindow = new CMainWindow();
    mainWindow->InitializeWindow();

    strcpy(mainWindow->m_currentDir, currentDir);
    mainWindow->Create((UINT)IDD_ALTACAST, AfxGetMainWnd());
    int x = getLastX();
    int y = getLastY();
    if (x < 0) {
        x = 0;
    }
    if (y < 0) {
        y = 0;
    }
    mainWindow->SetWindowPos(NULL, (int)x, (int)y, -1, -1, SWP_NOSIZE | SWP_SHOWWINDOW);

    mainWindow->SetIcon(mainApp.LoadIcon(IDR_MAINFRAME), TRUE);
    
    mainWindow->ShowWindow(SW_SHOW);

	initializealtacast();

	timerId = SetTimer(NULL, 1, 1000, (TIMERPROC)getCurrentSongTitle);

	return 0;
}
Ejemplo n.º 11
0
void initializeIt()
{
		char filename[512],*p;
		char	directory[1024] = "";
		char currentDir[MAX_PATH] = "";


		memset(filename, '\000', sizeof(filename));
		GetModuleFileName(NULL,filename,sizeof(filename));
		strcpy(currentDir, filename);
		char *pend;
		pend = strrchr(currentDir, '\\');
		if (pend) {
			*pend = '\000';
		}
		p = filename+lstrlen(filename);
		while (p >= filename && *p != '\\') p--;
		p++;

		char	logFile[1024] = "";
		memset(logFile, '\000', sizeof(logFile));
		strcpy(logFile, "altacast_foo");

		char tmpfile[MAX_PATH] = "";
		sprintf(tmpfile, "%s\\.tmp", currentDir);

		FILE *filep = fopen(tmpfile, "w");
		if (filep == 0) {
			char path[MAX_PATH] = "";

			SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, path);
			strcpy(currentDir, path);
		}
		else {
			fclose(filep);
		}
        LoadConfigs(currentDir, logFile);

        AfxWinInit(core_api::get_my_instance(), NULL, "", SW_HIDE);

        mainWindow = new CMainWindow();

        mainWindow->InitializeWindow();

        strcpy(mainWindow->m_currentDir, currentDir);

        //mainWindow->Create((UINT)IDD_ALTACAST, mainApp.GetMainWnd());    
        //mainWindow->Create((UINT)IDD_ALTACAST, CWnd::FromHandle(core_api::get_main_window()));    
        mainWindow->Create((UINT)IDD_ALTACAST, AfxGetMainWnd());
        int x = getLastX();
        int y = getLastY();
        if (x < 0) {
            x = 0;
        }
        if (y < 0) {
            y = 0;
        }

        mainWindow->SetWindowPos(NULL, x, y, -1, -1, SWP_NOSIZE | SWP_SHOWWINDOW);

        modeless_dialog_manager::g_add(mainWindow->m_hWnd);
        modeless_dialog_manager::g_add(mainWindow->configDialog->m_hWnd);   
        modeless_dialog_manager::g_add(mainWindow->editMetadata->m_hWnd);

        mainWindow->SetIcon(mainApp.LoadIcon(IDR_MAINFRAME), TRUE);
        mainWindow->ShowWindow(SW_HIDE);
        

        initializealtacast();
}
Ejemplo n.º 12
0
extern "C" BOOL WINAPI
DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID)
{
        CWinApp* pApp = AfxGetApp();
        if (dwReason == DLL_PROCESS_ATTACH)
        {
                // initialize MFC exception handling
#ifndef _AFX_OLD_EXCEPTIONS
                set_terminate(&AfxStandardTerminate);
#endif
                _set_new_handler(&AfxNewHandler);

                // initialize DLL's instance(/module) not the app's
                if (!AfxWinInit(hInstance, NULL, &afxChNil, 0))
                {
                        AfxWinTerm();
                        return FALSE;   // Init Failed
                }

                // initialize the single instance DLL
                if (pApp != NULL && !pApp->InitInstance())
                {
                        pApp->ExitInstance();
                        AfxWinTerm();
                        return FALSE;   // Init Failed
                }
        }
        else if (dwReason == DLL_PROCESS_DETACH)
        {
                if (pApp != NULL)
                        pApp->ExitInstance();

#ifdef _DEBUG
                // check for missing AfxLockTempMap calls
                if (AfxGetThreadState()->m_nTempMapLock != 0)
                        TRACE1("Warning: Temp map lock count non-zero (%ld).\n",
                                AfxGetThreadState()->m_nTempMapLock);
#endif
                // terminate the library before destructors are called
                AfxWinTerm();

                // free safety pool buffer
                AFX_THREAD_STATE* pThreadState = AfxGetThreadState();
                if (pThreadState->m_pSafetyPoolBuffer != NULL)
                {
                        free(pThreadState->m_pSafetyPoolBuffer);
                        pThreadState->m_pSafetyPoolBuffer = NULL;
                }

#ifdef _DEBUG
                // trace any memory leaks that may have occurred
                AfxDumpMemoryLeaks();
#endif

                // clean up map objects before it is too late
                delete pThreadState->m_pmapHWND;
                pThreadState->m_pmapHWND = NULL;
                delete pThreadState->m_pmapHMENU;
                pThreadState->m_pmapHMENU = NULL;
                delete pThreadState->m_pmapHDC;
                pThreadState->m_pmapHDC = NULL;
                delete pThreadState->m_pmapHGDIOBJ;
                pThreadState->m_pmapHGDIOBJ = NULL;
                delete pThreadState->m_pmapHIMAGELIST;
                pThreadState->m_pmapHIMAGELIST = NULL;

                pThreadState->m_mapSocketHandle.CMapPtrToPtr::~CMapPtrToPtr();
                pThreadState->m_mapDeadSockets.CMapPtrToPtr::~CMapPtrToPtr();
                pThreadState->m_listSocketNotifications.CPtrList::~CPtrList();
        }
        return TRUE;    // ok
}
Ejemplo n.º 13
0
int AFXAPI AfxWinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
	LPTSTR lpCmdLine, int nCmdShow)
{
#ifdef DISPLAYCONSOLE 

  // Redirection of standard output to console
  int hCrt;  BOOL rep;  FILE *hf;
  _SYSTEM_INFO lps;
  GetSystemInfo(&lps);
  rep = AllocConsole();
  hCrt = _open_osfhandle((intptr_t) GetStdHandle(STD_OUTPUT_HANDLE),_O_TEXT);
  hf = _fdopen( hCrt, "w" );
  *stdout = *hf;
  // stop the buffer on stdout
//  int i = setvbuf( stdout, NULL, _IONBF, 0 );
//  filebuf ff(hCrt);
//  cout = &ff;
  cout<<"This Debug Window is defined in WinMain.cpp and will disappear in release mode"<<endl;

#endif //  DISPLAYCONSOLE  // By Matra

  // create log file for all OCC messages
//  Message::DefaultMessenger()->AddPrinter (new Message_PrinterOStream ("OCCSampleRun.log", Standard_False));

  ASSERT(hPrevInstance == NULL);

  int nReturnCode = -1;
  CWinApp* pApp = AfxGetApp();

// new in 2.0 CAS.CADE uses the standard C++ exception mechanism
/*#ifdef _DEBUG  // By Matra
  // _Function declaratiob here because you can jump to InitFailure
  Standard_ErrorHandler _Function;  
#endif //  _DEBUG  // By Matra
*/
	// AFX internal initialization
	if (!AfxWinInit(hInstance, hPrevInstance, lpCmdLine, nCmdShow))
		goto InitFailure;

	// App global initializations (rare)
	ASSERT_VALID(pApp);
	if (!pApp->InitApplication())
		goto InitFailure;
	ASSERT_VALID(pApp);

	// Perform specific initializations
	if (!pApp->InitInstance())
	{
		if (pApp->m_pMainWnd != NULL)
		{
			TRACE0("Warning: Destroying non-NULL m_pMainWnd\n");
			pApp->m_pMainWnd->DestroyWindow();
		}
		nReturnCode = pApp->ExitInstance();
		goto InitFailure;
	}
	ASSERT_VALID(pApp);


#ifdef _DEBUG  // By Matra
Application:

// new in 2.0 CAS.CADE uses the standard C++ exception mechanism

 // if(DoesNotAbort(_Function))
	try
    {
	  nReturnCode = pApp->Run();
    }
//  if(_Function.Catches(STANDARD_TYPE(Standard_Failure)))
	catch(Standard_Failure)
    {
      Standard_SStream ostr;
      ostr<<Standard_Failure::Caught()<<"\n\0";
      CString aMsg = ostr.str().c_str();
      MessageBoxW (NULL, aMsg, L"CasCade Error", MB_ICONERROR);
      goto Application; // restart application loop
    }
#else // _DEBUG  // By Matra
	nReturnCode = pApp->Run();
#endif // _DEBUG  // By Matra


	ASSERT_VALID(pApp);

InitFailure:
#ifdef _DEBUG
	// Check for missing AfxLockTempMap calls
	if (AfxGetModuleThreadState()->m_nTempMapLock != 0)
	{
		TRACE1("Warning: Temp map lock count non-zero (%ld).\n",
			AfxGetModuleThreadState()->m_nTempMapLock);
	}

	AfxLockTempMaps();
	AfxUnlockTempMaps();
#endif

	AfxWinTerm();

#ifdef DISPLAYCONSOLE  // By Matra
  // ferme la console pour le cout 
  fclose( stdout );
  //hCrt = _fcloseall();  :-)
  rep = FreeConsole();  
#endif // DISPLAYCONSOLE  // By Matra


	return nReturnCode;
}