tags:

views:

45

answers:

1

Here is a code snippet

#include "stdafx.h"
#include <tchar.h>
#include <windows.h>
#include <dshow.h>
#include <ExDisp.h>
int _tmain(int argc, _TCHAR* argv[])
{
    CoInitialize(NULL);
    HRESULT hr = S_OK;
    DWORD err = 0;

    // Try to create graph builder
    IGraphBuilder* pGraph = 0;
    hr = CoCreateInstance(CLSID_FilterGraph, NULL,
    CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void**)&pGraph );
    err = GetLastError();

    // Here, hr is E_ACCESSDENIED
    // err is 5 (ERROR_ACCESS_DENIED)
    // Try to create capture graph builder (succeeds)
    ICaptureGraphBuilder2* pBuild = 0;
    hr = CoCreateInstance(CLSID_CaptureGraphBuilder2, NULL, CLSCTX_INPROC_SERVER, IID_ICaptureGraphBuilder2, (void **)&pBuild );
    err = GetLastError();

    // Here, hr is S_OK
    // err is 0 (ERROR_SUCCESS)
    // Try to create IWebBrowser (succeeds)
    IWebBrowser2* pBrowser = 0;
    hr = CoCreateInstance (CLSID_InternetExplorer, NULL, CLSCTX_LOCAL_SERVER, IID_IWebBrowser2, (LPVOID *)&pBrowser);

    err = GetLastError();

    // Here, hr is S_OK
    // err is 0 (ERROR_SUCCESS)
    return 0;
}

I'm trying to create IFilterGraph, which fails with E_ACCESSDENIED. On the other hand, creating other directshow objects works ok. The same with some other COM objects (tried with IWebBrowser2 as an example). Any idea what can be the problem? Thanks!

+2  A: 

Well, that doesn't look good. It is the result of a Windows security problem. This would not normally fail, the coclass lives in c:\windows\system32\quartz.dll. There are many possible operations that could cause the failure, including having trouble reading the registry and loading the DLL.

Perhaps the best way to troubleshoot it is to use SysInternals' ProcMon and observe your program's actions. Pay attention to the Result column, you should see the error there. This ought to get you closer to finding out what security configuration problem might be the source.

Hans Passant
Very true, I debugged numerous weird-looking problems with it. I suppose a link would be very useful: http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx
sharptooth
Thanks, I have totally forgot that ProcMon can help here. One of the dlls was registered from a folder where my user didn't have permissions.
vucetica