CoCreateInstance 上的 E_ACCESSDENIED

发布于 2024-09-02 03:56:34 字数 1299 浏览 4 评论 0原文

代码片段

#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;
}

这是我尝试创建 IFilterGraph 的 ,该代码片段失败并显示 E_ACCESSDENIED。另一方面,创建其他 directshow 对象也可以正常工作。与其他一些 COM 对象相同(以 IWebBrowser2 为例进行尝试)。知道可能是什么问题吗?谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无敌元气妹 2024-09-09 03:56:34

嗯,这看起来不太好。这是 Windows 安全问题的结果。这通常不会失败,组件类位于 c:\windows\system32\quartz.dll 中。有许多可能导致失败的操作,包括读取注册表和加载 DLL 时遇到问题。

也许排除故障的最佳方法是使用 SysInternals 的 ProcMon 并观察程序的操作。请注意“结果”列,您应该会看到那里的错误。这应该可以让您更接近地找出安全配置问题可能的根源。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文