开发者

E_ACCESSDENIED on CoCreateInstance

开发者 https://www.devze.com 2022-12-31 17:02 出处:网络
Here is a code snippet #include \"stdafx.h\" #include <tchar.h> #include <windows.h> #include <dshow.h>

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!


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消