AerospaceMilitary420
AerospaceMilitary420

Reputation: 65

Redefinition, multiple initialization in C

I'm working on a DirectShow program which is a windows library. I was following this website: https://learn.microsoft.com/en-us/windows/win32/directshow/how-to-play-a-file

This is my code:

#include <dshow.h>
#include <stdio.h>
#include <Windows.h>

void main(void) 
{
    HRESULT hr = CoInitialize(NULL);
    if (FAILED(hr))
    {
        printf("FAIL");
    }
    else
    {
        printf("PASS");
    }
    IGraphBuilder *pGraph;
    HRESULT hr=CoCreateInstance(&CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER,&IID_IGraphBuilder, (void **)&pGraph);
    IMediaControl *pControl;
    IMediaEvent *pEvent;
    hr = pGraph->lpVtbl->QueryInterface(pGraph,&IID_IMediaControl, (void**)&pControl);
    hr = pGraph->lpVtbl->QueryInterface(pGraph,&IID_IMediaEvent, (void**)&pEvent);
}

The error is in this line:

HRESULT hr=CoCreateInstance(&CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER,&IID_IGraphBuilder, (void **)&pGraph);

This is the error:

'hr':redefinition; multiple initialization

My issue is that, I can't remove the HRESULT, because that gives more errors and the code on the website is telling me to do it, so I don't know why it isn't working in my compiler. Note: I'm using C and the website is C++ which I think is the cause of the error but idk how to solve it either.

Upvotes: -3

Views: 220

Answers (1)

0___________
0___________

Reputation: 67835

Scroll your learn.microsoft.com page down and see the complete example code:

#include <dshow.h>
void main(void)
{
    IGraphBuilder *pGraph = NULL;
    IMediaControl *pControl = NULL;
    IMediaEvent   *pEvent = NULL;

    // Initialize the COM library.
    HRESULT hr = CoInitialize(NULL);
    if (FAILED(hr))
    {
        printf("ERROR - Could not initialize COM library");
        return;
    }

    // Create the filter graph manager and query for interfaces.
    hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, 
                        IID_IGraphBuilder, (void **)&pGraph);
    if (FAILED(hr))
    {
        printf("ERROR - Could not create the Filter Graph Manager.");
        return;
    }

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

    // Build the graph. IMPORTANT: Change this string to a file on your system.
    hr = pGraph->RenderFile(L"C:\\Example.avi", NULL);
    if (SUCCEEDED(hr))
    {
        // Run the graph.
        hr = pControl->Run();
        if (SUCCEEDED(hr))
        {
            // Wait for completion.
            long evCode;
            pEvent->WaitForCompletion(INFINITE, &evCode);

            // Note: Do not use INFINITE in a real application, because it
            // can block indefinitely.
        }
    }
    pControl->Release();
    pEvent->Release();
    pGraph->Release();
    CoUninitialize();
}

Upvotes: 0

Related Questions