Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7058727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:08:50+00:00 2026-05-28T04:08:50+00:00

I keep getting E_INVALIDARG when calling RenderStream(). My program output is: SUCCESS – Initialized

  • 0

I keep getting “E_INVALIDARG” when calling RenderStream().

My program output is:

SUCCESS - Initialized COM library.
SUCCESS - Created the Filter Graph Manager.
SUCCESS - Created the Media Control and Media Event Interfaces.
SUCCESS - Enumerated devices.
--------------DEVICE INFORMATION--------------
Integrated Webcam
------------END DEVICE INFORMATION------------
SUCCESS - Bound to moniker.

Here is the code:

#include "stdafx.h"

#include <dshow.h>      //direct show
#include <windows.h>    //windows

#pragma comment(lib,"Strmiids.lib") //used for direct show

HRESULT InitCaptureGraphBuilder(
    IGraphBuilder **ppGraph,  // Receives the pointer.
    ICaptureGraphBuilder2 **ppBuild  // Receives the pointer.
    )
{
    if (!ppGraph || !ppBuild)
    {
        return E_POINTER;
    }
    IGraphBuilder *pGraph = NULL;
    ICaptureGraphBuilder2 *pBuild = NULL;

    // Create the Capture Graph Builder.
    HRESULT hr = CoCreateInstance(CLSID_CaptureGraphBuilder2, NULL, 
        CLSCTX_INPROC_SERVER, IID_ICaptureGraphBuilder2, (void**)&pBuild );
    if (SUCCEEDED(hr))
    {
        // Create the Filter Graph Manager.
        hr = CoCreateInstance(CLSID_FilterGraph, 0, CLSCTX_INPROC_SERVER,
            IID_IGraphBuilder, (void**)&pGraph);
        if (SUCCEEDED(hr))
        {
            // Initialize the Capture Graph Builder.
            pBuild->SetFiltergraph(pGraph);

            // Return both interface pointers to the caller.
            *ppBuild = pBuild;
            *ppGraph = pGraph; // The caller must release both interfaces.
            return S_OK;
        }
        else
        {
            pBuild->Release();
        }
    }
    return hr; // Failed
}
HRESULT EnumerateDevices(REFGUID category, IEnumMoniker **ppEnum)
{
    // Create the System Device Enumerator.
    ICreateDevEnum *pDevEnum;
    HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL,  
        CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pDevEnum));

    if (SUCCEEDED(hr))
    {
        // Create an enumerator for the category.
        hr = pDevEnum->CreateClassEnumerator(category, ppEnum, 0);
        if (hr == S_FALSE)
        {
            hr = VFW_E_NOT_FOUND;  // The category is empty. Treat as an error.
        }
        pDevEnum->Release();
    }
    return hr;
}
void DisplayDeviceInformation(IEnumMoniker *pEnum, IMoniker** pMoniker)
{
    while (pEnum->Next(1, pMoniker, NULL) == S_OK)
    {
        IPropertyBag *pPropBag;
        HRESULT hr = (*pMoniker)->BindToStorage(0, 0, IID_PPV_ARGS(&pPropBag));
        if (FAILED(hr))
        {
            (*pMoniker)->Release();
            continue;  
        } 

        VARIANT var;
        VariantInit(&var);

        // Get description or friendly name.
        hr = pPropBag->Read(L"Description", &var, 0);
        if (FAILED(hr))
        {
            hr = pPropBag->Read(L"FriendlyName", &var, 0);
        }
        if (SUCCEEDED(hr))
        {
            printf("%S\n", var.bstrVal);
            if(0 == wcscmp(var.bstrVal, L"Integrated Webcam"))
            {
                VariantClear(&var); 
                pPropBag->Release();
                return;
            }
            VariantClear(&var); 
        }

        hr = pPropBag->Write(L"FriendlyName", &var);

        pPropBag->Release();
    }
}

void main()
{
    HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);

    IGraphBuilder *pGraph = NULL;
    ICaptureGraphBuilder2 *pBuild = NULL;
    IMediaControl *pControl = NULL;
    IMediaEvent   *pEvent = NULL;

    if (FAILED(hr))
    {
        printf("ERROR - Could not initialize COM library\n");
        return;
    }

    printf("SUCCESS - Initialized COM library.\n");

    hr = InitCaptureGraphBuilder(&pGraph, &pBuild);

    if (FAILED(hr))
    {
        printf("ERROR - Could not create the Filter Graph Manager.\n");
        return;
    }

    printf("SUCCESS - Created the Filter Graph Manager.\n");

    hr = pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl);
    hr = pGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent);

    if (FAILED(hr))
    {
        printf("ERROR - Could not create the Media Control or Media Event Interfaces.\n");
        return;
    }

    printf("SUCCESS - Created the Media Control and Media Event Interfaces.\n");

    IEnumMoniker *pEnum;

    hr = EnumerateDevices(CLSID_VideoInputDeviceCategory, &pEnum);

    if(FAILED(hr))
    {
        printf("ERROR - Failed to enumerate devices.\n");
        return;
    }

    printf("SUCCESS - Enumerated devices.\n");
    IMoniker* pMoniker = NULL;

    printf("--------------DEVICE INFORMATION--------------\n");
    DisplayDeviceInformation(pEnum, &pMoniker);
    printf("------------END DEVICE INFORMATION------------\n");

    IBaseFilter *pCap = NULL;
    hr = pMoniker->BindToObject(0, 0, IID_IBaseFilter, (void**)&pCap);

    if(FAILED(hr))
    {
        printf("ERROR - Failed to bind to moniker.\n");
        return;
    }

    printf("SUCCESS - Bound to moniker.\n");

    hr = pBuild->RenderStream(&PIN_CATEGORY_PREVIEW, &MEDIATYPE_Video, pCap, NULL, NULL);

    if(FAILED(hr))
    {
        printf("ERROR - RenderStream() failed.\n");
        return;
    }

    printf("SUCCESS - RenderStream() succeeded.\n");

    hr = pControl->Run();

    if(FAILED(hr))
    {
        printf("ERROR - Run() failed.\n");
        return;
    }

    printf("SUCCESS - Running.\n");

    long evCode;
    hr = pEvent->WaitForCompletion(INFINITE, &evCode);

    if(FAILED(hr))
    {
        printf("ERROR - WaitForCompletion() failed.\n");
        return;
    }

    hr = pControl->Stop();

    if(FAILED(hr))
    {
        printf("ERROR - Stop() failed.\n");
        return;
    }

    printf("SUCCESS - Stopping.\n");

    pControl->Release();
    pEvent->Release();
    pGraph->Release();
    pMoniker->Release();
    pEnum->Release();

    CoUninitialize();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T04:08:50+00:00Added an answer on May 28, 2026 at 4:08 am

    Before using RenderStream you need to IGraphBuilder::AddFilter your camera filter to the graph.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I keep getting a NullPointerException when I call the method I created, draw(), in
I keep getting this error when making the program as given below: using System;
I am trying to simulate my small program and I keep getting error messages
Keep getting this error after inserting a subdatasheet into a query and trying to
I keep getting tasks that are above my skill level. How can I address this without coming accross as grossly incompetent?
I keep getting compiler errors when I try to access flashVars in an AS3
I keep getting asked about AppDomains in interviews, and I know the basics :
I keep getting a PermGen error on my Tomcat 6 server. I know what
I keep getting stuck conceptually on deciding an Exception-handling structure for my project. Suppose
I keep getting this NPE in my application and I can't seem to get

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.