c++ - 如何在 Microsoft Visual Studio Community 2019 中运行 Microsoft DirectShow 官方示例 C++ 代码?
问题描述
我是 Window 和DirectShow开发的新手。我正在关注官方文档。
我想测试和播放他们在https://docs.microsoft.com/en-us/windows/win32/directshow/how-to-play-a-file上给出的示例代码,但我遇到了错误。
代码是:
#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();
}
错误是:
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
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
如何解决这些错误以运行代码?