Suppose one wants to write a program that plays latest version of files in the widely used mp3 format. What libraries (or functions, methods, etc) should one include in their program in the first place. How can one make language instructions do something like that? There must be more clever ways of doing things than doing them all over again. Having the source code available of such programs available with adequate, almost step-by-step explanations, is always a great boon, though they may be costly. One may make alterations as they wish, but that is not the expectation here, although it is desirable. Getting the right codecs to play files of a desired format can either be done freely or associated with cost.
There does not seem to be much literature that 1) Provides an outline of what should be done to make a fully fledged program from scratch. 2) Covers extra guidance and/or information on any part of the outline one would like to expand on. There is certainly a large body of literature on language instructions or, roughly speaking, commands (eg getch(), putch(), etc). But useful as it may be when invoked at exactly the right time and used as appropriate reference, that is definitely not what is meant here. 3) Points to practical, tangible tools (eg libraries) one is going to use, at least basic ones. Such a piece of literature would tell one that if they are going to write (or make) a media player program that includes coverage of such and such media libraries that amount to a hypothetical 23 files.
Resolving such a barrier to either visual, console, Windows or API programming may introduce a boom to the programmer community, just like the introduction of visual programming did. It may lead to rise of new figures in the programming communities while it may extend junk programming as well. Experience shows the latter should not pose a risk to the software community.
// Visual C++ example
#include <dshow.h>
#include <cstdio>
// For IID_IGraphBuilder, IID_IMediaControl, IID_IMediaEvent
#pragma comment(lib, "strmiids.lib")
// Obviously change this to point to a valid mp3 file.
constwchar_t* filePath = L"C:/example.mp3";
int main()
{
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 0;
}
// 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 0;
}
hr = pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl);
hr = pGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent);
// Build the graph.
hr = pGraph->RenderFile(filePath, 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.
}
}
// Clean up in reverse order.
pEvent->Release();
pControl->Release();
pGraph->Release();
::CoUninitialize();
}