Search code examples
c++directshow

How to Register "quartz.dll" by myself?


Register a COM, which is mostly regsvr32.exe, but I need to write my own code to Register quartz.dll. So I wrote the following code:

typedef HRESULT(WINAPI *FREG)();

BOOL Register()
{
    CoInitialize(NULL);
    HMODULE hMod = ::LoadLibrary(L"C:/windows/sysWow64/quartz.dll");
    if (!hMod)
        return FALSE;

    HRESULT hResult = ::OleInitialize(NULL);
    if (hResult != S_OK)
    {
        ::FreeLibrary(hMod);
        return FALSE;
    }

FREG lpfunc = (FREG)::GetProcAddress(hMod, "DllRegisterServer");
if (!lpfunc)
{
    ::FreeLibrary(hMod);
    ::OleUninitialize();
    return FALSE;
}

hResult = lpfunc();
::OleUninitialize();
::FreeLibrary(hMod);

return (hResult == S_OK);
}

but lpfunc() got E_ACCESSDENIED General access denied error. I enabled UAC to requireAdministrator,but nothing changed.

Interestingly, the above code works well in the console program, and there are still permissions issues in the MFC.I found a lot of information, but the problem was not solved .


Solution

  • First of all, you don't normally want to register quartz.dll. In some rare cases it indeed allows to fix certain issues (esp. related to uninstallation of inaccurately made codec pack). Luckily, there is no harm in re-registration either.

    The code is about right except that OleInitialize is not really necessary. Unprivileged application cannot write under HKLM and hence the E_ACCESSDENIED failure. If you have UAC level reduced to not prompt users to confirm execution of requireAdministrator applications, you still have to "run as administrator" in recent OSes or otherwise registry still remains read only for your app and for the DLL you ask to do the registration.

    Bottom line, it is still about security and UAC.