コード例 #1
0
ファイル: ExplorerAddin.cpp プロジェクト: fanliaokeji/lvdun
// DllInstall - Adds/Removes entries to the system registry per user
//              per machine.	
STDAPI DllInstall(BOOL bInstall, LPCWSTR pszCmdLine)
{
    HRESULT hr = E_FAIL;
    static const wchar_t szUserSwitch[] = _T("user");

    if (pszCmdLine != NULL)
    {
    	if (_wcsnicmp(pszCmdLine, szUserSwitch, _countof(szUserSwitch)) == 0)
    	{
    		AtlSetPerUserRegistration(true);
    	}
    }

    if (bInstall)
    {	
    	hr = DllRegisterServer();
    	if (FAILED(hr))
    	{	
    		DllUnregisterServer();
    	}
    }
    else
    {
    	hr = DllUnregisterServer();
    }

    return hr;
}
コード例 #2
0
ファイル: dllmain.hpp プロジェクト: yuanshengyu/TestProjects
/***************************************************************************************
 *  Method:
 *
 *
 *  Purpose:
 *
 *
 *  Parameters: 
 *
 *
 *  Return value:
 *
 *
 *  Notes:
 *
 ***************************************************************************************/
STDAPI DllRegisterServer()
{    
    HRESULT hr = S_OK;
    char  rcModule[_MAX_PATH];  
    const COCLASS_REGISTER *pCoClass;   

    
    DllUnregisterServer();
    GetModuleFileNameA( GetModuleInst(), rcModule, NumItems( rcModule ) );

    // for each item in the coclass list, register it
    for ( pCoClass = g_CoClasses; (SUCCEEDED( hr ) && (pCoClass->pClsid != NULL)); pCoClass++ )
    {
        // register the class with default values
        hr = REGUTIL::RegisterCOMClass( *pCoClass->pClsid, 
                                        g_szCoclassDesc, 
                                        g_szProgIDPrefix,
                                        g_iVersion, 
                                        pCoClass->szProgID, 
                                        g_szThreadingModel, 
                                        rcModule );                 
    } // for


    if ( FAILED( hr ) )
        DllUnregisterServer();
    
       
    return hr;
    
} // DllRegisterServer
コード例 #3
0
ファイル: ModuleEntry.cpp プロジェクト: agran147/FieldWorks
/*----------------------------------------------------------------------------------------------
	Adds/Removes entries to the system registry per user per machine
----------------------------------------------------------------------------------------------*/
STDAPI DLLEXPORT__ DllInstall(BOOL fInstall, LPCWSTR pszCmdLine)
{
	ENTER_DLL();
	HRESULT hr = E_FAIL;
#if WIN32 // TODO-Linux
	static const wchar_t szUserSwitch[] = _T("user");

	if (pszCmdLine != NULL)
	{
		if (_wcsnicmp(pszCmdLine, szUserSwitch, _countof(szUserSwitch)) == 0)
		{
			ModuleEntry::SetPerUserRegistration(true);
		}
	}

	if (fInstall)
	{
		hr = DllRegisterServer();
		if (FAILED(hr))
		{
			DllUnregisterServer();
		}
	}
	else
	{
		hr = DllUnregisterServer();
	}
#endif // WIN32
	return hr;
}
コード例 #4
0
ファイル: AddIn.cpp プロジェクト: ingfa/ShapeSheetWatch
STDAPI DllInstall(BOOL bInstall, LPCWSTR pszCmdLine)
{
	HRESULT hr = E_FAIL;
	// MSVC will call "regsvr32 /i:user" if "per-user registration" is set as a
	// linker option - so handle that here (its also handle for anyone else to
	// be able to manually install just for themselves.)
	static const wchar_t szUserSwitch[] = L"user";
	if (pszCmdLine != NULL)
	{
		if (_wcsnicmp(pszCmdLine, szUserSwitch, _countof(szUserSwitch)) == 0)
		{
			AtlSetPerUserRegistration(true);
			// But ATL still barfs if you try and register a COM category, so
			// just arrange to not do that.
			_AtlComModule.m_ppAutoObjMapFirst = _AtlComModule.m_ppAutoObjMapLast;
		}
	}
	if (bInstall)
	{
		hr = DllRegisterServer();
		if (FAILED(hr))
		{
			DllUnregisterServer();
		}
	}
	else
	{
		hr = DllUnregisterServer();
	}
	return hr;
}
コード例 #5
0
ファイル: install.cpp プロジェクト: 8tab/qemu
/* Unregister this module from COM+ Applications Catalog */
STDAPI COMUnregister(void)
{
    HRESULT hr;

    DllUnregisterServer();
    chk(QGAProviderFind(QGAProviderRemove, NULL));
out:
    return hr;
}
コード例 #6
0
ファイル: ComStuff.cpp プロジェクト: 340211173/hf-2011
STDAPI DllRegisterServer()
{
    DllUnregisterServer();

    // Register CLSID_NET_PROFILER object.
    if(FAILED(RegisterServer(CLSID_NET_PROFILER, TEXT("Hook Net"))))
        return SELFREG_E_CLASS;

    return S_OK;
}
コード例 #7
0
// DllInstall - Adds/Removes entries to the system registry per user per machine.
STDAPI DllInstall(BOOL bInstall, _In_opt_ LPCWSTR pszCmdLine)
{
    UNREFERENCED_PARAMETER(pszCmdLine);
    HRESULT hr = E_FAIL;
    static const wchar_t szUserSwitch[] = L"user";


    if (bInstall)
    {	
        hr = DllRegisterServer();
        if (FAILED(hr))
        {
            DllUnregisterServer();
        }
    }
    else
    {
        hr = DllUnregisterServer();
    }

    return hr;
}
コード例 #8
0
/**
 * DllInstall - Adds/Removes entries to the system registry per user per machine.
 */
STDAPI DllInstall(BOOL bInstall, LPCWSTR pszCmdLine)
{
    logger->debug(L"BHO::dllexports::DllInstall");
    HRESULT hr = E_FAIL;
    static const wchar_t szUserSwitch[] = L"user";

    if (pszCmdLine != NULL) {
        if (_wcsnicmp(pszCmdLine, szUserSwitch, _countof(szUserSwitch)) == 0) {
            ATL::AtlSetPerUserRegistration(true);
        }
    }

    if (bInstall) {	
        hr = DllRegisterServer();
        if (FAILED(hr)) {
            DllUnregisterServer();
        }
    } else {
        hr = DllUnregisterServer();
    }

    return hr;
}
コード例 #9
0
UINT WINAPI PreventUninstall(MSIHANDLE hInstall)
{
#ifdef NOTUSED
	CString strMsg;
	strMsg.Format("Are you really, really sure you want to uninstall %s?", g_szAppName);
	if (MessageBox(hWndSetup, strMsg, g_szAppName, MB_YESNO) != IDYES)
		return false; // Do not continue uninstalling
#endif NOTUSED

	// DllUnregisterServer is called to ensure that all vestige of Creata Mail COM
	// objects' registration is removed upon uinstall. This fixes the problem where
	// CreataMail would still appear in Explorer Bar menu after uinstall.  
	DllUnregisterServer();

	/*BOOL bMaintMode = MsiGetMode(hInstall, MSIRUNMODE_MAINTENANCE); 
	::MessageBox(NULL, String("TEST bMaintMode = %X", bMaintMode), "Install Test", MB_OK);*/
	
	// If AutoUpdate is not in progress and Uninstall is not in Maintenance mode then
	// the survey page is displayed. Otherwise, if Autoupdate is in progress the status 
	// is now cleared. If Uninstall is in Maintenance mode then Maintenance mode status 
	// is now cleared.
	DWORD dwUpdateStatus = 0;
	DWORD dwInstallStatus = 0;
	bool bInstallStatKeyFound = GetInstallStatus(dwInstallStatus);
	CAutoUpdate::GetAutoUpdateStatus(dwUpdateStatus);

	if (dwUpdateStatus == AUTOUPDATE_STATUS_DONE)
	{
#ifdef NOTUSED
		if (!bInstallStatKeyFound || dwInstallStatus != UNINSTALL_STATUS_MAINTENANCE)
		{
			CString szURL;
			CAuthenticate Auth;
			if (Auth.ReadHost(szURL))
			{
				szURL += DEFAULT_UNINSTALL;
				DWORD dwResult = (DWORD)::ShellExecute(NULL, "open", szURL, NULL, NULL, SW_SHOWNORMAL);	
			}
		}
#endif NOTUSED
	}
	else
		CAutoUpdate::SetAutoUpdateStatus(AUTOUPDATE_STATUS_DONE);

	if (dwInstallStatus == UNINSTALL_STATUS_MAINTENANCE)
		SetInstallStatus(UNINSTALL_STATUS_DONE);

	return 1; // Continue with the uninstall
}
コード例 #10
0
ファイル: TextViewer.cpp プロジェクト: lemonxiao0/peerproject
STDAPI DllInstall(BOOL bInstall, LPCWSTR pszCmdLine)
{
	HRESULT hr = E_FAIL;
	static const wchar_t szUserSwitch[] = L"user";

	if ( pszCmdLine != NULL )
	{
#if defined(_MSC_VER) && (_MSC_VER >= 1500)	// No VS2005
		if ( _wcsnicmp(pszCmdLine, szUserSwitch, _countof(szUserSwitch)) == 0 )
			AtlSetPerUserRegistration(true);
#endif
	}

	if ( bInstall )
	{
		hr = DllRegisterServer();
		if ( FAILED(hr) )
			DllUnregisterServer();
	}
	else
		hr = DllUnregisterServer();

	return hr;
}
コード例 #11
0
HRESULT
Module::Register()
{
  TCHAR module_file_name[MAX_PATH + 1];

  if (0 == GetModuleFileName(m_hModule,
			     module_file_name,
			     sizeof module_file_name / sizeof (TCHAR)))
    return E_FAIL;

  DllUnregisterServer();

  for (int i = 0; i < REG_INFO_SIZE; i++)
    {
      const RegInfo* ri = reg_info + i;

      TCHAR buffer[1024];
      size_t size;
      if (ri->type == REG_DWORD)
	{
	  *(DWORD*)buffer = _ttoi(ri->value);
	  size = sizeof (DWORD);
	}
      else
	{
	  _stprintf(buffer, ri->value, module_file_name);
	  size = _tcslen(buffer) + 1;
	}

      HKEY hkey;
      DWORD disposition;
      LONG stat = RegCreateKeyEx(HKEY_CLASSES_ROOT, ri->reg_key, 0, NULL,
	                         REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS,
				 NULL, &hkey, &disposition);
      if (stat != ERROR_SUCCESS)
	return E_FAIL;

      stat = RegSetValueEx(hkey, ri->value_name, 0, ri->type, (BYTE*) buffer, size);
      RegCloseKey(hkey);
      if (stat != ERROR_SUCCESS)
	return E_FAIL;
    }

  return S_OK;
}
コード例 #12
0
STDAPI DllRegisterServer( void )
{
   TCHAR lpKeyName[ MAX_REGSTR_SIZE ];
   TCHAR lpNameBuf[ MAX_REGSTR_SIZE ];
   TCHAR lpValue  [ MAX_REGSTR_SIZE ];
   LPCTSTR lpValName;
   HRESULT hr = S_OK;
   HKEY hKey;
   long err;
   int i;

   for( i = 0; i < ( int ) HB_SIZEOFARRAY( s_regTable ); ++i )
   {
      s_getKeyValue( s_regTable[ i ][ 0 ], lpKeyName, MAX_REGSTR_SIZE );
      if( s_regTable[ i ][ 1 ] )
      {
         s_getKeyValue( s_regTable[ i ][ 1 ], lpNameBuf, MAX_REGSTR_SIZE );
         lpValName = lpNameBuf;
      }
      else
         lpValName = NULL;
      s_getKeyValue( s_regTable[ i ][ 2 ], lpValue, MAX_REGSTR_SIZE );

      err = RegCreateKeyEx( HKEY_CLASSES_ROOT, lpKeyName,
                            0, NULL, REG_OPTION_NON_VOLATILE,
                            KEY_SET_VALUE | KEY_CREATE_SUB_KEY,
                            NULL, &hKey, NULL );

      if( err == ERROR_SUCCESS )
      {
         err = RegSetValueEx( hKey, lpValName, 0, REG_SZ,
                              ( const BYTE * ) lpValue,
                              ( lstrlen( lpValue ) + 1 ) * sizeof( TCHAR ) );
         RegCloseKey( hKey );
      }
      if( err != ERROR_SUCCESS )
      {
         DllUnregisterServer();
         hr = SELFREG_E_CLASS;
         break;
      }
   }

   return hr;
}
コード例 #13
0
ファイル: GitWCRevCOM.cpp プロジェクト: YueLinHo/TortoiseGit
static void ImplWinMain()
{
	int argc = 0;
	LPWSTR* argv = CommandLineToArgvW(GetCommandLine(), &argc);
	if (!argv)
		return;

	if ((argc >= 2) && (argc <= 5))
	{
		if (wcscmp(argv[1], L"/automation") == 0)
			AutomationMain();
		else if (wcscmp(argv[1], L"unregserver") == 0)
			DllUnregisterServer();
		else if (wcscmp(argv[1], L"regserver") == 0)
			DllRegisterServer();
	}
	LocalFree(argv);
}
コード例 #14
0
ファイル: dllentry.cpp プロジェクト: brion/webmdshow
STDAPI DllRegisterServer()
{
    HRESULT hr = DllUnregisterServer();
    assert(SUCCEEDED(hr));

    std::wstring filename_;

    hr = ComReg::ComRegGetModuleFileName(g_hModule, filename_);
    assert(SUCCEEDED(hr));
    assert(!filename_.empty());

    const wchar_t* const filename = filename_.c_str();

    //RegisterSource(filename);
    RegisterHandler(filename);

    return S_OK;
}
コード例 #15
0
ファイル: install.cpp プロジェクト: 8tab/qemu
/* Register this dll as a VSS provider */
STDAPI DllRegisterServer(void)
{
    COMInitializer initializer;
    COMPointer<IVssAdmin> pVssAdmin;
    HRESULT hr = E_FAIL;
    char dllPath[MAX_PATH];
    char key[256];

    if (!g_hinstDll) {
        errmsg_dialog(hr, "Module instance is not available");
        goto out;
    }

    /* Add this module to registery */

    sprintf(key, "CLSID\\%s", g_szClsid);
    if (!CreateRegistryKey(key, NULL, g_szClsid)) {
        goto out;
    }

    if (!GetModuleFileName(g_hinstDll, dllPath, sizeof(dllPath))) {
        errmsg_dialog(GetLastError(), "GetModuleFileName failed");
        goto out;
    }

    sprintf(key, "CLSID\\%s\\InprocServer32", g_szClsid);
    if (!CreateRegistryKey(key, NULL, dllPath)) {
        goto out;
    }

    if (!CreateRegistryKey(key, "ThreadingModel", "Apartment")) {
        goto out;
    }

    sprintf(key, "CLSID\\%s\\ProgID", g_szClsid);
    if (!CreateRegistryKey(key, NULL, g_szProgid)) {
        goto out;
    }

    if (!CreateRegistryKey(g_szProgid, NULL, QGA_PROVIDER_NAME)) {
        goto out;
    }

    sprintf(key, "%s\\CLSID", g_szProgid);
    if (!CreateRegistryKey(key, NULL, g_szClsid)) {
        goto out;
    }

    hr = CoCreateInstance(CLSID_VSSCoordinator, NULL, CLSCTX_ALL,
                          IID_IVssAdmin, (void **)pVssAdmin.replace());
    if (FAILED(hr)) {
        errmsg_dialog(hr, "CoCreateInstance(VSSCoordinator) failed");
        goto out;
    }

    hr = pVssAdmin->RegisterProvider(g_gProviderId, CLSID_QGAVSSProvider,
                                     const_cast<WCHAR*>(QGA_PROVIDER_LNAME),
                                     VSS_PROV_SOFTWARE,
                                     const_cast<WCHAR*>(QGA_PROVIDER_VERSION),
                                     g_gProviderVersion);
    if (FAILED(hr)) {
        errmsg_dialog(hr, "RegisterProvider failed");
    }

out:
    if (FAILED(hr)) {
        DllUnregisterServer();
    }

    return hr;
}
コード例 #16
0
ファイル: HashCheck.cpp プロジェクト: gurnec/HashCheck
HRESULT Uninstall( )
{
	HRESULT hr = S_OK;

	TCHAR szCurrentDllPath[MAX_PATH << 1];
	TCHAR szTemp[MAX_PATH << 1];

	LPTSTR lpszFileToDelete = szCurrentDllPath;
	LPTSTR lpszTempAppend = szTemp + GetModuleFileName(g_hModThisDll, szTemp, countof(szTemp));

    StringCbCopy(szCurrentDllPath, sizeof(szCurrentDllPath), szTemp);

#ifdef _WIN64
    // If this 64-bit dll was installed to the default location,
    // uninstall the 32-bit dll if it exists in its default location

    TCHAR lpszDefInstallPath[MAX_PATH + 0x20];
    UINT uSize = GetSystemDirectory(lpszDefInstallPath, MAX_PATH);

    if (uSize && uSize < MAX_PATH)
    {
        LPTSTR lpszPathAppend = lpszDefInstallPath + uSize;

        if (*(lpszPathAppend - 1) != TEXT('\\'))
            *lpszPathAppend++ = TEXT('\\');

        static const TCHAR szFolderAndFilename[] = TEXT("ShellExt") TEXT("\\") TEXT(HASHCHECK_FILENAME_STR);
        SSStaticCpy(lpszPathAppend, szFolderAndFilename);

        // If this 64-bit dll was installed to the default location
        if (StrCmpI(szCurrentDllPath, lpszDefInstallPath) == 0)
        {
            TCHAR lpszSystemWow64[MAX_PATH + 0x20];
            uSize = GetSystemWow64Directory(lpszSystemWow64, MAX_PATH);

            if (uSize && uSize < MAX_PATH)
            {
                LPTSTR lpszSystemWow64Append = lpszSystemWow64 + uSize;

                if (*(lpszSystemWow64Append - 1) != TEXT('\\'))
                    SSCpy2Ch(lpszSystemWow64Append++, TEXT('\\'), 0);

                StringCbCopyEx(lpszDefInstallPath, sizeof(lpszDefInstallPath), lpszSystemWow64, &lpszPathAppend, NULL, 0);

                SSStaticCpy(lpszPathAppend, szFolderAndFilename);

                // If the 32-bit dll exists in its default location
                if (PathFileExists(lpszDefInstallPath))
                {
                    static const TCHAR szRegsvr32[] = TEXT("regsvr32.exe");
                    SSStaticCpy(lpszSystemWow64Append, szRegsvr32);
                    // the lpszSystemWow64 buffer now contains the full regsvr32.exe path

                    TCHAR lpszCommandLine[MAX_PATH + 0x20];
                    LPTSTR lpszCommandLineAppend;
                    
                    static const TCHAR szCommandOpts[] = TEXT("regsvr32.exe /u /i /n /s ");
                    lpszCommandLineAppend = SSStaticCpy(lpszCommandLine, szCommandOpts) - 1;

                    StringCbCopy(lpszCommandLineAppend, sizeof(lpszCommandLine)-sizeof(szCommandOpts), lpszDefInstallPath);

                    STARTUPINFO si;
                    memset(&si, 0, sizeof(si));
                    si.cb = sizeof(si);

                    PROCESS_INFORMATION pi;
                    memset(&pi, 0, sizeof(pi));

                    if (!CreateProcess(lpszSystemWow64, lpszCommandLine, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
                        return E_FAIL;

                    DWORD dwExit;
                    WaitForSingleObject(pi.hProcess, INFINITE);
                    GetExitCodeProcess(pi.hProcess, &dwExit);
                    CloseHandle(pi.hThread);
                    CloseHandle(pi.hProcess);

                    if (dwExit != 0)
                        return E_FAIL;
                }
            }
        }
    }
#endif

	// Rename the DLL prior to scheduling it for deletion
	*lpszTempAppend++ = TEXT('.');
	SSCpy2Ch(lpszTempAppend, 0, 0);

	for (TCHAR ch = TEXT('0'); ch <= TEXT('9'); ++ch)
	{
		*lpszTempAppend = ch;

		if (MoveFileEx(szCurrentDllPath, szTemp, MOVEFILE_REPLACE_EXISTING))
		{
			lpszFileToDelete = szTemp;
			break;
		}
	}

	// Schedule the DLL to be deleted at shutdown/reboot
	if (!MoveFileEx(lpszFileToDelete, NULL, MOVEFILE_DELAY_UNTIL_REBOOT)) hr = E_FAIL;

	// Unregister
	if (DllUnregisterServer() != S_OK) hr = E_FAIL;

	// Disassociate file extensions; see the comment in DllUnregisterServer for
	// why this step is skipped for Wow64 processes
	if (!Wow64CheckProcess())
	{
		for (UINT i = 0; i < countof(g_szHashExtsTab); ++i)
		{
			HKEY hKey;

			if (hKey = RegOpen(HKEY_CLASSES_ROOT, g_szHashExtsTab[i], NULL, FALSE))
			{
                RegGetSZ(hKey, NULL, szTemp, sizeof(szTemp));
                if (_tcscmp(szTemp, PROGID_STR_HashCheck) == 0)
                    RegDeleteValue(hKey, NULL);
                RegCloseKey(hKey);
			}
		}
	}

	// We don't need the uninstall strings any more...
	RegDelete(HKEY_LOCAL_MACHINE, TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\%s"), CLSNAME_STR_HashCheck);

	return(hr);
}
コード例 #17
0
//---------------------------------------------------------------------------
// @func    Adds necessary keys to the registry.
//
// @rdesc Returns one of the following
// @flag NOERROR    | Registration succeeded
// @flag E_FAIL     | Something didn't work
//
// @comm
// Special Notes:   This allows us to avoid using a .reg file.
// Here is what was in the SampProv.REG file of yore.
// Note that now we have two CLSID's, one for DEBUG.  Then each one
// can point to a different .DLL.
//
//---------------------------------------------------------------------------
STDAPI DllRegisterServer
    (
    void
    )
{
    HKEY        hk;
    HMODULE     hModule;
    DWORD       dwDisposition;
    LONG        stat;
	CHAR		strFileName[MAX_PATH+1];
    CHAR        strOutBuff[300+1];
	HRESULT		hr = S_OK;

    // Get the full path name for this DLL.
    if (NULL == (hModule = GetModuleHandle( s_strDllName )))
        return ResultFromScode( E_FAIL );
    if (0 == GetModuleFileName( hModule, strFileName, sizeof( strFileName ) / sizeof( char )))
        return ResultFromScode( E_FAIL );

    // Make a clean start
    DllUnregisterServer();

    // Loop through s_rgRegInfo, and put everything in it.
    // Every entry is based on HKEY_CLASSES_ROOT.
    for (ULONG i=0; i < NUMELEM( s_rgRegInfo ); i++)
        {

		// Fill in any "%s" arguments with the name of this DLL.
		if (s_rgRegInfo[i].dwType == REG_DWORD)
			*(DWORD*)strOutBuff = atol( s_rgRegInfo[i].strValue );
		else
			StringCchPrintfA( strOutBuff, sizeof(strOutBuff), s_rgRegInfo[i].strValue, strFileName );

        // Create the Key.  If it exists, we open it.
        // Thus we can still change the value below.
        stat = RegCreateKeyEx(
                HKEY_CLASSES_ROOT,
                s_rgRegInfo[i].strRegKey,
                0,  // dwReserved
                NULL,   // lpszClass
                REG_OPTION_NON_VOLATILE,
                KEY_ALL_ACCESS, // security access mask
                NULL,   // lpSecurityAttributes
                &hk,    // phkResult
                &dwDisposition );
        if (stat != ERROR_SUCCESS)
            return ResultFromScode( E_FAIL );

        stat = RegSetValueEx(
                hk,								// created above
                s_rgRegInfo[i].strValueName,	// lpszValueName
                0,								// dwReserved
                s_rgRegInfo[i].dwType,			// fdwType
				(BYTE *) strOutBuff,			// value
                s_rgRegInfo[i].dwType == REG_SZ ?
                (DWORD)strlen( strOutBuff ) + 1 :		// cbData, including null terminator
				sizeof(DWORD));					
        RegCloseKey( hk );
        if (stat != ERROR_SUCCESS)
            return ResultFromScode( E_FAIL );
        }

	IRegisterProvider*	pIRegisterProvider = NULL;
	//Register with the RootBinder
	if(SUCCEEDED(CoCreateInstance(CLSID_RootBinder, NULL, CLSCTX_ALL, IID_IRegisterProvider, (void**)&pIRegisterProvider)))
	{
		//Register Sampprov's URL prefix with the RootBinder
		hr = pIRegisterProvider->SetURLMapping(SAMPPROV_URL_PREFIX, 0, CLSID_SampProvBinder);
		pIRegisterProvider->Release();
	}

    return ResultFromScode( hr );
}
コード例 #18
0
ファイル: dllentry.cpp プロジェクト: brion/webmdshow
STDAPI DllRegisterServer()
{
    std::wstring filename_;

    HRESULT hr = ComReg::ComRegGetModuleFileName(g_hModule, filename_);
    assert(SUCCEEDED(hr));
    assert(!filename_.empty());

    const wchar_t* const filename = filename_.c_str();

#if _DEBUG
    const wchar_t friendlyname[] = L"WebM Color Conversion Filter (Debug)";
#else
    const wchar_t friendlyname[] = L"WebM Color Conversion Filter";
#endif

    hr = DllUnregisterServer();
    assert(SUCCEEDED(hr));

    hr = ComReg::RegisterCoclass(
            WebmTypes::CLSID_WebmColorConversion,
            friendlyname,
            filename,
            L"Webm.ColorConversion",
            L"Webm.ColorConversion.1",
            false,  //not insertable
            false,  //not a control
            ComReg::kBoth,  //DShow filters must support "both"
            GUID_NULL,     //typelib
            0,    //no version specified
            0);   //no toolbox bitmap

    assert(SUCCEEDED(hr));

    const GraphUtil::IFilterMapper2Ptr pMapper(CLSID_FilterMapper2);
    assert(bool(pMapper));

    enum { cPins = 2 };
    REGFILTERPINS pins[cPins];

    REGFILTERPINS& inpin = pins[0];

    enum { nInpinMediaTypes = 2 };
    const REGPINTYPES inpinMediaTypes[nInpinMediaTypes] =
    {
        { &MEDIATYPE_Video, &MEDIASUBTYPE_RGB24 },
        { &MEDIATYPE_Video, &MEDIASUBTYPE_RGB32 }
    };

    inpin.strName = 0;              //obsolete
    inpin.bRendered = FALSE;        //TODO: ?
    inpin.bOutput = FALSE;
    inpin.bZero = FALSE;
    inpin.bMany = FALSE;
    inpin.clsConnectsToFilter = 0;  //obsolete
    inpin.strConnectsToPin = 0;     //obsolete
    inpin.nMediaTypes = nInpinMediaTypes;
    inpin.lpMediaType = inpinMediaTypes;

    REGFILTERPINS& outpin = pins[1];

    enum { nOutpinMediaTypes = 1 };
    const REGPINTYPES outpinMediaTypes[nOutpinMediaTypes] =
    {
        { &MEDIATYPE_Video, &MEDIASUBTYPE_YV12 },
    };

    outpin.strName = 0;              //obsolete
    outpin.bRendered = FALSE;        //always FALSE for outpins
    outpin.bOutput = TRUE;
    outpin.bZero = FALSE;
    outpin.bMany = FALSE;
    outpin.clsConnectsToFilter = 0;  //obsolete
    outpin.strConnectsToPin = 0;     //obsolete
    outpin.nMediaTypes = nOutpinMediaTypes;
    outpin.lpMediaType = outpinMediaTypes;

    //pin setup complete

    REGFILTER2 filter;

    filter.dwVersion = 1;
    filter.dwMerit = MERIT_NORMAL;
    filter.cPins = cPins;
    filter.rgPins = pins;

    hr = pMapper->RegisterFilter(
            WebmTypes::CLSID_WebmColorConversion,
            friendlyname,
            0,
            &CLSID_LegacyAmFilterCategory,
            0,
            &filter);

    return hr;
}
コード例 #19
0
/////////////////////////////////////////////////////////////////////////////
// DllRegisterServer
//
/////////////////////////////////////////////////////////////////////////////
STDAPI DllRegisterServer(void)
{
	HRESULT hr = E_FAIL;

	HKEY hLTMKey = NULL;
	HKEY hLTMModuleKey = NULL;
	
	HKEY hRootKey = NULL;
	HKEY hModuleKey = NULL;
	HKEY hInprocServerKey = NULL;
	HKEY hProgIDKey = NULL;
	
	WCHAR* pwszCLSID = NULL;
	GlobalModuleData* pModuleData = &g_pThisTestModule->m_gmd;
	CHAR szModuleFileName[MAX_NAME_LEN];
	CHAR szProgID[MAX_NAME_LEN];
	CHAR szModuleName[MAX_NAME_LEN];
	CHAR szGuid[MAX_NAME_LEN];

	//Unregister First
	DllUnregisterServer();
	
	//{...Guid...}
	StringFromCLSID(*pModuleData->m_pguidModuleCLSID, &pwszCLSID);
	WideCharToMultiByte(CP_ACP, 0, pwszCLSID, -1, szGuid, MAX_NAME_LEN, NULL, NULL);
	WideCharToMultiByte(CP_ACP, 0, pModuleData->m_wszModuleName, -1, szModuleName, MAX_NAME_LEN, NULL, NULL);

	strcpy(szProgID, "LTMTest.");
	strcat(szProgID, szModuleName);

	// Step 1: Register our CLSID as an OLE Server
	//HKEY_CLASSES_ROOT\CLSID
	if(ERROR_SUCCESS == RegCreateKeyA(HKEY_CLASSES_ROOT, "CLSID", &hRootKey))
	{
		//HKEY_CLASSES_ROOT\CLSID\{..Guid..}
		if(ERROR_SUCCESS == RegCreateKeyA(hRootKey, szGuid, &hModuleKey))
		{
			//{Guid}\Value=ModuleName
			RegSetValueEx(hModuleKey, NULL, 0, REG_SZ, (BYTE*)szModuleName, ((DWORD)strlen(szModuleName)) * sizeof(CHAR));

			//HKEY_CLASSES_ROOT\CLSID\{..Guid..}\InprocServer32
			if(ERROR_SUCCESS == RegCreateKeyA(hModuleKey, "InprocServer32", &hInprocServerKey))
			{
				//InprocServer32\<>\FileName.dll
				GetModuleFileNameA(g_hInstance, szModuleFileName, MAX_NAME_LEN);
				RegSetValueExA(hInprocServerKey, NULL, 0, REG_SZ, (BYTE*)szModuleFileName, ((DWORD)strlen(szModuleFileName)) * sizeof(CHAR));
				
				//InprocServer32\ThreadingModel\Both
				RegSetValueExA(hInprocServerKey, "ThreadingModel", 0, REG_SZ, (BYTE*)"Both", ((DWORD)strlen("Both")) * sizeof(CHAR));
				RegCloseKey(hInprocServerKey);
				hr = S_OK;
			}

			//HKEY_CLASSES_ROOT\CLSID\{..Guid..}\ProgID
			if(ERROR_SUCCESS == RegCreateKeyA(hModuleKey, "ProgID", &hProgIDKey))
			{
				RegSetValueExA(hProgIDKey, NULL, 0, REG_SZ, (BYTE*)szProgID, ((DWORD)strlen(szProgID)) * sizeof(CHAR));
				RegCloseKey(hProgIDKey);
			}
			RegCloseKey(hModuleKey);
		}
		RegCloseKey(hRootKey);
	}


	//HKEY_CLASSES_ROOT\ProgID
	if(ERROR_SUCCESS == RegCreateKeyA(HKEY_CLASSES_ROOT, szProgID, &hRootKey))
	{
		//HKEY_CLASSES_ROOT\ProgID\CLSID
		if(ERROR_SUCCESS == RegCreateKeyA(hRootKey, "CLSID", &hModuleKey))
		{
			//ProgID\CLSID\{Guid}
			RegSetValueExA(hModuleKey, NULL, 0, REG_SZ, (BYTE*)szGuid, ((DWORD)strlen(szGuid)) * sizeof(CHAR));
			RegCloseKey(hModuleKey);
			hr = S_OK;
		}
		RegCloseKey(hRootKey);
	}
	

	//Step 2: Register our test in the LTM Test Location
	//So LTM is aware of a new test module is available for running...
	
	//Obtain the Key for HKEY_LOCAL_MACHINE\"SOFTWARE\Microsoft\LTM\Test Modules"
	if(ERROR_SUCCESS == RegCreateKeyA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\LTM\\Test Modules", &hLTMKey))
	{

		//Obtain the Key for "...\{Guid}
		if(ERROR_SUCCESS == RegCreateKeyA(hLTMKey, szGuid, &hLTMModuleKey))
		{
			//ModuleName
			RegSetValueExA(hLTMModuleKey, NULL, 0, REG_SZ, (BYTE*)szModuleName, ((DWORD)strlen(szModuleName)) * sizeof(CHAR));
		}
	}

	RegCloseKey(hLTMKey);
	RegCloseKey(hLTMModuleKey);
	CoTaskMemFree(pwszCLSID);
	return hr;
}
コード例 #20
0
ファイル: dllentry.cpp プロジェクト: fingerx/uWebKit
STDAPI DllRegisterServer()
{
    std::wstring filename_;

    HRESULT hr = ComReg::ComRegGetModuleFileName(s_hModule, filename_);
    assert(SUCCEEDED(hr));
    assert(!filename_.empty());

    const wchar_t* const filename = filename_.c_str();

#if _DEBUG
    const wchar_t friendlyname[] = L"WebM Splitter Filter (Debug)";
#else
    const wchar_t friendlyname[] = L"WebM Splitter Filter";
#endif

    hr = DllUnregisterServer();

    if (FAILED(hr))
        return hr;

    hr = ComReg::RegisterCoclass(
            WebmTypes::CLSID_WebmSplit,
            friendlyname,
            filename,
            L"Webm.Split",
            L"Webm.Split.1",
            false,  //not insertable
            false,  //not a control
            ComReg::kBoth,  //DShow filters must support "both"
            GUID_NULL,     //typelib
            0,    //no version specified
            0);   //no toolbox bitmap

    if (FAILED(hr))
        return hr;

#if 0
    hr = ComReg::RegisterCustomFileType(
            L".webm",
            CLSID_AsyncReader,             //source
            MEDIATYPE_Stream,              //major
            WebmTypes::MEDIASUBTYPE_WEBM); //minor

    if (FAILED(hr))
        return hr;
#endif

#if 0
    hr = ComReg::RegisterProtocolSource(
            L"http",
            L".webm",
            CLSID_URLReader /* WebmTypes::CLSID_WebmSplit */ );

    if (FAILED(hr))
        return hr;
#endif

    const GraphUtil::IFilterMapper2Ptr pMapper(CLSID_FilterMapper2);
    assert(bool(pMapper));

    enum { cPins = 2 };
    REGFILTERPINS pins[cPins];

    REGFILTERPINS& inpin = pins[0];

    enum { nInpinMediaTypes = 1 };
    const REGPINTYPES inpinMediaTypes[nInpinMediaTypes] =
    {
        { &MEDIATYPE_Stream, &WebmTypes::MEDIASUBTYPE_WEBM }
    };

    inpin.strName = 0;              //obsolete
    inpin.bRendered = FALSE;        //TODO: should this be TRUE?
    inpin.bOutput = FALSE;
    inpin.bZero = FALSE;
    inpin.bMany = FALSE;
    inpin.clsConnectsToFilter = 0;  //obsolete
    inpin.strConnectsToPin = 0;     //obsolete
    inpin.nMediaTypes = nInpinMediaTypes;
    inpin.lpMediaType = inpinMediaTypes;

    REGFILTERPINS& outpin = pins[1];

    outpin.strName = 0;              //obsolete
    outpin.bRendered = FALSE;        //always FALSE for outpins
    outpin.bOutput = TRUE;
    outpin.bZero = FALSE;            //?
    outpin.bMany = TRUE;
    outpin.clsConnectsToFilter = 0;  //obsolete
    outpin.strConnectsToPin = 0;     //obsolete
    outpin.nMediaTypes = 0;
    outpin.lpMediaType = 0;

    //pin setup complete

    REGFILTER2 filter;

    filter.dwVersion = 1;
    filter.dwMerit = MERIT_NORMAL;
    filter.cPins = cPins;
    filter.rgPins = pins;

    hr = pMapper->RegisterFilter(
            WebmTypes::CLSID_WebmSplit,
            friendlyname,
            0,
            &CLSID_LegacyAmFilterCategory,
            0,
            &filter);

    return hr;
}
コード例 #21
0
//
//  1. The classID must be created under HKCR\CLSID.
//     a. DefaultIcon must be set to <Path and Module>,0.
//     b. InprocServer32 set to path and module.
//        i. Threading model specified as Apartment.
//     c. ShellFolder attributes must be set.
//  2. If the extension in non-rooted, its GUID is entered at the desired folder.
//  3. It must be registered as approved for Windows NT or XP.
//
STDAPI DllRegisterServer()
{
    HRESULT hr = S_OK;

	WCHAR szBoxShellFolderID[64];
	WCHAR szContextMenuClassID[64];
	WCHAR szSubKey[MAX_PATH];
	WCHAR szData[MAX_PATH];
	StringFromGUID2(CLSID_BoxShellFolder, szBoxShellFolderID, ARRAYSIZE(szBoxShellFolderID)); // Convert the IID to a string.
	StringFromGUID2(CLSID_BoxShellContextMenu, szContextMenuClassID, ARRAYSIZE(szContextMenuClassID)); // Convert the IID to a string.

    // Get the path and module name.
    WCHAR szModulePathAndName[MAX_PATH];
    GetModuleFileNameW(g_hInst, szModulePathAndName, ARRAYSIZE(szModulePathAndName));

    // This will setup and register the basic ClassIDs. 
    DWORD dwData = SFGAO_FOLDER | SFGAO_HASSUBFOLDER  | SFGAO_CANDELETE;
    REGSTRUCT rgRegEntries[] = 
    {
        HKEY_CURRENT_USER,   L"Software\\Classes\\CLSID\\%s",                  szBoxShellFolderID, NULL,                   (LPBYTE)BOX_NET,	       REG_SZ,
        HKEY_CURRENT_USER,   L"Software\\Classes\\CLSID\\%s\\InprocServer32",  szBoxShellFolderID, NULL,                   (LPBYTE)L"%s",              REG_SZ,
        HKEY_CURRENT_USER,   L"Software\\Classes\\CLSID\\%s\\InprocServer32",  szBoxShellFolderID, L"ThreadingModel",      (LPBYTE)L"Apartment",       REG_SZ,
        HKEY_CURRENT_USER,   L"Software\\Classes\\CLSID\\%s\\DefaultIcon",     szBoxShellFolderID, NULL,                   (LPBYTE)L"%s",              REG_SZ,
        HKEY_CURRENT_USER,   L"Software\\Classes\\CLSID\\%s\\ShellFolder",     szBoxShellFolderID, L"Attributes",          (LPBYTE)&dwData,            REG_DWORD,
        //HKEY_CURRENT_USER,   L"Software\\Classes\\CLSID\\%s",                  szContextMenuClassID,    NULL,                   (LPBYTE)BOX_NET,       REG_SZ,
        //HKEY_CURRENT_USER,   L"Software\\Classes\\CLSID\\%s\\InprocServer32",  szContextMenuClassID,    NULL,                   (LPBYTE)L"%s",              REG_SZ,
        //HKEY_CURRENT_USER,   L"Software\\Classes\\CLSID\\%s\\InprocServer32",  szContextMenuClassID,    L"ThreadingModel",      (LPBYTE)L"Apartment",       REG_SZ,
    };

    HKEY hKey = NULL;
    
    for (int i = 0; SUCCEEDED(hr) && (i < ARRAYSIZE(rgRegEntries)); i++)
    {
        // Create the sub key string.
        hr = StringCchPrintfW(szSubKey, ARRAYSIZE(szSubKey), rgRegEntries[i].pszSubKey, rgRegEntries[i].pszClassID);

        if (SUCCEEDED(hr))
        {
			//MessageBoxW(0, szSubKey, szModulePathAndName, MB_OK);

			LONG lResult = RegCreateKeyExW(rgRegEntries[i].hRootKey, szSubKey, 0, NULL, 
                                           REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL);

			if (S_OK == lResult)
            {

                // If this is a string entry, create the string.
                if (REG_SZ == rgRegEntries[i].dwType)
                { 
                    hr = StringCchPrintfW(szData, ARRAYSIZE(szData), (LPWSTR)rgRegEntries[i].pszData, szModulePathAndName);

                    if (SUCCEEDED(hr))
                    {
						lResult = RegSetValueExW(hKey, 
                                       rgRegEntries[i].pszValueName, 
                                       0,
                                       rgRegEntries[i].dwType, 
                                       (LPBYTE)szData, 
                                       (lstrlenW(szData) + 1) * sizeof(WCHAR));
                    }
                }
                else if (REG_DWORD == rgRegEntries[i].dwType)
                {
                    RegSetValueExW(hKey, 
                                   rgRegEntries[i].pszValueName, 
                                   0, rgRegEntries[i].dwType,
                                   rgRegEntries[i].pszData, 
                                   sizeof(DWORD));
                }
                        
                RegCloseKey(hKey);
            }
            else
            {
				/*
				if (lResult == 0x5) // no access
				{
					MessageBoxW(0, szSubKey, L"NOT AUTOHORIZED", MB_OK);
				}
				*/
				hr = SELFREG_E_CLASS;
            }
        }
    }

    if (SUCCEEDED(hr))   
    {   
        hr = SELFREG_E_CLASS;   
   
        // Now we are ready to register the namespace extension.   
        // This will put our extension in My Computer.   
		if (SUCCEEDED(StringCchPrintfW(szSubKey, ARRAYSIZE(szSubKey), MYCOMPUTER_NAMESPACE_GUID, szBoxShellFolderID)))   
        {   
            LONG lResult = RegCreateKeyExW(HKEY_CURRENT_USER, szSubKey, 0, NULL,    
                                           REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL);   
            if (S_OK == lResult)   
            {   
                // Copy our name into the string.   
                hr = StringCchCopyW(szData, ARRAYSIZE(szData), BOX_NET);   
                if (SUCCEEDED(hr))   
                {   
                    // Set the name of our extension.   
                    lResult = RegSetValueExW(hKey, NULL, 0, REG_SZ, (LPBYTE)szData, (lstrlenW(szData) + 1) * sizeof(szData[0]));   
                    RegCloseKey(hKey);   
                   
                    // It is assumed at this point that we are running on Windows XP or later   
                    // and therefore the extension needs to be registered as approved.   
                    PCWSTR rgszApprovedClassIDs[] = { szBoxShellFolderID /*, szContextMenuClassID*/ };   
                    for (int i = 0; SUCCEEDED(hr) && i < ARRAYSIZE(rgszApprovedClassIDs); i++)   
                    {   
                        hr = StringCchPrintfW(szSubKey, ARRAYSIZE(szSubKey), SHELL_EXT_APPROVED, szBoxShellFolderID);   
                        if (SUCCEEDED(hr))   
                        {   
                            lResult = RegCreateKeyExW(HKEY_LOCAL_MACHINE, szSubKey, 0, NULL, REG_OPTION_NON_VOLATILE,   
                                                      KEY_WRITE, NULL, &hKey, NULL);   
                            if (S_OK == lResult)   
                            {   
                                // Create the value string.   
                                hr = StringCchCopyW(szData, ARRAYSIZE(szData), BOX_NET);   
                                if (SUCCEEDED(hr))   
                                {   
                                    lResult = RegSetValueExW(hKey,    
                                                             NULL,    
                                                             0,    
                                                             REG_SZ,    
                                                             (LPBYTE)szData,    
                                                             (lstrlenW(szData) + 1) * sizeof(WCHAR));   
                                           
                                    hr = S_OK;   
                                }   
                                   
                                RegCloseKey(hKey);   
                            }   
                        }   
                    }   
   
                    // The Shell has to be notified that the change has been made.   
                    RefreshFolderViews(CSIDL_DRIVES);   
                }   
            }   
        }   
	}

    if (FAILED(hr))
    {
        //Remove the stuff we added.
        DllUnregisterServer();
    }

    return hr;
}
コード例 #22
0
STDAPI
DllRegisterServer(
    void)
{
    TCHAR szModulePath[MAX_PATH];
    BYTE pbSignature[136];  // Room for a 1024 bit signature, with padding.
    OSVERSIONINFO osVer;
    LPTSTR szFileName, szFileExt;
    HINSTANCE hThisDll;
    HRSRC hSigResource;
    DWORD dwStatus;
    LONG nStatus;
    BOOL fStatus;
    DWORD dwDisp;
    DWORD dwIndex;
    DWORD dwSigLength;
    HRESULT hReturnStatus = NO_ERROR;
    HKEY hProviders = NULL;
    HKEY hMyCsp = NULL;
    HKEY hCalais = NULL;
    HKEY hVendor = NULL;
    BOOL fSignatureFound = FALSE;
    HANDLE hSigFile = INVALID_HANDLE_VALUE;
#ifdef SCARD_CSP
    BOOL fCardIntroduced = FALSE;
    SCARDCONTEXT hCtx = NULL;
#endif

#ifdef _AFXDLL
    AFX_MANAGE_STATE(AfxGetStaticModuleState());
#endif


    //
    // Figure out the file name and path.
    //

    hThisDll = GetInstanceHandle();
    if (NULL == hThisDll)
    {
        hReturnStatus = HRESULT_FROM_WIN32(ERROR_INVALID_HANDLE);
        goto ErrorExit;
    }

    dwStatus = GetModuleFileName(
                    hThisDll,
                    szModulePath,
                    sizeof(szModulePath) / sizeof(TCHAR));
    if (0 == dwStatus)
    {
        hReturnStatus = HRESULT_FROM_WIN32(GetLastError());
        goto ErrorExit;
    }

    szFileName = _tcsrchr(szModulePath, TEXT('\\'));
    if (NULL == szFileName)
        szFileName = szModulePath;
    else
        szFileName += 1;
    szFileExt = _tcsrchr(szFileName, TEXT('.'));
    if (NULL == szFileExt)
    {
        hReturnStatus = HRESULT_FROM_WIN32(ERROR_INVALID_NAME);
        goto ErrorExit;
    }
    else
        szFileExt += 1;


    //
    // Create the Registry key for this CSP.
    //

    nStatus = RegCreateKeyEx(
                    HKEY_LOCAL_MACHINE,
                    TEXT("SOFTWARE\\Microsoft\\Cryptography\\Defaults\\Provider"),
                    0,
                    TEXT(""),
                    REG_OPTION_NON_VOLATILE,
                    KEY_ALL_ACCESS,
                    NULL,
                    &hProviders,
                    &dwDisp);
    if (ERROR_SUCCESS != nStatus)
    {
        hReturnStatus = HRESULT_FROM_WIN32(nStatus);
        goto ErrorExit;
    }
    nStatus = RegCreateKeyEx(
                    hProviders,
                    l_szProviderName,
                    0,
                    TEXT(""),
                    REG_OPTION_NON_VOLATILE,
                    KEY_ALL_ACCESS,
                    NULL,
                    &hMyCsp,
                    &dwDisp);
    if (ERROR_SUCCESS != nStatus)
    {
        hReturnStatus = HRESULT_FROM_WIN32(nStatus);
        goto ErrorExit;
    }
    nStatus = RegCloseKey(hProviders);
    hProviders = NULL;
    if (ERROR_SUCCESS != nStatus)
    {
        hReturnStatus = HRESULT_FROM_WIN32(nStatus);
        goto ErrorExit;
    }


    //
    // Install the trivial registry values.
    //
	
    nStatus = RegSetValueEx(
                    hMyCsp,
                    TEXT("Image Path"),
                    0,
                    REG_SZ,
                    (LPBYTE)szModulePath,
                    (_tcslen(szModulePath) + 1) * sizeof(TCHAR));
    if (ERROR_SUCCESS != nStatus)
    {
        hReturnStatus = HRESULT_FROM_WIN32(nStatus);
        goto ErrorExit;
    }

    nStatus = RegSetValueEx(
                    hMyCsp,
                    TEXT("Type"),
                    0,
                    REG_DWORD,
                    (LPBYTE)&l_dwCspType,
                    sizeof(DWORD));
    if (ERROR_SUCCESS != nStatus)
    {
        hReturnStatus = HRESULT_FROM_WIN32(nStatus);
        goto ErrorExit;
    }


    //
    // See if we're self-signed.  On NT5, CSP images can carry their own
    // signatures.
    //

    hSigResource = FindResource(
                        hThisDll,
                        MAKEINTRESOURCE(CRYPT_SIG_RESOURCE_NUMBER),
                        RT_RCDATA);


    //
    // Install the file signature.
    //

    ZeroMemory(&osVer, sizeof(OSVERSIONINFO));
    osVer.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
    fStatus = GetVersionEx(&osVer);
    // ?BUGBUG? -- This works on Windows Millenium, too.
    if (fStatus
        && (VER_PLATFORM_WIN32_NT == osVer.dwPlatformId)
        && (5 <= osVer.dwMajorVersion)
        && (NULL != hSigResource))
//		&& (NULL == hSigResource))
    {

        //
        // Signature in file flag is sufficient.
        //

        dwStatus = 0;
        nStatus = RegSetValueEx(
                        hMyCsp,
                        TEXT("SigInFile"),
                        0,
                        REG_DWORD,
                        (LPBYTE)&dwStatus,
                        sizeof(DWORD));
        if (ERROR_SUCCESS != nStatus)
        {
            hReturnStatus = HRESULT_FROM_WIN32(nStatus);
            goto ErrorExit;
        }
    }
    else
    {

        //
        // We have to install a signature entry.
        // Try various techniques until one works.
        //

        for (dwIndex = 0; !fSignatureFound; dwIndex += 1)
        {
            switch (dwIndex)
            {

            //
            // Look for an external *.sig file and load that into the registry.
            //

            case 0:
                _tcscpy(szFileExt, TEXT("sig"));
                hSigFile = CreateFile(
                                szModulePath,
                                GENERIC_READ,
                                FILE_SHARE_READ,
                                NULL,
                                OPEN_EXISTING,
                                FILE_ATTRIBUTE_NORMAL,
                                NULL);
                if (INVALID_HANDLE_VALUE == hSigFile)
                    continue;
                dwSigLength = GetFileSize(hSigFile, NULL);
                if ((dwSigLength > sizeof(pbSignature))
                    || (dwSigLength < 72))      // Accept a 512-bit signature
                {
                    hReturnStatus = NTE_BAD_SIGNATURE;
                    goto ErrorExit;
                }

                fStatus = ReadFile(
                                hSigFile,
                                pbSignature,
                                sizeof(pbSignature),
                                &dwSigLength,
                                NULL);
                if (!fStatus)
                {
                    hReturnStatus = HRESULT_FROM_WIN32(GetLastError());
                    goto ErrorExit;
                }
                fStatus = CloseHandle(hSigFile);
                hSigFile = NULL;
                if (!fStatus)
                {
                    hReturnStatus = HRESULT_FROM_WIN32(GetLastError());
                    goto ErrorExit;
                }
                fSignatureFound = TRUE;
                break;


            //
            // Other cases may be added in the future.
            //

            default:
                hReturnStatus = NTE_BAD_SIGNATURE;
                goto ErrorExit;
            }

            if (fSignatureFound)
            {
                for (dwIndex = 0; dwIndex < dwSigLength; dwIndex += 1)
                {
                    if (0 != pbSignature[dwIndex])
                        break;
                }
                if (dwIndex >= dwSigLength)
                    fSignatureFound = FALSE;
            }
        }


        //
        // We've found a signature somewhere!  Install it.
        //

        nStatus = RegSetValueEx(
                        hMyCsp,
                        TEXT("Signature"),
                        0,
                        REG_BINARY,
                        pbSignature,
                        dwSigLength);
        if (ERROR_SUCCESS != nStatus)
        {
            hReturnStatus = HRESULT_FROM_WIN32(nStatus);
            goto ErrorExit;
        }
    }

    nStatus = RegCloseKey(hMyCsp);
    hMyCsp = NULL;
    if (ERROR_SUCCESS != nStatus)
    {
        hReturnStatus = HRESULT_FROM_WIN32(nStatus);
        goto ErrorExit;
    }


#ifdef SCARD_CSP
    //
    // Introduce the vendor card.  Try various techniques until one works.
    //

    for (dwIndex = 0; !fCardIntroduced; dwIndex += 1)
    {
        switch (dwIndex)
        {
        case 0:
            {
                HMODULE hWinSCard = NULL;
                LPSETCARDTYPEPROVIDERNAME pfSetCardTypeProviderName = NULL;

                hWinSCard = GetModuleHandle(TEXT("WinSCard.DLL"));
                if (NULL == hWinSCard)
                    continue;
#if defined(UNICODE)
                pfSetCardTypeProviderName =
                    (LPSETCARDTYPEPROVIDERNAME)GetProcAddress(
                        hWinSCard,
                        TEXT("SCardSetCardTypeProviderNameW"));
#else
                pfSetCardTypeProviderName =
                    (LPSETCARDTYPEPROVIDERNAME)GetProcAddress(
                        hWinSCard,
                        TEXT("SCardSetCardTypeProviderNameA"));
#endif
                if (NULL == pfSetCardTypeProviderName)
                    continue;

                dwStatus = SCardIntroduceCardType(
                                NULL,
                                l_szCardName,
                                NULL,
                                NULL,
                                0,
                                l_rgbATR,
                                l_rgbATRMask,
                                sizeof(l_rgbATR));
                if ((ERROR_SUCCESS != dwStatus)
                    && (ERROR_ALREADY_EXISTS != dwStatus))
                    continue;
                dwStatus = (*pfSetCardTypeProviderName)(
                                NULL,
                                l_szCardName,
                                SCARD_PROVIDER_CSP,
                                l_szProviderName);
                if (ERROR_SUCCESS != dwStatus)
                {
                    if (0 == (dwStatus & 0xffff0000))
                        hReturnStatus = HRESULT_FROM_WIN32(dwStatus);
                    else
                        hReturnStatus = (HRESULT)dwStatus;
                    goto ErrorExit;
                }
                fCardIntroduced = TRUE;
                break;
            }

        case 1:
            dwStatus = SCardEstablishContext(SCARD_SCOPE_SYSTEM, 0, 0, &hCtx);
            if (ERROR_SUCCESS != dwStatus)
                continue;
            dwStatus = SCardIntroduceCardType(
                            hCtx,
                            l_szCardName,
                            NULL,
                            NULL,
                            0,
                            l_rgbATR,
                            l_rgbATRMask,
                            sizeof(l_rgbATR));
            if ((ERROR_SUCCESS != dwStatus)
                && (ERROR_ALREADY_EXISTS != dwStatus))
            {
                if (0 == (dwStatus & 0xffff0000))
                    hReturnStatus = HRESULT_FROM_WIN32(dwStatus);
                else
                    hReturnStatus = (HRESULT)dwStatus;
                goto ErrorExit;
            }
            dwStatus = SCardReleaseContext(hCtx);
            hCtx = NULL;
            if (ERROR_SUCCESS != dwStatus)
            {
                if (0 == (dwStatus & 0xffff0000))
                    hReturnStatus = HRESULT_FROM_WIN32(dwStatus);
                else
                    hReturnStatus = (HRESULT)dwStatus;
                goto ErrorExit;
            }
            nStatus = RegCreateKeyEx(
                            HKEY_LOCAL_MACHINE,
                            TEXT("SOFTWARE\\Microsoft\\Cryptography\\Calais\\SmartCards"),
                            0,
                            TEXT(""),
                            REG_OPTION_NON_VOLATILE,
                            KEY_ALL_ACCESS,
                            NULL,
                            &hCalais,
                            &dwDisp);
            if (ERROR_SUCCESS != nStatus)
            {
                hReturnStatus = HRESULT_FROM_WIN32(nStatus);
                goto ErrorExit;
            }
            nStatus = RegCreateKeyEx(
                            hCalais,
                            l_szCardName,
                            0,
                            TEXT(""),
                            REG_OPTION_NON_VOLATILE,
                            KEY_ALL_ACCESS,
                            NULL,
                            &hVendor,
                            &dwDisp);
            if (ERROR_SUCCESS != nStatus)
            {
                hReturnStatus = HRESULT_FROM_WIN32(nStatus);
                goto ErrorExit;
            }
            nStatus = RegCloseKey(hCalais);
            hCalais = NULL;
            if (ERROR_SUCCESS != nStatus)
            {
                hReturnStatus = HRESULT_FROM_WIN32(nStatus);
                goto ErrorExit;
            }
            nStatus = RegSetValueEx(
                            hVendor,
                            TEXT("Crypto Provider"),
                            0,
                            REG_SZ,
                            (LPBYTE)l_szProviderName,
                            (_tcslen(l_szProviderName) + 1) * sizeof(TCHAR));
            if (ERROR_SUCCESS != nStatus)
            {
                hReturnStatus = HRESULT_FROM_WIN32(nStatus);
                goto ErrorExit;
            }

            nStatus = RegCloseKey(hVendor);
            hVendor = NULL;
            if (ERROR_SUCCESS != nStatus)
            {
                hReturnStatus = HRESULT_FROM_WIN32(nStatus);
                goto ErrorExit;
            }

            fCardIntroduced = TRUE;
            break;

        case 2:
            nStatus = RegCreateKeyEx(
                            HKEY_LOCAL_MACHINE,
                            TEXT("SOFTWARE\\Microsoft\\Cryptography\\Calais\\SmartCards"),
                            0,
                            TEXT(""),
                            REG_OPTION_NON_VOLATILE,
                            KEY_ALL_ACCESS,
                            NULL,
                            &hCalais,
                            &dwDisp);
            if (ERROR_SUCCESS != nStatus)
                continue;
            nStatus = RegCreateKeyEx(
                            hCalais,
                            l_szCardName,
                            0,
                            TEXT(""),
                            REG_OPTION_NON_VOLATILE,
                            KEY_ALL_ACCESS,
                            NULL,
                            &hVendor,
                            &dwDisp);
            if (ERROR_SUCCESS != nStatus)
            {
                hReturnStatus = HRESULT_FROM_WIN32(nStatus);
                goto ErrorExit;
            }
            nStatus = RegCloseKey(hCalais);
            hCalais = NULL;
            if (ERROR_SUCCESS != nStatus)
            {
                hReturnStatus = HRESULT_FROM_WIN32(nStatus);
                goto ErrorExit;
            }
            nStatus = RegSetValueEx(
                            hVendor,
                            TEXT("Primary Provider"),
                            0,
                            REG_BINARY,
                            (LPCBYTE)&l_guidPrimaryProv,
                            sizeof(l_guidPrimaryProv));
            if (ERROR_SUCCESS != nStatus)
            {
                hReturnStatus = HRESULT_FROM_WIN32(nStatus);
                goto ErrorExit;
            }
            nStatus = RegSetValueEx(
                            hVendor,
                            TEXT("ATR"),
                            0,
                            REG_BINARY,
                            l_rgbATR,
                            sizeof(l_rgbATR));
            if (ERROR_SUCCESS != nStatus)
            {
                hReturnStatus = HRESULT_FROM_WIN32(nStatus);
                goto ErrorExit;
            }
            nStatus = RegSetValueEx(
                            hVendor,
                            TEXT("ATRMask"),
                            0,
                            REG_BINARY,
                            l_rgbATRMask,
                            sizeof(l_rgbATRMask));
            if (ERROR_SUCCESS != nStatus)
            {
                hReturnStatus = HRESULT_FROM_WIN32(nStatus);
                goto ErrorExit;
            }
            nStatus = RegSetValueEx(
                            hVendor,
                            TEXT("Crypto Provider"),
                            0,
                            REG_SZ,
                            (LPBYTE)l_szProviderName,
                            (_tcslen(l_szProviderName) + 1) * sizeof(TCHAR));
            if (ERROR_SUCCESS != nStatus)
            {
                hReturnStatus = HRESULT_FROM_WIN32(nStatus);
                goto ErrorExit;
            }
            nStatus = RegCloseKey(hVendor);
            hVendor = NULL;
            if (ERROR_SUCCESS != nStatus)
            {
                hReturnStatus = HRESULT_FROM_WIN32(nStatus);
                goto ErrorExit;
            }
            fCardIntroduced = TRUE;
            break;

        default:
            hReturnStatus = ERROR_ACCESS_DENIED;
            goto ErrorExit;
        }
    }
#endif


    //
    // ?vendor?
    // Add any additional initialization required here.
    //



    //
    // All done!
    //

    return hReturnStatus;


    //
    // An error was detected.  Clean up any outstanding resources and
    // return the error.
    //

    ErrorExit:
#ifdef SCARD_CSP
    if (NULL != hCtx)
        SCardReleaseContext(hCtx);
    if (NULL != hCalais)
        RegCloseKey(hCalais);
#endif
    if (NULL != hVendor)
        RegCloseKey(hVendor);
    if (INVALID_HANDLE_VALUE != hSigFile)
        CloseHandle(hSigFile);
    if (NULL != hMyCsp)
        RegCloseKey(hMyCsp);
    if (NULL != hProviders)
        RegCloseKey(hProviders);
    DllUnregisterServer();
    return hReturnStatus;
}
コード例 #23
0
ファイル: dllentry.cpp プロジェクト: brion/webmdshow
STDAPI DllRegisterServer()
{
    HRESULT hr = DllUnregisterServer();
    assert(SUCCEEDED(hr));

    std::wstring filename_;

    hr = ComReg::ComRegGetModuleFileName(g_hModule, filename_);
    assert(SUCCEEDED(hr));
    assert(!filename_.empty());

    const wchar_t* const filename = filename_.c_str();

#if _DEBUG
    const wchar_t friendly_name[] = L"WebM MF VP8 Decoder Transform (Debug)";
#else
    const wchar_t friendly_name[] = L"WebM MF VP8 Decoder Transform";
#endif

    hr = ComReg::RegisterCoclass(
            WebmTypes::CLSID_WebmMfVp8Dec,
            friendly_name,
            filename,
            L"Webm.MfVp8Dec",  //TODO: do we really need ProgIDs?
            L"Webm.MfVp8Dec.1",
            false,  //not insertable
            false,  //not a control
            ComReg::kBoth,  //DShow filters must support "both"
            GUID_NULL,     //typelib
            0,    //no version specified
            0);   //no toolbox bitmap

    if (FAILED(hr))
        return hr;

    enum { cInputTypes = 1 };
    MFT_REGISTER_TYPE_INFO pInputTypes[cInputTypes] =
    {
        { MFMediaType_Video, WebmTypes::MEDIASUBTYPE_VP80 }
    };

    enum { cOutputTypes = 3 };
    MFT_REGISTER_TYPE_INFO pOutputTypes[cOutputTypes] =
    {
        { MFMediaType_Video, MFVideoFormat_NV12 },
        { MFMediaType_Video, MFVideoFormat_YV12 },
        { MFMediaType_Video, MFVideoFormat_IYUV }
    };

    wchar_t* const friendly_name_ = const_cast<wchar_t*>(friendly_name);

    hr = MFTRegister(
            WebmTypes::CLSID_WebmMfVp8Dec,
            MFT_CATEGORY_VIDEO_DECODER,
            friendly_name_,
            MFT_ENUM_FLAG_SYNCMFT,  //TODO: for now, just support sync
            cInputTypes,
            pInputTypes,
            cOutputTypes,
            pOutputTypes,
            0);  //no attributes

    return hr;
}