Search code examples
mfcmsdn

MSDN: "This class and its members cannot be used in applications that execute in the Windows Runtime"


I came across a problem using the CImage class, which is part of MFC:

void SaveBmp(HBITMAP handle, CString name)
{
    CImage image;
    image.Attach(handle);
    image.Save(name,ImageFormatBMP);
}

The symbol ImageFormatBMP is an undeclared identifier.

I went into MSDN section for the CImage class, and saw this bizarre note at the top of the page:

This class and its members cannot be used in
applications that execute in the Windows Runtime.

What is the meaning of this (ridiculous) note?

Where else could this class be possibly used other than within a Windows application?


Solution

  • The Windows Runtime (WinRT) is a special runtime that may be used for applications. This note simply tells you that this classes is not available if you develop an application to run under WinRT.

    Quote from wikipedia:

    Windows Runtime (WinRT), is a platform-agnostic application architecture first introduced in Windows 8 and Windows Server 2012 in 2012. WinRT supports development in C++/CX (Component Extensions, a language based on C++), JavaScript-TypeScript, and the managed code languages C# and Visual Basic .NET (VB.NET). WinRT applications natively support both the x86 and ARM processors, and run inside a sandboxed environment to allow greater security and stability. WinRT components are designed with interoperability between multiple languages and APIs in mind, including native, managed and scripting languages.

    https://en.wikipedia.org/wiki/Windows_Runtime

    Furthermore ImageFormatBMP is part of the GDIPlus but not of CImage class. So using it would require to use include GDIplus the gdiplus header and the according namespace.