How to dynamically call/or not call Windows.Graphics.Capture's API based on Windows 10 version

xin luo 1 Reputation point

Hi Team,
My Windows C++ desktop application is required to run on all versions of Windows 10 operating systems, and I do want to use Windows.Graphics.Capture APIs to capture other application's window. I Know that Windows.Graphics.Capture is only supported on Windows 10, version 1803 or above. So how to dynamically call/or not call Windows.Graphics.Capture APIs based on Windows 10 version. For example, at the run time, if my application detects that OS is Windows 10 version below 1803, my app will not load the Windows.Graphics.Capture API dll and will not call Windows.Graphics.Capture APIs; if version is 1803 or above, my app will load Windows.Graphics.Capture API dll and call Windows.Graphics.Capture APIs.

Thanks for your help for resolving this issue,

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,070 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Roman R 331 Reputation points

    The best place to ask questions on Windows.Graphics.Capture is here:

    ApiInformation::IsApiContractPresent is the one you need.

    1 person found this answer helpful.

  2. xin luo 1 Reputation point

    Just added two screenshots here, one is win10 version on my machine, the other is runtime error message when running on Windows 10, version 1607. Thanks for your help again.


    0 comments No comments

  3. Castorix31 71,626 Reputation points

    Maybe you can do a test like this (I cannot test if it fails as I have Windows 10 1909) :

    HMODULE hInst = LoadLibrary(L"CoreMessaging.dll");
    if (hInst)
     FARPROC pFunction = (FARPROC&)pFunction = GetProcAddress(hInst, "CreateDispatcherQueueController");
     if (pFunction)
     static IGraphicsCaptureSessionStatics* pStatics;
     HRESULT hr = RoGetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Graphics_Capture_GraphicsCaptureSession).Get(), IID_PPV_ARGS(&pStatics));
     if (SUCCEEDED(hr))
     bOK = TRUE;

    At beginning :

    #include <winrt/Windows.Foundation.h>
    #include <winrt/base.h>
    #include <wrl\wrappers\corewrappers.h>  // HString::MakeReference
    using namespace Microsoft::WRL::Wrappers;
    using namespace winrt;
    #include <roapi.h>
    #include <>
    using namespace ABI::Windows::Graphics::Capture;
    #pragma comment (lib, "windowsapp")