HMonitor undeclared in dxgi.h with WINAPI_FAMILY_GAMES macro

jacob kristersson 6 Reputation points
2022-09-27T09:25:02.207+00:00

code is as follows:

#pragma once  
#define WINAPI_FAMILY WINAPI_FAMILY_GAMES  
#define NOMINMAX  
#define NOKANJI  
#define WIN32_LEAN_AND_MEAN  
  
#include <windows.h>  
#include <dxgi.h>  
#include <d3d11.h>  

compilation results in E0020 identifier "HMONITOR" is undefined

looking into <dxgi.h> on line 210:

if !defined(HMONITOR_DECLARED) && !defined(HMONITOR) && (WINVER < 0x0500)  
#define HMONITOR_DECLARED  
#if 0  
typedef HANDLE HMONITOR;  
  
#endif  
DECLARE_HANDLE(HMONITOR);  
#endif  
typedef struct DXGI_OUTPUT_DESC  
    {  
    WCHAR DeviceName[ 32 ];  
    RECT DesktopCoordinates;  
    BOOL AttachedToDesktop;  
    DXGI_MODE_ROTATION Rotation;  
    HMONITOR Monitor;  
    } 	DXGI_OUTPUT_DESC;  

and <windef.h> on line 107:

#pragma region Application Family  
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_SYSTEM)  
  
DECLARE_HANDLE(HMONITOR);  
  
#endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_SYSTEM) */  
#pragma endregion  

How do you resolve this without changing WINAPI_FAMILY to WINAPI_FAMILY_DESKTOP_APP?

Windows development | Windows API - Win32
{count} vote

1 answer

Sort by: Most helpful
  1. Junjie Zhu - MSFT 21,646 Reputation points
    2022-09-28T09:07:41.447+00:00

    Hello @jacob kristersson ,
    Welcome to Microsoft Q&A!

    You can modify the value of WINVER in the header file to make it less than 0x0500, like #define WINVER 0x0499

    For details, please refer to this document Update WINVER and _WIN32_WINNT.

    Thank you.
    Junjie


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.