Exemplo n.º 1
0
__declspec(dllexport) void ShowDiscoveryDialogEx(IDispatch* pDocument, HWND hParent)
{
	try
	{
		::CoInitialize( 0 );

		try
		{
			CMWDiscovery discovery(pDocument);
			if(hParent)
			{
				discovery.m_hwnd = hParent;
			}

			discovery.SetHelpFile(CGeneral::DefaultHelpFileTitle( AppWorkshare ));
			discovery.DisplayDiscovery();	
		}
		catch(Workshare::Exception& e)
		{
			LOG_WS_ERROR_RESULT(e);
		}
		catch(_com_error& e)
		{
			LOG_WS_ERROR_RESULT(e);
		}
		catch(...)
		{
			LogUnexpected();
		}
		
		CoFreeUnusedLibraries();
		::CoUninitialize();
	}
	catch(Workshare::Exception& e)
	{
		LOG_WS_ERROR_RESULT(e);
	}
	catch(_com_error& e)
	{
		LOG_WS_ERROR_RESULT(e);
	}
	catch(...)
	{
		LogUnexpected();
	}
}
Exemplo n.º 2
0
//
// DllUnregisterServer
//
STDAPI DllUnregisterServer()
{
	CoInitialize(0);

	IFilterMapper2 *fm = NULL;

	HRESULT hr = CoCreateInstance(CLSID_FilterMapper2, NULL, CLSCTX_INPROC_SERVER, IID_IFilterMapper2,(LPVOID*)&fm);
	if( FAILED(hr) ) {
		CoFreeUnusedLibraries();
		CoUninitialize();
		return AMovieDllRegisterServer2(FALSE);
	}

	fm->UnregisterFilter(&CLSID_VideoInputDeviceCategory, g_videoName, CLSID_OpenNIVideo);

	return AMovieDllRegisterServer2(FALSE);
} // DllUnregisterServer
Exemplo n.º 3
0
CShellExtensionInterface::~CShellExtensionInterface()
{
	if (m_shellExtension)
	{
		((IUnknown*)m_shellExtension)->Release();
		CoFreeUnusedLibraries();
	}

	if (m_hMapping)
		CloseHandle(m_hMapping);

	if (m_hMutex)
		CloseHandle(m_hMutex);

	if (m_dragDirectory != _T(""))
		RemoveDirectory(m_dragDirectory);
}
Exemplo n.º 4
0
void AFXAPI AfxOleTermOrFreeLib(BOOL bTerm, BOOL bJustRevoke)
{
	if (bTerm)
	{
		AfxOleTerm(bJustRevoke);
	}
	else
	{
		// only call CoFreeUnusedLibraries if one minute has gone by
		static DWORD lTickCount = GetTickCount();
		if (GetTickCount() - lTickCount > 60000)
		{
			CoFreeUnusedLibraries();
			lTickCount = GetTickCount();
		}
	}
}
void SetDesktopWallPaper(LPWSTR wallpaper)
{
	CoInitialize(NULL);   
    
	IActiveDesktop   *pDesk;   
	if(   S_OK   !=   CoCreateInstance   (   CLSID_ActiveDesktop,   NULL,   CLSCTX_INPROC_SERVER,   IID_IActiveDesktop,   (void**)   &pDesk   )   )   
	{ 
	  pDesk->Release();
	  return ;
	}   
	pDesk->SetWallpaper(wallpaper,0);
	WALLPAPEROPT wallpaperopt;
	wallpaperopt.dwSize = sizeof(WALLPAPEROPT);
	wallpaperopt.dwStyle = WPSTYLE_CENTER;
	pDesk->SetWallpaperOptions(&wallpaperopt,0);
	pDesk->ApplyChanges(AD_APPLY_ALL);
	pDesk->Release();
	CoFreeUnusedLibraries();   
	CoUninitialize();  
}
Exemplo n.º 6
0
HRESULT WINAPI AMovieDllRegisterServer2(BOOL bRegister)
{
    HRESULT hr;
    int i;
    IFilterMapper2 *pIFM2 = NULL;
    WCHAR szFileName[MAX_PATH];

    if (!GetModuleFileNameW(g_hInst, szFileName, MAX_PATH))
    {
        ERR("Failed to get module file name for registration\n");
        return E_FAIL;
    }

    if (bRegister)
        hr = SetupRegisterAllClasses(g_Templates, g_cTemplates, szFileName, TRUE );

    hr = CoInitialize(NULL);

    TRACE("Getting IFilterMapper2\r\n");
    hr = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC_SERVER,
                          &IID_IFilterMapper2, (void **)&pIFM2);

    for (i = 0; SUCCEEDED(hr) && i < g_cTemplates; i++)
        hr = AMovieSetupRegisterFilter2(g_Templates[i].m_pAMovieSetup_Filter, pIFM2, bRegister);

    /* release interface */
    if (pIFM2)
        IFilterMapper2_Release(pIFM2);

    /* and clear up */
    CoFreeUnusedLibraries();
    CoUninitialize();

    /* if unregistering, unregister all OLE servers */
    if (SUCCEEDED(hr) && !bRegister)
        hr = SetupRegisterAllClasses(g_Templates, g_cTemplates, szFileName, FALSE);

    return hr;
}
Exemplo n.º 7
0
void AFXAPI AfxOleTermOrFreeLib(BOOL bTerm, BOOL bJustRevoke)
{
	if (bTerm)
	{
		AfxOleTerm(bJustRevoke);
	}
	else
	{
		// initialize _afxTickCount if necessary
		if (!_afxTickInit)
		{
			_afxTickCount = ::GetTickCount();
			++_afxTickInit;
		}

		// only call CoFreeUnusedLibraries if one minute has gone by
		if (GetTickCount() - _afxTickCount > 60000)
		{
			CoFreeUnusedLibraries();
			_afxTickCount = ::GetTickCount();
		}
	}
}
Exemplo n.º 8
0
// Cmyadsk 成员函数
BOOL Cmyadsk::SetWallPaper(LPWSTR strPicFile, DWORD dwStyle)
{
  HRESULT hr;
  IActiveDesktop* pIAD;
	//创建接口的实例
  hr = CoCreateInstance ( CLSID_ActiveDesktop,  NULL, CLSCTX_INPROC_SERVER,       
              IID_IActiveDesktop, (void**) &pIAD );
  if(!SUCCEEDED(hr)) return FALSE;
  //将文件名改为宽字符串,这是IActiveDesktop::SetWallpaper的要求
  //WCHAR   wszWallpaper [MAX_PATH];
  //LPTSTR lpStr = strPicFile.GetBuffer(strPicFile.GetLength() );
  //MultiByteToWideChar(CP_ACP, 0, lpStr, -1, wszWallpaper, MAX_PATH);
  //strPicFile.ReleaseBuffer();
  //设置墙纸
  hr = pIAD->SetWallpaper(strPicFile, 0);
  if(!SUCCEEDED(hr)) return FALSE;
  //设置墙纸的样式
  WALLPAPEROPT wpo;
  wpo.dwSize = sizeof(wpo);
  wpo.dwStyle = dwStyle;
  hr = pIAD->SetWallpaperOptions(&wpo, 0);
  if(!SUCCEEDED(hr)) return FALSE;
  //应用墙纸的设置
  hr = pIAD->ApplyChanges(AD_APPLY_ALL);
  if(!SUCCEEDED(hr)) return FALSE;
  //读取墙纸的文件名并打印在debug窗口内
  //LPWSTR aa;
  //hr = pIAD->GetWallpaper(aa, MAX_PATH, 0);
  //CString strFile = aa;
  //TRACE(strFile); //如果不用位图的话,这里有你意想不到的发现
  //释放接口的实例
  pIAD->Release();
  CoFreeUnusedLibraries();     
  CoUninitialize();
  return TRUE;
}
Exemplo n.º 9
0
STDAPI
AMovieDllRegisterServer2( BOOL bRegister )
{
  HRESULT hr = NOERROR;

  DbgLog((LOG_TRACE, 2, TEXT("AMovieDllRegisterServer2()")));

  // get file name (where g_hInst is the
  // instance handle of the filter dll)
  //
  WCHAR achFileName[MAX_PATH];

  // WIN95 doesn't support GetModuleFileNameW
  //
  {
    char achTemp[MAX_PATH];

    DbgLog((LOG_TRACE, 2, TEXT("- get module file name")));

    // g_hInst handle is set in our dll entry point. Make sure
    // DllEntryPoint in dllentry.cpp is called
    ASSERT(g_hInst != 0);

    if( 0 == GetModuleFileNameA( g_hInst
                              , achTemp
                              , sizeof(achTemp) ) )
    {
      // we've failed!
      DWORD dwerr = GetLastError();
      return AmHresultFromWin32(dwerr);
    }

    MultiByteToWideChar( CP_ACP
                       , 0L
                       , achTemp
                       , lstrlenA(achTemp) + 1
                       , achFileName
                       , NUMELMS(achFileName) );
  }

  //
  // first registering, register all OLE servers
  //
  if( bRegister )
  {
    DbgLog((LOG_TRACE, 2, TEXT("- register OLE Servers")));
    hr = RegisterAllServers( achFileName, TRUE );
  }

  //
  // next, register/unregister all filters
  //

  if( SUCCEEDED(hr) )
  {
    // init is ref counted so call just in case
    // we're being called cold.
    //
    DbgLog((LOG_TRACE, 2, TEXT("- CoInitialize")));
    hr = CoInitialize( (LPVOID)NULL );
    ASSERT( SUCCEEDED(hr) );

    // get hold of IFilterMapper2
    //
    DbgLog((LOG_TRACE, 2, TEXT("- obtain IFilterMapper2")));
    IFilterMapper2 *pIFM2 = 0;
    IFilterMapper *pIFM = 0;
    hr = CoCreateInstance( CLSID_FilterMapper2
                         , NULL
                         , CLSCTX_INPROC_SERVER
                         , IID_IFilterMapper2
                         , (void **)&pIFM2       );
    if(FAILED(hr))
    {
        DbgLog((LOG_TRACE, 2, TEXT("- trying IFilterMapper instead")));

        hr = CoCreateInstance(
            CLSID_FilterMapper,
            NULL,
            CLSCTX_INPROC_SERVER,
            IID_IFilterMapper,
            (void **)&pIFM);
    }
    if( SUCCEEDED(hr) )
    {
      // scan through array of CFactoryTemplates
      // registering servers and filters.
      //
      DbgLog((LOG_TRACE, 2, TEXT("- register Filters")));
      for( int i = 0; i < g_cTemplates; i++ )
      {
        // get i'th template
        //
        const CFactoryTemplate *pT = &g_Templates[i];

        if( NULL != pT->m_pAMovieSetup_Filter )
        {
          DbgLog((LOG_TRACE, 2, TEXT("- - register %ls"), (LPCWSTR)pT->m_Name ));

          if(pIFM2)
          {
              hr = AMovieSetupRegisterFilter2( pT->m_pAMovieSetup_Filter, pIFM2, bRegister );
          }
          else
          {
              hr = AMovieSetupRegisterFilter( pT->m_pAMovieSetup_Filter, pIFM, bRegister );
          }
        }

        // check final error for this pass
        // and break loop if we failed
        //
        if( FAILED(hr) )
          break;
      }

      // release interface
      //
      if(pIFM2)
          pIFM2->Release();
      else
          pIFM->Release();

    }

    // and clear up
    //
    CoFreeUnusedLibraries();
    CoUninitialize();
  }

  //
  // if unregistering, unregister all OLE servers
  //
  if( SUCCEEDED(hr) && !bRegister )
  {
    DbgLog((LOG_TRACE, 2, TEXT("- register OLE Servers")));
    hr = RegisterAllServers( achFileName, FALSE );
  }

  DbgLog((LOG_TRACE, 2, TEXT("- return %0x"), hr));
  return hr;
}
Exemplo n.º 10
0
/****************************************************************************
 * SetupRegisterServers
 *
 * This function is table driven using the static members of the
 * CFactoryTemplate class defined in the Dll.
 *
 * It registers the Dll as the InprocServer32 for all the classes in
 * CFactoryTemplate
 *
 ****************************************************************************/
HRESULT SetupRegisterServers(const CFactoryTemplate * pList, int num,
                             HINSTANCE hinst, BOOL bRegister)
{
    HRESULT hr = NOERROR;
    WCHAR szFileName[MAX_PATH];
    IFilterMapper2 *pIFM2 = NULL;
    IFilterMapper *pIFM = NULL;

    /* Win95 wouldn't support the Unicode version of this API!! */
    if (!GetModuleFileNameW(hinst, szFileName, MAX_PATH))
        return HRESULT_FROM_WIN32(GetLastError());

    /* first register all server classes, just to make sure */
    if (bRegister)
        hr = SetupRegisterAllClasses(pList, num, szFileName, TRUE );

    /* next, register/unregister all filters */
    if (SUCCEEDED(hr))
    {
        hr = CoInitialize(NULL);

        TRACE("Getting IFilterMapper2\r\n");
        hr = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC_SERVER,
                              &IID_IFilterMapper2, (void **)&pIFM2);
        if (FAILED(hr))
        {
            TRACE("- trying IFilterMapper instead\r\n");

            hr = CoCreateInstance(&CLSID_FilterMapper, NULL, CLSCTX_INPROC_SERVER,
                                  &IID_IFilterMapper, (void **)&pIFM);
        }

        if (SUCCEEDED(hr))
        {
            int i;
            
            /* scan through array of CFactoryTemplates registering all filters */
            for (i = 0; i < num; i++, pList++)
            {
                if (NULL != pList->m_pAMovieSetup_Filter)
                {
                    if (pIFM2)
                        hr = SetupRegisterFilter2(pList->m_pAMovieSetup_Filter,
                                                  pIFM2, bRegister);
                    else
                        hr = SetupRegisterFilter(pList->m_pAMovieSetup_Filter,
                                                 pIFM, bRegister);
                }

                /* check final error for this pass and break loop if we failed */
                if (FAILED(hr))
                    break;
            }

            /* release interface */
            if (pIFM2)
                IFilterMapper2_Release(pIFM2);
            else
                IFilterMapper_Release(pIFM);
        }

        /* and clear up */
        CoFreeUnusedLibraries();
        CoUninitialize();
    }

    /* if unregistering, unregister all OLE servers */
    if (SUCCEEDED(hr) && !bRegister)
        hr = SetupRegisterAllClasses(pList, num, szFileName, FALSE);
    return hr;
}
Exemplo n.º 11
0
BOOL CWSConfigAssistantApp::InitInstance()
{
    CLimitSingleInstance lsi(SINGLE_INSTANCE_MUTEX_NAME);
    if ( lsi.IsAnotherInstanceRunning() )
    {
        MessageBox(NULL, _T("An instance of Workshare Configuration Assistant is already running. Please close that to run another instance."), _T("Workshare"), MB_OK | MB_ICONWARNING);
        return FALSE;
    }

    if( m_pInstallAgent )
    {
        m_pInstallAgent->Initialize();

        // workaround for imanage f*****g up our current path
        // stores path internally.
        m_pInstallAgent->GetInstallDir();
    }

    // Ensure Windows Message box displayed when can not load Workshare Message component has correct title
    free((void*)m_pszAppName);
    m_pszAppName =_tcsdup(_T("Workshare Configuration Assistant"));

    CStdString sCmdLine(GetCommandLine());
    sCmdLine.MakeLower();

    bool bRunTests(sCmdLine.Find(_T("runtests")) != -1);
    bool bAutoRunTests(sCmdLine.Find(_T("autoruntests")) != -1);
    bool bRunFunctionalTests(sCmdLine.Find(_T("functionaltests")) != -1);

    if(bRunTests)
    {
        m_iRetCode = RunAppTestsEx(bAutoRunTests, bRunFunctionalTests, false, _T(""), false);
        CoFreeUnusedLibraries();
        return FALSE;
    }

    if( m_pInstallAgent && !m_pInstallAgent->WasCommandLineValid())
    {
        AfxMessageBox(m_pInstallAgent->GetCommandLineHelp(),MB_OK);
        return FALSE;
    }

    if(m_pInstallAgent && m_pInstallAgent->IsQuiet())
    {
        if(GetInstallAgent())
            GetInstallAgent()->LogEvent(_T("CWSConfigAssistantApp::OnInitDialog - Quiet Silent version of the application."));

        SafeDeleteSingleItem(m_pInstallAgent);
        m_pInstallAgent = NULL;

        CQuietProgressDlg dlg;
        dlg.DoModal();
        m_iRetCode = dlg.GetResult();
    }
    else if (!IsSilent())
    {
        if(GetInstallAgent())
            GetInstallAgent()->LogEvent(_T("CWSConfigAssistantApp::OnInitDialog - Running UI version of the application."));

        CWSConfigAssistantDlg dlg(_T("Workshare"));
        dlg.SetWizardMode();
        m_pMainWnd = &dlg;

        if( ::IsWindow(dlg.m_hWnd) )
            dlg.SetWindowPos(&CWnd::wndTop, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);

        INT_PTR ret = dlg.DoModal();
        if (ret == IDCANCEL)
        {
            m_iRetCode = 1602;
        }
    }
    else
    {
        if(GetInstallAgent())
            GetInstallAgent()->LogEvent(_T("CWSConfigAssistantApp::OnInitDialog - Running Silent version of the application."));

        SafeDeleteSingleItem(m_pInstallAgent);
        m_pInstallAgent = NULL;

        CStdString sResult;
        m_iRetCode = InstallAgent::Run(GetCommandLine(), sResult);
    }

    return FALSE;
}
Exemplo n.º 12
0
/***********************************************************************
 *           CoFreeUnusedLibraries [COMPOBJ.17]
 */
void WINAPI CoFreeUnusedLibraries16(void)
{
    CoFreeUnusedLibraries();
}
Exemplo n.º 13
0
void _EnableIntegration (BOOL bEnable, DWORD dwReserved)
{
    HRESULT hr = CoInitialize (NULL);
    char sz [MAX_PATH];

    if (bEnable)
    {
        IFdmUplShellExtsPtr spExts;
        spExts.CreateInstance (__uuidof (FdmUplShellExts));

        if (spExts == NULL)
        {
            _pDllCaller->GetCommonFilesFolder (sz);
            lstrcat (sz, "fumshext.dll");
            HMODULE hDll = LoadLibrary (sz);
            if (hDll != NULL)
            {
                typedef HRESULT (_stdcall *FNDRUS)(void);
                FNDRUS pfn;
                pfn = (FNDRUS)GetProcAddress (hDll, "DllRegisterServer");
                if (pfn)
                    pfn ();
                FreeLibrary (hDll);
            }
            spExts.CreateInstance (__uuidof (FdmUplShellExts));
        }

        if (spExts != NULL)
        {
            spExts->put_ShowInExplorerContextMenu (bEnable);
            spExts->put_ShowInSendToContextMenu (bEnable);
            spExts = NULL;
        }
    }
    else
    {
        _pDllCaller->GetCommonFilesFolder (sz);
        lstrcat (sz, "fumshext.dll");
        HMODULE hDll = LoadLibrary (sz);
        if (hDll != NULL)
        {
            typedef HRESULT (_stdcall *FNDRUS)(void);
            FNDRUS pfn;
            pfn = (FNDRUS)GetProcAddress (hDll, "DllUnregisterServer");
            if (pfn)
                pfn ();
            FreeLibrary (hDll);
        }
    }

    CRegKey key;
    key.Open (HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Run");

    if (bEnable)
    {
        char sz [MAX_PATH];
#ifdef _DEBUG
        lstrcpy (sz, "E:\\VCW\\FDM\\FDM\\Uploader\\UploadContextMenu\\UploadOeMenu\\InjApp\\Debug\\fumoei.exe");
#else
        _pDllCaller->GetCommonFilesFolder (sz);
        lstrcat (sz, "fumoei.exe");
#endif

        ASSERT (GetFileAttributes (sz) != DWORD (-1));
        if (key.m_hKey)
            key.SetValue (sz, "Free Uploader Oe Integration");
        ShellExecute (0, "open", sz, 0, 0, SW_SHOW);
    }
    else
    {
        HANDLE h = CreateEvent (NULL, TRUE, FALSE, "fum - oe - injapp");
        SetEvent (h);
        CloseHandle (h);
        if (key.m_hKey)
            key.DeleteValue ("Free Uploader Oe Integration");
    }


    _pDllCaller->GetCommonFilesFolder (sz);
    lstrcat (sz, "fumiebtn.dll");
    HMODULE hDll = LoadLibrary (sz);
    if (hDll != NULL)
    {
        typedef HRESULT (_stdcall *FNDRUS)(void);
        FNDRUS pfn;
        pfn = (FNDRUS)GetProcAddress (hDll, bEnable ? "DllRegisterServer" : "DllUnregisterServer");
        if (pfn)
            pfn ();
        FreeLibrary (hDll);
        CoFreeUnusedLibraries ();
    }


    if (SUCCEEDED (hr))
        CoUninitialize ();
}
Exemplo n.º 14
0
HRESULT DoTests
	(
	)
{
	IDBInitialize*	    pIDBInitialize 	= NULL;
    IOpenRowset*        pIOpenRowset    = NULL;
    IRowset*		    pIRowset		= NULL;
	LPWSTR			    pwszTableName   = 	L"customer.csv";
	HRESULT			    hr;


	hr = GetSampprovDataSource( &pIDBInitialize );
	if (FAILED(hr))
	{
		DUMP_ERROR_LINENUMBER();
		DumpErrorHResult( hr, "GetSampprovDataSource" );
		goto error;
	}

	hr = GetDBSessionFromDataSource( pIDBInitialize, &pIOpenRowset );
	if (FAILED(hr))
	{
		DUMP_ERROR_LINENUMBER();
		DumpErrorHResult( hr, "GetDBSessionFromDataSource" );
		goto error;
	}

	pIDBInitialize->Release();
	pIDBInitialize = NULL;    

	hr = GetRowsetFromDBSession( pIOpenRowset, pwszTableName, &pIRowset );
	if (FAILED(hr))
	{
		DUMP_ERROR_LINENUMBER();
		DumpErrorHResult( hr, "GetRowsetFromDBCreateSession" );
		goto error;
	}

    pIOpenRowset->Release();
    pIOpenRowset = NULL;    

	hr = GetDataFromRowset( pIRowset );
	if (FAILED(hr))
	{
		DUMP_ERROR_LINENUMBER();
		DumpErrorHResult( hr, "GetDataFromRowset" );
		goto error;
	}
	pIRowset->Release(); 
	pIRowset = NULL;
	CoFreeUnusedLibraries();

	DumpStatusMsg( "\nDone! ");
	printf("\n\nFor more data from this run, see the log file sampclnt.out\n" );	
	return ResultFromScode( S_OK );
    
error:    
	if (pIRowset) 
		pIRowset->Release();
    if (pIOpenRowset)
        pIOpenRowset->Release();    
    if (pIDBInitialize)
    	pIDBInitialize->Release();	    
	
	return ResultFromScode( hr );
}						    
Exemplo n.º 15
0
/****************************************************************************
 * SetupRegisterServers
 *
 * This function is table driven using the static members of the
 * CFactoryTemplate class defined in the Dll.
 *
 * It registers the Dll as the InprocServer32 for all the classes in
 * CFactoryTemplate
 *
 ****************************************************************************/
HRESULT SetupRegisterServers(const CFactoryTemplate * pList, int num,
                             BOOL bRegister)
{
    static const WCHAR szFileName[] = {'q','c','a','p','.','d','l','l',0};
    HRESULT hr = NOERROR;
    IFilterMapper2 *pIFM2 = NULL;
    IFilterMapper *pIFM = NULL;

    /* first register all server classes, just to make sure */
    if (bRegister)
        hr = SetupRegisterAllClasses(pList, num, szFileName, TRUE );

    /* next, register/unregister all filters */
    if (SUCCEEDED(hr))
    {
        hr = CoInitialize(NULL);

        TRACE("Getting IFilterMapper2\r\n");
        hr = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC_SERVER,
                              &IID_IFilterMapper2, (void **)&pIFM2);
        if (FAILED(hr))
        {
            TRACE("- trying IFilterMapper instead\r\n");

            hr = CoCreateInstance(&CLSID_FilterMapper, NULL, CLSCTX_INPROC_SERVER,
                                  &IID_IFilterMapper, (void **)&pIFM);
        }

        if (SUCCEEDED(hr))
        {
            int i;
            
            /* scan through array of CFactoryTemplates registering all filters */
            for (i = 0; i < num; i++, pList++)
            {
                if (NULL != pList->m_pAMovieSetup_Filter)
                {
                    if (pIFM2)
                        hr = SetupRegisterFilter2(pList->m_pAMovieSetup_Filter,
                                                  pIFM2, bRegister);
                    else
                        hr = SetupRegisterFilter(pList->m_pAMovieSetup_Filter,
                                                 pIFM, bRegister);
                }

                /* check final error for this pass and break loop if we failed */
                if (FAILED(hr))
                    break;
            }

            /* release interface */
            if (pIFM2)
                IFilterMapper2_Release(pIFM2);
            else
                IFilterMapper_Release(pIFM);
        }

        /* and clear up */
        CoFreeUnusedLibraries();
        CoUninitialize();
    }

    /* if unregistering, unregister all OLE servers */
    if (SUCCEEDED(hr) && !bRegister)
        hr = SetupRegisterAllClasses(pList, num, szFileName, FALSE);
    return hr;
}
Exemplo n.º 16
0
/*F+F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F
  Function: WinMain

  Summary:  The Windows main entry point function for this application.
            Initializes the application, the OLE Libraries, and starts
            the main application message loop.

  Args:     HINSTANCE hInstance,
              Instance handle; a new one for each invocation of this app.
            HINSTANCE hPrevInstance,
              Instance handle of the previous instance. NULL in Win32.
            LPSTR lpCmdLine,
              Windows passes a pointer to the application's
              invocation command line.
            int nCmdShow)
              Bits telling the show state of the application.

  Returns:  int
              msg.wParam (upon exit of message loop).
              FALSE if this instance couldn't initialize and run.
F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F-F*/
extern "C" int PASCAL WinMain(
    HINSTANCE hInstance,
    HINSTANCE ,
    LPSTR ,
    int nCmdShow)
{
    CMainWindow* pWin = NULL;
    MSG msg;
    HACCEL hAccel = NULL;
    int iRun = FALSE;

    // If we were compiled for UNICODE and the platform seems OK with this
    // then proceed.  Else we error and exit the app.
    if (UnicodeOk())
    {
        // Call to initialize the OLE COM Library.  Use the OLE SUCCEEDED macro
        // to detect success.  If fail then exit app with error message.
        // Tell COM that this client process and all subordinate threads
        // will live in a multi-threaded world. This means that all subsequent
        // COM objects created and functioned by this client must be coded
        // to be thread-safe. This is where we tell COM that we are using
        // the "Free-threading" model (rather than the default Apartment Model).
        if (SUCCEEDED(CoInitializeEx(NULL, COINIT_MULTITHREADED)))
        {
            // If we succeeded in initializing the COM Library we proceed to
            // initialize the application.  If we can't init the application
            // then we signal shut down with an error message exit.
            iRun = InitApplication(hInstance);
            if (iRun)
            {
                // Assume we'll set iRun to TRUE when initialization is done.
                iRun = FALSE;
                // We are still go for running so we try to create a nifty new
                // CMainWindow object for this app instance.
                pWin = new CMainWindow;
                if (NULL != pWin)
                {
                    // Now we initialize an instance of the new CMainWindow.
                    // This includes creating the main window.  Note: if
                    // InitInstance fails then it would have already deleted
                    // pWin so we wouldn't need to delete it here.
                    if (pWin->InitInstance(hInstance, nCmdShow))
                    {
                        // Load the keyboard accelerators from the resources.
                        hAccel = LoadAccelerators(hInstance, TEXT("AppAccel"));
                        if (NULL != hAccel)
                        {
                            // Signal App Initialization is successfully done.
                            iRun = TRUE;
                        }
                    }
                }
            }

            if (iRun)
            {
                // If we initialized the app instance properly then we are still
                // go for running.  We then start up the main message pump for
                // the application.
                while (GetMessage(&msg, NULL, 0, 0))
                {
                    if (!TranslateAccelerator(pWin->GetHwnd(), hAccel, &msg))
                    {
                        TranslateMessage(&msg);
                        DispatchMessage(&msg);
                    }
                }

                // We also ask COM to unload any unused COM Servers, including our
                // friend, FRESERVE.
                CoFreeUnusedLibraries();

                // We'll pass to Windows the reason why we exited the message loop.
                iRun = (int) msg.wParam;
            }
            else
            {
                // We failed to initialize the application--issue an error
                // messagebox.
                TCHAR szMsg[MAX_STRING_LENGTH];

                // Load the error message string from the resources.
                if (LoadString(
                            hInstance,
                            IDS_APPINITFAILED,
                            szMsg,
                            MAX_STRING_LENGTH))
                {
                    // Put up error message box saying that application couldn't be
                    // initialized.  Parent window is desktop (ie, NULL).
                    MessageBox(
                        NULL,
                        szMsg,
                        TEXT(ERROR_TITLE_STR),
                        MB_OK | MB_ICONEXCLAMATION);
                }
                delete pWin;
            }

            // We're exiting this app (either normally or by init failure) so
            // shut down the OLE COM Library.
            CoUninitialize();
        }
        else
        {
            // We failed to Initialize the OLE COM Library.
            TCHAR szMsg[MAX_STRING_LENGTH];

            // Load the error message string from the resources.
            if (LoadString(
                        hInstance,
                        IDS_OLEINITFAILED,
                        szMsg,
                        MAX_STRING_LENGTH))
            {
                // Put up error message box saying that OLE COM Library
                // couldn't be initialized.  Parent window is desktop (ie, NULL).
                // And exit the failed application.
                MessageBox(
                    NULL,
                    szMsg,
                    TEXT(ERROR_TITLE_STR),
                    MB_OK | MB_ICONEXCLAMATION);
            }
        }
    }
    else
    {
        // If we were compiled for UNICODE but the platform has problems with
        // this then indicate an error and exit the app immediately.
        CHAR szMsg[MAX_STRING_LENGTH];

        if (LoadStringA(
                    hInstance,
                    IDS_NOUNICODE,
                    szMsg,
                    MAX_STRING_LENGTH))
        {
            MessageBoxA(
                NULL,
                szMsg,
                ERROR_TITLE_STR,
                MB_OK | MB_ICONEXCLAMATION);
        }
    }

    return iRun;
}