Exemplo n.º 1
0
bool StartServer( HINSTANCE hInstance, HINSTANCE MaxhInstance, int registerCOM ) {

	bool res = true;

	HRESULT hRes = CoInitialize(NULL);
    _ASSERTE(SUCCEEDED(hRes));
	_Module.Init(ObjectMap, hInstance, &LIBID_COMSRVLib);
	_Module.dwThreadID = GetCurrentThreadId();

	switch (registerCOM) {
		case 1:
			res = UnRegisterCOM();
			CoUninitialize();
            return res;
		case 2:
			res = RegisterCOM(MaxhInstance);
			CoUninitialize();
            return res;
	}

	//-- Register Classes (Runtime)

    _Module.StartMonitor();
	hRes = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER | CLSCTX_REMOTE_SERVER,
		REGCLS_SINGLEUSE);
    _ASSERTE(SUCCEEDED(hRes));
	
	return res;

}
Exemplo n.º 2
0
extern "C" int WINAPI _tWinMain(HINSTANCE hInstance, 
    HINSTANCE /*hPrevInstance*/, LPTSTR lpCmdLine, int /*nShowCmd*/)
{
    lpCmdLine = GetCommandLine(); //this line necessary for _ATL_MIN_CRT

    HRESULT hRes = CoInitializeEx(NULL, COINIT_MULTITHREADED);

	_ASSERTE(SUCCEEDED(hRes));
    _Module.Init(ObjectMap, hInstance, &LIBID_IVMCTRLLib);
    _Module.dwThreadID = GetCurrentThreadId();
    TCHAR szTokens[] = _T("-/");

    int nRet = 0;
    BOOL bRun = TRUE;
    LPCTSTR lpszToken = FindOneOf(lpCmdLine, szTokens);
    while (lpszToken != NULL)
    {
        if (lstrcmpi(lpszToken, _T("UnregServer"))==0)
        {
            _Module.UpdateRegistryFromResource(IDR_IVMCtrl, FALSE);
            nRet = _Module.UnregisterServer(TRUE);
            bRun = FALSE;
            break;
        }
        if (lstrcmpi(lpszToken, _T("RegServer"))==0)
        {
            _Module.UpdateRegistryFromResource(IDR_IVMCtrl, TRUE);
            nRet = _Module.RegisterServer(TRUE);
            bRun = FALSE;
            break;
        }
        lpszToken = FindOneOf(lpszToken, szTokens);
    }

    if (bRun)
    {
        _Module.StartMonitor();
#if _WIN32_WINNT >= 0x0400 & defined(_ATL_FREE_THREADED)
        hRes = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER, 
            REGCLS_MULTIPLEUSE | REGCLS_SUSPENDED);
        _ASSERTE(SUCCEEDED(hRes));
        hRes = CoResumeClassObjects();
#else
        hRes = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER, 
            REGCLS_MULTIPLEUSE);
#endif
        _ASSERTE(SUCCEEDED(hRes));

        MSG msg;
        while (GetMessage(&msg, 0, 0, 0))
            DispatchMessage(&msg);

        _Module.RevokeClassObjects();
        Sleep(dwPause); //wait for any threads to finish
    }

    _Module.Term();
    CoUninitialize();
    return nRet;
}
Exemplo n.º 3
0
bool RegisterCOM(HINSTANCE MaxhInstance) {
	
	_Module.UpdateRegistryFromResource(IDR_Comsrv, TRUE);
	HRESULT hRes = _Module.RegisterServer(TRUE);
    _ASSERTE(SUCCEEDED(hRes));
	
	//-- Update Server Location

	TCHAR szModule[_MAX_PATH];
	GetModuleFileName(MaxhInstance,szModule,_MAX_PATH);
	TCHAR szKeyName[256];
	TCHAR keyLocalServer[] = {_T("LocalServer32")};
	
	//-- MaxRenderer Class
	// DC 707698 - VISTA compatibility
	// this key needs to be created at install time
	TCHAR clsidApp[] = {_T("{4AD72E6E-5A4B-11D2-91CB-0060081C257E}")};
	_stprintf(szKeyName,_T("CLSID\\%s\\%s"),clsidApp,keyLocalServer);
	OpenKeyAndSetValue(szKeyName,szModule);

	//-- MaxBitmapInfo Class
	// DC 707698 - VISTA compatibility
	// this key needs to be created at install time
	_tcscpy(clsidApp,_T("{D888A162-6543-11D2-91CC-0060081C257E}"));
	_stprintf(szKeyName,_T("CLSID\\%s\\%s"),clsidApp,keyLocalServer);
	OpenKeyAndSetValue(szKeyName,szModule);

	return true;
}
Exemplo n.º 4
0
void StopServer( ) {
//    _Module.Unlock();
	_Module.RevokeClassObjects();
	Sleep(dwPause);
	_Module.Term();
	CoUninitialize();
}
Exemplo n.º 5
0
bool RegisterCOM(HINSTANCE MaxhInstance) {
	
	_Module.UpdateRegistryFromResource(IDR_Comsrv, TRUE);
	HRESULT hRes = _Module.RegisterServer(TRUE);
    _ASSERTE(SUCCEEDED(hRes));
	
	//-- Update Server Location

	TCHAR szModule[_MAX_PATH];
	GetModuleFileName(MaxhInstance,szModule,_MAX_PATH);
	TCHAR szKeyName[256];
	TCHAR keyLocalServer[] = {"LocalServer32"};
	
	//-- MaxRenderer Class

	TCHAR clsidApp[] = {"{4AD72E6E-5A4B-11D2-91CB-0060081C257E}"};
	wsprintf(szKeyName,"CLSID\\%s\\%s",clsidApp,keyLocalServer);
	OpenKeyAndSetValue(szKeyName,szModule);

	//-- MaxBitmapInfo Class

	_tcscpy(clsidApp,_T("{D888A162-6543-11D2-91CC-0060081C257E}"));
	wsprintf(szKeyName,"CLSID\\%s\\%s",clsidApp,keyLocalServer);
	OpenKeyAndSetValue(szKeyName,szModule);

#ifdef RENDER_VER
	//Max application object
	_tcscpy(clsidApp,_T("{8A9DCB83-B385-41D0-B8E8-05A1AD47E72A}"));
	wsprintf(szKeyName,"CLSID\\%s\\%s",clsidApp,keyLocalServer);
	OpenKeyAndSetValue(szKeyName,szModule);

	//Max document object
	_tcscpy(clsidApp,_T("{F40F75D9-7384-44F1-8AC1-933D8CBEA728}"));
	wsprintf(szKeyName,"CLSID\\%s\\%s",clsidApp,keyLocalServer);
	OpenKeyAndSetValue(szKeyName,szModule);

	//TestMarshalSpeed class
	//To DO
	//remove this when testing complete
	_tcscpy(clsidApp,_T("{93B00F73-A90D-4A4B-9F4D-B7328892D624}"));
	wsprintf(szKeyName,"CLSID\\%s\\%s",clsidApp,keyLocalServer);
	OpenKeyAndSetValue(szKeyName,szModule);
#endif
	return true;

}
Exemplo n.º 6
0
extern "C" int WINAPI wWinMain(HINSTANCE hInstance, 
    HINSTANCE /*hPrevInstance*/, LPWSTR lpCmdLine, int /*nShowCmd*/)
{
    lpCmdLine = GetCommandLine(); //this line necessary for _ATL_MIN_CRT
    HRESULT hr = CoInitialize(NULL);
    _ASSERTE(SUCCEEDED(hr));

    _Module.Init(ObjectMap, hInstance);
    _Module.dwThreadID = GetCurrentThreadId();
    WCHAR wszTokens[] = L"-/";

    int nRet = 0;
    bool bRun = true;
    LPCWSTR lpwszToken = FindOneOf(lpCmdLine, wszTokens);
    while (lpwszToken != NULL)
    {
        if (_wcsnicmp(lpwszToken, L"UnregServer", 11)==0)
        {
            _Module.UpdateRegistryFromResource(IDR_ComSpy, FALSE);
            nRet = _Module.UnregisterServer();
            bRun = false;
            break;
        }
        if (_wcsnicmp(lpwszToken, L"RegServer", 9)==0)
        {
            _Module.UpdateRegistryFromResource(IDR_ComSpy, TRUE);
            nRet = _Module.RegisterServer(TRUE);
            bRun = false;
            break;
        }
        lpwszToken = FindOneOf(lpwszToken, wszTokens);
    }

    if (bRun)
    {
        hr = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE);
        _ASSERTE(SUCCEEDED(hr));

        CComPtr<ISpyCon> spApp;
        hr = CoCreateInstance(CLSID_SpyCon, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&spApp));
        _ASSERTE(SUCCEEDED(hr));

        if (SUCCEEDED(spApp->Run()))
        {
            MSG msg;
            while (GetMessage(&msg, 0, 0, 0))
            {
                TranslateMessage(&msg);
                DispatchMessage(&msg);
            }
        }

        _Module.RevokeClassObjects();
    }

    CoUninitialize();
    return nRet;
}
Exemplo n.º 7
0
extern "C" int WINAPI _tWinMain(HINSTANCE hInstance,
	HINSTANCE /*hPrevInstance*/, LPTSTR lpCmdLine, int /*nShowCmd*/)
{
	lpCmdLine = GetCommandLine();
	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);
	_ASSERTE(SUCCEEDED(hRes));
	_Module.Init(ObjectMap, hInstance);
	_Module.dwThreadID = GetCurrentThreadId();
	TCHAR szTokens[] = _T("-/");

	int nRet = 0;
	BOOL bRun = TRUE;
	LPCTSTR lpszToken = FindOneOf(lpCmdLine, szTokens);
	while (lpszToken != NULL)
	{
		if (lstrcmpi(lpszToken, _T("UnregServer"))==0)
		{
			_Module.UpdateRegistryFromResource(IDR_Stlcoll, FALSE);
			nRet = _Module.UnregisterServer();
			bRun = FALSE;
			break;
		}
		if (lstrcmpi(lpszToken, _T("RegServer"))==0)
		{
			_Module.UpdateRegistryFromResource(IDR_Stlcoll, TRUE);
			nRet = _Module.RegisterServer(TRUE);
			bRun = FALSE;
			break;
		}
		lpszToken = FindOneOf(lpszToken, szTokens);
	}

	if (bRun)
	{
		hRes = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER,
			REGCLS_MULTIPLEUSE);
		_ASSERTE(SUCCEEDED(hRes));

		MSG msg;
		while (GetMessage(&msg, 0, 0, 0))
			DispatchMessage(&msg);

		_Module.RevokeClassObjects();
	}

	CoUninitialize();
	return nRet;
}
int CMyApp::ExitInstance()     {

	DWORD dwStart = ::GetTickCount();
	MSG message;

	do {
	if (::PeekMessage(&message, NULL, 0, 0, PM_REMOVE)) {
			::TranslateMessage(&message);
			::DispatchMessage(&message);
		}
	}while ((::GetTickCount()-dwStart)<3000);


	// MFC's class factories registration is
	// automatically revoked by MFC itself
	_Module.RevokeClassObjects(); // Revoke class factories for ATL
	_Module.Term();               // cleanup ATL Global Module
	
	
	
	VERIFY(CTcpServer::StopWinsock());

	return CWinApp::ExitInstance();  
}
extern "C" int WINAPI wWinMain(HINSTANCE hInstance, 
    HINSTANCE /*hPrevInstance*/, LPWSTR lpCmdLine, int /*nShowCmd*/)
{
    lpCmdLine = GetCommandLine(); //this line necessary for _ATL_MIN_CRT

#if _WIN32_WINNT >= 0x0400 & defined(_ATL_FREE_THREADED)
    HRESULT hRes = CoInitializeEx(NULL, COINIT_MULTITHREADED);
#else
    HRESULT hRes = CoInitialize(NULL);
#endif
    _ASSERTE(SUCCEEDED(hRes));
    _Module.Init(ObjectMap, hInstance, &LIBID_ATLLib);
    _Module.dwThreadID = GetCurrentThreadId();
   
    _Module.StartMonitor();
#if _WIN32_WINNT >= 0x0400 & defined(_ATL_FREE_THREADED)
    hRes = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER, 
        REGCLS_MULTIPLEUSE | REGCLS_SUSPENDED);
    _ASSERTE(SUCCEEDED(hRes));
    hRes = CoResumeClassObjects();
#else
    hRes = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER, 
       REGCLS_MULTIPLEUSE);
#endif
    _ASSERTE(SUCCEEDED(hRes));

    CMainDlg dlg;
    dlg.DoModal();

    _Module.RevokeClassObjects();
    Sleep(dwPause); //wait for any threads to finish

    _Module.Term();
    CoUninitialize();
    return 0;
}
Exemplo n.º 10
0
//===========================================================================
extern "C" int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 
                                LPTSTR lpCmdLine, int nShowCmd ) {

  HANDLE hMutex;
  int iRet;
  HRESULT hRes;
  TCHAR szTokens[] = _T("-/");

  // Check for another instance
  hMutex = OpenMutex( SYNCHRONIZE,  // requested access (lowest possible)
                      FALSE,  // allow inheritance (does not matter)
                      x_szMutexName);  // unique name

  if(hMutex){
    MessageBox( NULL, "Cannot start the application because another instance is already running.\n", 
                g_szAppTitile, MB_OK | MB_ICONERROR );
    return 1;
  }

  hMutex = CreateMutex( NULL,  // default security
                        TRUE,  // obtain ownership
                        x_szMutexName);  // unique name
  if(!hMutex){
    MessageBox( NULL, "Cannot create application mutex.\n", 
                g_szAppTitile, MB_OK | MB_ICONERROR );
    return 1;
  }
    

  hRes = CoInitialize(NULL);  // single-threaded apartment 
  _ASSERTE(SUCCEEDED(hRes));
  _Module.Init(ObjectMap, hInstance, &LIBID_CP_DISPLAYLib);
  hRes = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE);
  _ASSERTE(SUCCEEDED(hRes));

  lpCmdLine = GetCommandLine(); //this line is necessary for _ATL_MIN_CRT


  // Parse the command line for options
  LPCTSTR lpszToken = FindOneOf(lpCmdLine, szTokens);
  while (lpszToken != NULL) {
    if (lstrcmpi(lpszToken, "UnregServer")==0) {
      _Module.UpdateRegistryFromResource(IDR_CP_Display, FALSE);
      iRet = _Module.UnregisterServer(TRUE);
	  //	iRet = g_UnregisterCOM();


      if( iRet != 0 ) { 
        MessageBox( NULL, "Error: Can't unregister server. UnregisterServer() failed.", g_szAppTitile, MB_OK);
      }
      else {
        MessageBox( NULL, "Success: the server is unregistered.", g_szAppTitile, MB_OK);
      }
      _Module.Term();
      CoUninitialize();
      return iRet;
    }
    if (lstrcmpi(lpszToken, "RegServer")==0) {
      iRet = _Module.UpdateRegistryFromResource(IDR_CP_Display, TRUE);
      iRet = _Module.RegisterServer(TRUE);
      //iRet = g_RegisterCOM();

      if( iRet != 0 ) { 
		  char str[200];
		  sprintf(str,"Error: Can't register server. g_RegisterCOM() failed (%lx).",(unsigned long)iRet);
        MessageBox( NULL, str, g_szAppTitile, MB_OK);
		//MessageBox( NULL, "Error: Can't register server. g_RegisterCOM() failed.", g_szAppTitile, MB_OK);
      }
      else {
        MessageBox( NULL, "Success: the server is registered.", g_szAppTitile, MB_OK);
      }
      _Module.Term();
      CoUninitialize();
      return iRet;
    }
    lpszToken = FindOneOf(lpszToken, szTokens);
  } // while there are tokens


  CP_printfCreate( g_szAppTitile );  // Creates log window (console)
  CP_printf("%s\n", g_szVersion );


  CP_printf("----------------------------------------\n");
  CP_printf("Build options:\n\n");
//~~~~~~~~~~~~~~~~~
#ifdef _DEBUG
  CP_printf("Debug version.\n");
#else
  CP_printf("Release version. \n\n");
#endif  // #ifdef _DEBUG
//~~~~~~~~~~~~~~~~~
  CP_printf("SET_FULLSCREEN_MODE: %d\n", SET_FULLSCREEN_MODE);
  CP_printf("DEBUG_THRESHOLD: %d\n", DEBUG_THRESHOLD);
  CP_printf("----------------------------------------\n");

  srand( (unsigned)123 );
  try {
    if ( !g_StartGL_Engine( hInstance, nShowCmd ) ){
      g_MainLoop();
    }
  }
  catch( ... ) {
    MessageBox( NULL, "Exception!!! SOS!!! The program will shut down!", 
               g_szAppTitile, MB_OK | MB_ICONERROR );
    exit(1);
  }

  CP_printf("N objects before quitting: %d\n", _Module.GetLockCount() );

  _Module.RevokeClassObjects();
  Sleep(COM_THREAD_WAIT_MS); //wait for any threads to finish


  // WrapUp
  _Module.Term();
  CoUninitialize();
  // Left-over objects are deleted in CoUninitialize(). Since they call RequestUpdate 
  // in the destuctor, we have to delete GL_Window after CoUninitialize()
  g_StopGL_Engine( );  
  InvalidateRect(NULL, NULL, TRUE); // redraw the desktop
  Sleep(5000); // show log window for 5 sec before quitting
  CP_printfDestroy( );  // Kills log window (console)
  ReleaseMutex(hMutex); 

  return 0;
}
Exemplo n.º 11
0
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPSTR /*lpCmdLine*/, int /*nShowCmd*/)
{
    LPCTSTR lpCmdLine = GetCommandLine(); /* this line necessary for _ATL_MIN_CRT */

    /*
     * Need to parse the command line before initializing the VBox runtime.
     */
    TCHAR szTokens[] = _T("-/");
    LPCTSTR lpszToken = FindOneOf(lpCmdLine, szTokens);
    while (lpszToken != NULL)
    {
        if (WordCmpI(lpszToken, _T("Embedding")) == 0)
        {
            /* %HOMEDRIVE%%HOMEPATH% */
            wchar_t wszHome[RTPATH_MAX];
            DWORD cEnv = GetEnvironmentVariable(L"HOMEDRIVE", &wszHome[0], RTPATH_MAX);
            if (cEnv && cEnv < RTPATH_MAX)
            {
                DWORD cwc = cEnv; /* doesn't include NUL */
                cEnv = GetEnvironmentVariable(L"HOMEPATH", &wszHome[cEnv], RTPATH_MAX - cwc);
                if (cEnv && cEnv < RTPATH_MAX - cwc)
                {
                    /* If this fails there is nothing we can do. Ignore. */
                    SetCurrentDirectory(wszHome);
                }
            }
        }

        lpszToken = FindOneOf(lpszToken, szTokens);
    }

    /*
     * Initialize the VBox runtime without loading
     * the support driver.
     */
    int    argc = __argc;
    char **argv = __argv;
    RTR3InitExe(argc, &argv, 0);

    /* Note that all options are given lowercase/camel case/uppercase to
     * approximate case insensitive matching, which RTGetOpt doesn't offer. */
    static const RTGETOPTDEF s_aOptions[] =
    {
        { "--embedding",    'e',    RTGETOPT_REQ_NOTHING | RTGETOPT_FLAG_ICASE },
        { "-embedding",     'e',    RTGETOPT_REQ_NOTHING | RTGETOPT_FLAG_ICASE },
        { "/embedding",     'e',    RTGETOPT_REQ_NOTHING | RTGETOPT_FLAG_ICASE },
        { "--unregserver",  'u',    RTGETOPT_REQ_NOTHING | RTGETOPT_FLAG_ICASE },
        { "-unregserver",   'u',    RTGETOPT_REQ_NOTHING | RTGETOPT_FLAG_ICASE },
        { "/unregserver",   'u',    RTGETOPT_REQ_NOTHING | RTGETOPT_FLAG_ICASE },
        { "--regserver",    'r',    RTGETOPT_REQ_NOTHING | RTGETOPT_FLAG_ICASE },
        { "-regserver",     'r',    RTGETOPT_REQ_NOTHING | RTGETOPT_FLAG_ICASE },
        { "/regserver",     'r',    RTGETOPT_REQ_NOTHING | RTGETOPT_FLAG_ICASE },
        { "--reregserver",  'f',    RTGETOPT_REQ_NOTHING | RTGETOPT_FLAG_ICASE },
        { "-reregserver",   'f',    RTGETOPT_REQ_NOTHING | RTGETOPT_FLAG_ICASE },
        { "/reregserver",   'f',    RTGETOPT_REQ_NOTHING | RTGETOPT_FLAG_ICASE },
        { "--helper",       'H',    RTGETOPT_REQ_STRING | RTGETOPT_FLAG_ICASE },
        { "-helper",        'H',    RTGETOPT_REQ_STRING | RTGETOPT_FLAG_ICASE },
        { "/helper",        'H',    RTGETOPT_REQ_STRING | RTGETOPT_FLAG_ICASE },
        { "--logfile",      'F',    RTGETOPT_REQ_STRING | RTGETOPT_FLAG_ICASE },
        { "-logfile",       'F',    RTGETOPT_REQ_STRING | RTGETOPT_FLAG_ICASE },
        { "/logfile",       'F',    RTGETOPT_REQ_STRING | RTGETOPT_FLAG_ICASE },
        { "--logrotate",    'R',    RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_ICASE },
        { "-logrotate",     'R',    RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_ICASE },
        { "/logrotate",     'R',    RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_ICASE },
        { "--logsize",      'S',    RTGETOPT_REQ_UINT64 | RTGETOPT_FLAG_ICASE },
        { "-logsize",       'S',    RTGETOPT_REQ_UINT64 | RTGETOPT_FLAG_ICASE },
        { "/logsize",       'S',    RTGETOPT_REQ_UINT64 | RTGETOPT_FLAG_ICASE },
        { "--loginterval",  'I',    RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_ICASE },
        { "-loginterval",   'I',    RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_ICASE },
        { "/loginterval",   'I',    RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_ICASE },
    };

    bool            fRun = true;
    bool            fRegister = false;
    bool            fUnregister = false;
    const char      *pszPipeName = NULL;
    const char      *pszLogFile = NULL;
    uint32_t        cHistory = 10;                  // enable log rotation, 10 files
    uint32_t        uHistoryFileTime = RT_SEC_1DAY; // max 1 day per file
    uint64_t        uHistoryFileSize = 100 * _1M;   // max 100MB per file

    RTGETOPTSTATE   GetOptState;
    int vrc = RTGetOptInit(&GetOptState, argc, argv, &s_aOptions[0], RT_ELEMENTS(s_aOptions), 1, 0 /*fFlags*/);
    AssertRC(vrc);

    RTGETOPTUNION   ValueUnion;
    while ((vrc = RTGetOpt(&GetOptState, &ValueUnion)))
    {
        switch (vrc)
        {
            case 'e':
                /* already handled above */
                break;

            case 'u':
                fUnregister = true;
                fRun = false;
                break;

            case 'r':
                fRegister = true;
                fRun = false;
                break;

            case 'f':
                fUnregister = true;
                fRegister = true;
                fRun = false;
                break;

            case 'H':
                pszPipeName = ValueUnion.psz;
                if (!pszPipeName)
                    pszPipeName = "";
                fRun = false;
                break;

            case 'F':
                pszLogFile = ValueUnion.psz;
                break;

            case 'R':
                cHistory = ValueUnion.u32;
                break;

            case 'S':
                uHistoryFileSize = ValueUnion.u64;
                break;

            case 'I':
                uHistoryFileTime = ValueUnion.u32;
                break;

            case 'h':
            {
                TCHAR txt[]= L"Options:\n\n"
                             L"/RegServer:\tregister COM out-of-proc server\n"
                             L"/UnregServer:\tunregister COM out-of-proc server\n"
                             L"/ReregServer:\tunregister and register COM server\n"
                             L"no options:\trun the server";
                TCHAR title[]=_T("Usage");
                fRun = false;
                MessageBox(NULL, txt, title, MB_OK);
                return 0;
            }

            case 'V':
            {
                char *psz = NULL;
                RTStrAPrintf(&psz, "%sr%s\n", RTBldCfgVersion(), RTBldCfgRevisionStr());
                PRTUTF16 txt = NULL;
                RTStrToUtf16(psz, &txt);
                TCHAR title[]=_T("Version");
                fRun = false;
                MessageBox(NULL, txt, title, MB_OK);
                RTStrFree(psz);
                RTUtf16Free(txt);
                return 0;
            }

            default:
                /** @todo this assumes that stderr is visible, which is not
                 * true for standard Windows applications. */
                /* continue on command line errors... */
                RTGetOptPrintError(vrc, &ValueUnion);
        }
    }

    /* Only create the log file when running VBoxSVC normally, but not when
     * registering/unregistering or calling the helper functionality. */
    if (fRun)
    {
        if (!pszLogFile)
        {
            char szLogFile[RTPATH_MAX];
            vrc = com::GetVBoxUserHomeDirectory(szLogFile, sizeof(szLogFile));
            if (RT_SUCCESS(vrc))
                vrc = RTPathAppend(szLogFile, sizeof(szLogFile), "VBoxSVC.log");
            if (RT_SUCCESS(vrc))
                pszLogFile = RTStrDup(szLogFile);
        }
        char szError[RTPATH_MAX + 128];
        vrc = com::VBoxLogRelCreate("COM Server", pszLogFile,
                                    RTLOGFLAGS_PREFIX_THREAD | RTLOGFLAGS_PREFIX_TIME_PROG,
                                    "all", "VBOXSVC_RELEASE_LOG",
                                    RTLOGDEST_FILE, UINT32_MAX /* cMaxEntriesPerGroup */,
                                    cHistory, uHistoryFileTime, uHistoryFileSize,
                                    szError, sizeof(szError));
        if (RT_FAILURE(vrc))
            return RTMsgErrorExit(RTEXITCODE_FAILURE, "failed to open release log (%s, %Rrc)", szError, vrc);
    }

    int nRet = 0;
    HRESULT hRes = com::Initialize();

    _ASSERTE(SUCCEEDED(hRes));
    _Module.Init(ObjectMap, hInstance, &LIBID_VirtualBox);
    _Module.dwThreadID = GetCurrentThreadId();

    if (!fRun)
    {
        if (fUnregister)
        {
            _Module.UpdateRegistryFromResource(IDR_VIRTUALBOX, FALSE);
            nRet = _Module.UnregisterServer(TRUE);
        }
        if (fRegister)
        {
            _Module.UpdateRegistryFromResource(IDR_VIRTUALBOX, TRUE);
            nRet = _Module.RegisterServer(TRUE);
        }
        if (pszPipeName)
        {
            Log(("SVCMAIN: Processing Helper request (cmdline=\"%s\")...\n", pszPipeName));

            if (!*pszPipeName)
                vrc = VERR_INVALID_PARAMETER;

            if (RT_SUCCESS(vrc))
            {
                /* do the helper job */
                SVCHlpServer server;
                vrc = server.open(pszPipeName);
                if (RT_SUCCESS(vrc))
                    vrc = server.run();
            }
            if (RT_FAILURE(vrc))
            {
                Log(("SVCMAIN: Failed to process Helper request (%Rrc).", vrc));
                nRet = 1;
            }
        }
    }
    else
    {
        _Module.StartMonitor();
#if _WIN32_WINNT >= 0x0400 & defined(_ATL_FREE_THREADED)
        hRes = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE | REGCLS_SUSPENDED);
        _ASSERTE(SUCCEEDED(hRes));
        hRes = CoResumeClassObjects();
#else
        hRes = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE);
#endif
        _ASSERTE(SUCCEEDED(hRes));

        MSG msg;
        while (GetMessage(&msg, 0, 0, 0))
            DispatchMessage(&msg);

        _Module.RevokeClassObjects();
        Sleep(dwPause); //wait for any threads to finish
    }

    _Module.Term();

    com::Shutdown();

    Log(("SVCMAIN: Returning, COM server process ends.\n"));
    return nRet;
}
Exemplo n.º 12
0
int CStlcollApp::ExitInstance()
{
	_Module.Term();
	return CWinApp::ExitInstance();
}
Exemplo n.º 13
0
STDAPI DllCanUnloadNow(void)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	return (AfxDllCanUnloadNow()==S_OK && _Module.GetLockCount()==0) ? S_OK : S_FALSE;
}
Exemplo n.º 14
0
/////////////////////////////////////////////////////////////////////////////
// Program Entry Point
//
extern "C" int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
    // Initialize the application, if needed
    g_papp->Initialize(GetCommandLine());

    // Just display syntax when the command-line is empty
    if (argc < 2)
        return _Module.Syntax();

    // Enter this thread into a COM apartment
#if (_WIN32_WINNT >= 0x0400 || defined(_WIN32_DCOM)) & defined(_ATL_FREE_THREADED)
    TCCoInit coInit(COINIT_MULTITHREADED);
#else
    TCCoInit coInit();
#endif
    assert(coInit.Succeeded());

    // Initialize the ATL _Module object
    _Module.Init(ObjectMap, GetModuleHandle(NULL), &LIBID_PigsLib);

    // Parse the command line options
    HRESULT hr = _Module.ParseCommandLine(argc, argv);
    if (FAILED(hr))
        return hr;
    if (S_FALSE == hr)
        return S_OK;

    // Initialize security
    if (FAILED(hr = _Module.InitializeSecurity()))
        return _Module.ReportError(hr, TEXT("Security Initialization"));

    // Register our class (factory) objects
    if (FAILED(hr = _Module.RegisterClassObjects()))
    {
        _Module.Term();
        return _Module.ReportError(hr, TEXT("Class Object Registration"));
    }

    // Display status
    _Module.Echo(TEXT(" The server is running. Ctrl+C to exit."));
    _Module.EchoFlush();

    // Handle Ctrl+C and other important exiting events
    SetConsoleCtrlHandler(_Module.ConsoleCtrlHandler, true);

    // Enter a message loop (very last Unlock will post WM_QUIT message)
    MSG msg;
    while (GetMessage(&msg, 0, 0, 0))
        DispatchMessage(&msg);

    // Revoke our class (factory) objects
    _Module.RevokeClassObjects();

    // Terminate the ATL _Module object
    _Module.Term();

    // Indicate success
    return S_OK;
}
Exemplo n.º 15
0
BOOL CStlcollApp::InitInstance()
{
	_Module.Init(ObjectMap, m_hInstance);
	return CWinApp::InitInstance();
}
Exemplo n.º 16
0
int _tmain(int argc, LPTSTR argv[])
{
    int nRet = 0;

    if (_Module.IsWorker())
    {
        MSG(0, _T("Greetings from Worker! [%i]\n\n"), _Module.InstanceCount());
    }
    else
    {
        // check for help request or errors..
        nRet = _Module.LoadPreferences(argc, argv);
        if (nRet == ERROR_SUCCESS)
        {
            _Module.BackupTaskState();

            PROCESS_INFORMATION pi = {0};

            do
            {
                if (!_Module.CreateWorkerProcess(pi)) { nRet = -1; break; }

            } while (!_Module.WatchWorkerProcess(pi));
        }

        return nRet;
    }

    try
    {
        nRet = _Module.LoadPreferences(argc, argv);
        if (nRet == ERROR_SUCCESS)
        {
            CWsaInitialize _;

            if (_Module.Connect() == ERROR_SUCCESS)
            {
                nRet = _Module.Run();
            }
            _Module.Disconnect();
#ifdef _DEBUG
            MSG(0, _T("[%i] worker bye... \n"), _Module.InstanceCount());
            ::Sleep(3000);
#endif
        }
    }
    catch (int e)
    {
        nRet = CLog::Error(_T("Server failed."), e);
    }
    catch (std::exception& e)
    {
        ERR(_T("Exception caught: %s\n"), (LPCTSTR)CString(e.what()));
    }
    catch (...)
    {
        ERR(_T("Exception caught: unspecified.\n"));
    }

    return nRet;
}
Exemplo n.º 17
0
STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
{
	return _Module.GetClassObject(rclsid, riid, ppv);
}
Exemplo n.º 18
0
STDAPI DllRegisterServer(void)
{
	// registers object, typelib and all interfaces in typelib
	return _Module.RegisterServer(TRUE);
}
Exemplo n.º 19
0
extern "C" int WINAPI _tWinMain(HINSTANCE hInstance,
    HINSTANCE /*hPrevInstance*/, LPTSTR lpCmdLine, int /*nShowCmd*/)
{
    lpCmdLine = GetCommandLine(); //this line necessary for _ATL_MIN_CRT

    HRESULT hRes = CoInitializeEx(NULL, COINIT_MULTITHREADED);

    _ASSERTE(SUCCEEDED(hRes));
    _Module.Init(ObjectMap, hInstance, &LIBID_HYPERFEEDPROVIDERSLib);
    _Module.dwThreadID = GetCurrentThreadId();
    TCHAR szTokens[] = _T("-/");

    int nRet = 0;
    BOOL bRun = TRUE;
    LPCTSTR lpszToken = FindOneOf(lpCmdLine, szTokens);
    while (lpszToken != NULL)
    {
        if (lstrcmpi(lpszToken, _T("UnregServer"))==0)
        {
            _Module.UpdateRegistryFromResource(IDR_HyperFeedProviders, FALSE);
            nRet = _Module.UnregisterServer(TRUE);
            bRun = FALSE;
            break;
        }
        if (lstrcmpi(lpszToken, _T("RegServer"))==0)
        {
            _Module.UpdateRegistryFromResource(IDR_HyperFeedProviders, TRUE);
            nRet = _Module.RegisterServer(TRUE);
            bRun = FALSE;
            break;
        }
        lpszToken = FindOneOf(lpszToken, szTokens);
    }

    if (bRun)
    {
		// Starting with trace
		EgStd::g_pTrace = new CHyperFeedTrace();
		EgStd::g_pTrace->Init();


#ifndef _DEBUG 
		SetMiniDumpDefaultCrashHandler();
#endif
		ATLVERIFY(SUCCEEDED(_Module.LoadExchangeCodes()));
		ATLVERIFY(SUCCEEDED(_Module.LoadProviderSettings()));

       _Module.StartMonitor();
#if _WIN32_WINNT >= 0x0400 & defined(_ATL_FREE_THREADED)
        hRes = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER,
            REGCLS_MULTIPLEUSE | REGCLS_SUSPENDED);
        _ASSERTE(SUCCEEDED(hRes));
        hRes = CoResumeClassObjects();
#else
        hRes = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER,
            REGCLS_MULTIPLEUSE);
#endif
        _ASSERTE(SUCCEEDED(hRes));

        MSG msg;
        while (GetMessage(&msg, 0, 0, 0))
            DispatchMessage(&msg);

        _Module.RevokeClassObjects();
        Sleep(dwPause); //wait for any threads to finish

		// Exit the tracing
		EgStd::g_pTrace->Exit();

		if (EgStd::g_pTrace != NULL)
			delete EgStd::g_pTrace;
    }

    _Module.Term();
    CoUninitialize();
    return nRet;
}
Exemplo n.º 20
0
STDAPI DllUnregisterServer(void)
{
	_Module.UnregisterServer();
	return S_OK;
}
Exemplo n.º 21
0
bool UnRegisterCOM( ) {
	_Module.UpdateRegistryFromResource(IDR_Comsrv, FALSE);
	return(_Module.UnregisterServer(TRUE) != 0);
}
Exemplo n.º 22
0
void ShowMemoryMapDialog(HWND hParent)
{
    HWND hDlg = CreateDialog(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDD_MAPLISTDIALOG), hParent, MemoryMapDialogProc);
    ShowWindow(hDlg, SW_SHOW);
}
Exemplo n.º 23
0
extern "C" int WINAPI _tWinMain(HINSTANCE hInstance, 
    HINSTANCE /*hPrevInstance*/, LPTSTR lpCmdLine, int /*nShowCmd*/)
{
    lpCmdLine = GetCommandLine(); // この行は _ATL_MIN_CRT のために必要です
    
#if _WIN32_WINNT >= 0x0400 & defined(_ATL_FREE_THREADED)
    HRESULT hRes = CoInitializeEx(NULL, COINIT_MULTITHREADED);
#else
    HRESULT hRes = CoInitialize(NULL);
#endif
    _ASSERTE(SUCCEEDED(hRes));
    _Module.Init(ObjectMap, hInstance, &LIBID_ATLDEVICEMANAGERLib);
    _Module.dwThreadID = GetCurrentThreadId();
    TCHAR szTokens[] = _T("-/");

    int nRet = 0;
    BOOL bRun = TRUE;
    LPCTSTR lpszToken = FindOneOf(lpCmdLine, szTokens);
    while (lpszToken != NULL)
    {
        if (lstrcmpi(lpszToken, _T("UnregServer"))==0)
        {
            _Module.UpdateRegistryFromResource(IDR_ATLDeviceManager, FALSE);
            nRet = _Module.UnregisterServer(TRUE);
            bRun = FALSE;
            break;
        }
        if (lstrcmpi(lpszToken, _T("RegServer"))==0)
        {
            _Module.UpdateRegistryFromResource(IDR_ATLDeviceManager, TRUE);
            nRet = _Module.RegisterServer(TRUE);
            bRun = FALSE;
            break;
        }
        lpszToken = FindOneOf(lpszToken, szTokens);
    }

    if (bRun)
    {
		HWND dummy_dialog_handle = NULL;

		//::AllocConsole();

		ProcessInstance = hInstance;
		dummy_dialog_handle = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_DUMMYDIALOG), NULL, DummyDialogProc);
		ShowWindow(dummy_dialog_handle, SW_HIDE);

        _Module.StartMonitor();
#if _WIN32_WINNT >= 0x0400 & defined(_ATL_FREE_THREADED)
        hRes = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER, 
            REGCLS_MULTIPLEUSE | REGCLS_SUSPENDED);
        _ASSERTE(SUCCEEDED(hRes));
        hRes = CoResumeClassObjects();
#else
        hRes = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER, 
            REGCLS_MULTIPLEUSE);
#endif
        _ASSERTE(SUCCEEDED(hRes));

        MSG msg;
        while (GetMessage(&msg, 0, 0, 0))
            DispatchMessage(&msg);

        _Module.RevokeClassObjects();
        Sleep(dwPause); //スレッドが終了するまで待ちます

		if(dummy_dialog_handle != NULL)
			::DestroyWindow(dummy_dialog_handle);

		::FreeConsole();
	}

    _Module.Term();
    CoUninitialize();
    return nRet;
}
BOOL CMyApp::InitInstance()     {
	
	if (!DComOk()) {
		AfxMessageBox(_T("DCOM OLE Not supported"),MB_SYSTEMMODAL+MB_OK);
		return FALSE;       
	}      

	
	// Initialize OLE libraries       
	if (!AfxOleInit2())        {
		AfxMessageBox(_T("OLE Initialization Failed!"),MB_SYSTEMMODAL+MB_OK);
		return FALSE;       
	}        // Initialize the ATL Module

	_Module.Init(ObjectMap,m_hInstance); 
    _Module.dwThreadID = GetCurrentThreadId();

#ifdef _AFXDLL
		Enable3dControls(); // Call this when using MFC in a shared DLL
#else      
		Enable3dControlsStatic(); // Call this when linking
	// to MFC statically     
#endif

    //Reg UnregSever 
    TCHAR szTokens[] = _T("-/");
	int nRet = 0;
	BOOL bRun = TRUE;
	LPCTSTR lpszToken = FindOneOf(m_lpCmdLine, szTokens);

	while (lpszToken != NULL)
	{
		if (lstrcmpi(lpszToken, _T("UnregServer"))==0)
		{
			_Module.UpdateRegistryFromResource(IDR_ModbusServer, FALSE);
			nRet = _Module.UnregisterServer();
			nRet = UnRegisterTypeLib(
			   LIBID_MODBUSSERVERLib, 1, 0,
               LOCALE_NEUTRAL, SYS_WIN32);
			bRun = FALSE;
			break;
		}
		if (lstrcmpi(lpszToken, _T("RegServer"))==0)
		{
			_Module.UpdateRegistryFromResource(IDR_ModbusServer, TRUE);
			nRet = _Module.RegisterServer(TRUE);
			bRun = FALSE;
			// Update the System Registry
			COleObjectFactory::UpdateRegistryAll(); // MFC Classes
			if(!(SUCCEEDED(nRet))){
				AfxMessageBox("Register server Failed",MB_SYSTEMMODAL+MB_OK);
			}
			bRun=FALSE;
			break;
		}
		lpszToken = FindOneOf(lpszToken, szTokens);
	}
		
	// ATL Classes
	// Create the dialog box or other stuff here
	// Register OLE Class Factories
	// MFC ones are for multiple as specified
	// by the IMPLEMENT_OLECREATE() macro
	//COleObjectFactory::RegisterAll();
	// ATL ones specifically register with REGCLS_MULTIPLEUSE
	if (bRun) {
		if(!(SUCCEEDED(_Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER,
			REGCLS_MULTIPLEUSE)))){
				AfxMessageBox("RegisterClassObjects Failed",MB_SYSTEMMODAL+MB_OK);
		}
	}

	VERIFY(CTcpServer::StartWinsock());

	// Parse the command line to see if launched as OLE server
	if (RunEmbedded() || RunAutomated())        {
		// Application was run with /Embedding or /Automation.
		// Don't show the main window in this case. 
		//Test();
		return TRUE;
	}   
	
	return FALSE; // Nothing to do, so exit.    
	
}
Exemplo n.º 25
0
// Passed to CreateThread to monitor the shutdown event
static DWORD WINAPI MonitorProc(void* pv)
{
	CExeModule* p = (CExeModule*)pv;
	p->MonitorShutdown();
	return 0;
}
Exemplo n.º 26
0
extern "C" int WINAPI _tWinMain(HINSTANCE hInstance, 
    HINSTANCE /*hPrevInstance*/, LPTSTR lpCmdLine, int /*nShowCmd*/)
{
    lpCmdLine = GetCommandLine(); //this line necessary for _ATL_MIN_CRT

#if _WIN32_WINNT >= 0x0400 & defined(_ATL_FREE_THREADED)
    HRESULT hRes = CoInitializeEx(NULL, COINIT_MULTITHREADED);
#else
    HRESULT hRes = CoInitialize(NULL);
#endif
    _ASSERTE(SUCCEEDED(hRes));
    _Module.Init(ObjectMap, hInstance, &LIBID_VISSERVERLib);
    _Module.dwThreadID = GetCurrentThreadId();
    TCHAR szTokens[] = _T("-/");

    int nRet = 0;
    BOOL bRun = TRUE;
    LPCTSTR lpszToken = FindOneOf(lpCmdLine, szTokens);
    while (lpszToken != NULL)
    {
        if (lstrcmpi(lpszToken, _T("UnregServer"))==0)
        {
            _Module.UpdateRegistryFromResource(IDR_VisServer, FALSE);
            nRet = _Module.UnregisterServer(TRUE);
            bRun = FALSE;
            break;
        }
        if (lstrcmpi(lpszToken, _T("RegServer"))==0)
        {
            _Module.UpdateRegistryFromResource(IDR_VisServer, TRUE);
            nRet = _Module.RegisterServer(TRUE);
            bRun = FALSE;
            break;
        }
        lpszToken = FindOneOf(lpszToken, szTokens);
    }

    if (bRun)
    {
        _Module.StartMonitor();
#if _WIN32_WINNT >= 0x0400 & defined(_ATL_FREE_THREADED)
        hRes = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE | REGCLS_SUSPENDED);
        _ASSERTE(SUCCEEDED(hRes));
        hRes = CoResumeClassObjects();
#else
        hRes = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE);
#endif
        _ASSERTE(SUCCEEDED(hRes));

		///////////////
		/////////////// MAIN LOOP
		///////////////
		// PNS:: The orginal message loop did nothing but handle messages:
		/*
        MSG msg;
        while (GetMessage(&msg, 0, 0, 0))
			DispatchMessage(&msg);
		*/
	
		// Will Use WM_PAINT to coordinate painting		
		MSG msg;
		while (GetMessage(&msg, 0, 0, 0)){
			TranslateMessage( &msg );
			DispatchMessage(&msg);
		}
		
	/*
		// We need to add the graphics loop here.
		// We will:
		//   use PeekMessage (which does not block) as long as there is a message
		//   then do a single window Update
		//   then use GetMessage which blocks (idle) until the next message

		MSG msg;
		int done = 0;
		while(!done)									// Loop That Runs While done=FALSE
		{
			GetMessage(&msg, 0, 0, 0);					// Idle until first message
			if(msg.message==WM_QUIT) done=1;		
			else {
				TranslateMessage( &msg );
				DispatchMessage(&msg);
			}
			
			while(PeekMessage(&msg,NULL,0,0,PM_REMOVE))	// Handle rest of waiting messages
			{
				if(msg.message==WM_QUIT) done=1;		
				else {
					TranslateMessage( &msg );
					DispatchMessage(&msg);
				}
			}
			
			if(VisWindow!=NULL)	VisWindow->update();	// Take this time to update window
		}
	*/
		
		///////////////
				
        _Module.RevokeClassObjects();
        Sleep(dwPause); //wait for any threads to finish

		// Just in Case Window Cleanup
		if(WindowFlag) KillGLWindow();

    }


	// WrapUp
    _Module.Term();
    CoUninitialize();
    return nRet;
}