0

I am new to Window and DirectShow development. I am following official documentation.
I wanted to test and play around their sample code given at https://learn.microsoft.com/en-us/windows/win32/directshow/how-to-play-a-file but I am getting errors.

Code is:

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

Errors are:

Warning C4326   return type of 'main' should be 'int' instead of 'void' Project1    C:\Users\alok\source\repos\Project1\Project1\Source.cpp 3   
Error   LNK2001 unresolved external symbol _IID_IGraphBuilder   Project1    C:\Users\alok\source\repos\Project1\Project1\Source.obj 1   
Error   LNK2001 unresolved external symbol _IID_IMediaControl   Project1    C:\Users\alok\source\repos\Project1\Project1\Source.obj 1   
Error   LNK2001 unresolved external symbol _IID_IMediaEvent Project1    C:\Users\alok\source\repos\Project1\Project1\Source.obj 1   
Error   LNK2001 unresolved external symbol _CLSID_FilterGraph   Project1    C:\Users\alok\source\repos\Project1\Project1\Source.obj 1   
Error   LNK1120 4 unresolved externals  Project1    C:\Users\alok\source\repos\Project1\Debug\Project1.exe  1   

enter image description here

Details of IDE:

Microsoft Visual Studio Community 2019
Version 16.4.5
VisualStudio.16.Release/16.4.5+29806.167
Microsoft .NET Framework
Version 4.8.03761

Installed Version: Community

Visual C++ 2019   00435-60000-00000-AA810
Microsoft Visual C++ 2019

ASP.NET and Web Tools 2019   16.4.460.23317
ASP.NET and Web Tools 2019

C# Tools   3.4.1-beta4-19614-01+165046097562cfe65b09c2e9a9d8f7cd88526f2c
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

IntelliCode Extension   1.0
IntelliCode Visual Studio Extension Detailed Info

Microsoft JVM Debugger   1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft MI-Based Debugger   1.0
Provides support for connecting Visual Studio to MI compatible debuggers

Microsoft Visual C++ Wizards   1.0
Microsoft Visual C++ Wizards

Microsoft Visual Studio VC Package   1.0
Microsoft Visual Studio VC Package

NuGet Package Manager   5.4.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

ProjectServicesPackage Extension   1.0
ProjectServicesPackage Visual Studio Extension Detailed Info

Test Adapter for Boost.Test   1.0
Enables Visual Studio's testing tools with unit tests written for Boost.Test.  The use terms and Third Party Notices are available in the extension installation directory.

Test Adapter for Google Test   1.0
Enables Visual Studio's testing tools with unit tests written for Google Test.  The use terms and Third Party Notices are available in the extension installation directory.

Visual Basic Tools   3.4.1-beta4-19614-01+165046097562cfe65b09c2e9a9d8f7cd88526f2c
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual Studio Code Debug Adapter Host Package   1.0
Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

Visual Studio Tools for CMake   1.0
Visual Studio Tools for CMake

Visual Studio Tools for CMake   1.0
Visual Studio Tools for CMake

How can I resolve these errors to run code?

Alok
  • 7,734
  • 8
  • 55
  • 100

0 Answers0