GDI+ GIVING 2082 errors

gagrim808 26 Reputation points
2021-08-27T05:07:33.613+00:00

I have started with using GDI+ and have written the following code :-
1.
2. #include <gdiplus.h>
3. #include <windows.h>
4. #include <objidl.h>
5. #include <string.h>
6. #include <tchar.h>
7.
8. using Gdiplus;
9.
10. #pragma comment (lib,"Gdiplus.lib")
11.
12. HWND Button;
13. // The main window class name.
14. static TCHAR szWindowClass[] = _T("DesktopApp");
15.
16. // The string that appears in the application's title bar.
17. static TCHAR szTitle[] = _T("Windows Desktop Guided Tour Application");
18.
19. HINSTANCE hInst;
20. int i;
21. int x = 50;
22. int y = 50;
23.
24. // Forward declarations of functions included in this code module:
25. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
26.
27. int WINAPI WinMain(
28. In HINSTANCE hInstance,
29. _In_opt_ HINSTANCE hPrevInstance,
30. In LPSTR lpCmdLine,
31. In int nCmdShow
32. )
33. {
34. GdiplusStartupInput gdiplusStartupInput;
35. ULONG_PTR gdiplusToken;
36. GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
37.
38. WNDCLASSEX wcex;
39.
40. wcex.cbSize = sizeof(WNDCLASSEX);
41. wcex.style = CS_HREDRAW | CS_VREDRAW;
42. wcex.lpfnWndProc = WndProc;
43. wcex.cbClsExtra = 0;
44. wcex.cbWndExtra = 0;
45. wcex.hInstance = hInstance;
46. wcex.hIcon = LoadIcon(NULL, IDI_EXCLAMATION);
47. wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
48. wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
49. wcex.lpszMenuName = NULL;
50. wcex.lpszClassName = szWindowClass;
51. wcex.hIconSm = LoadIcon(wcex.hInstance, IDI_APPLICATION);
52.
53. if (!RegisterClassEx(&wcex))
54. {
55. MessageBox(NULL,
56. _T("Call to RegisterClassEx failed!"),
57. _T("Windows Desktop Guided Tour"),
58. NULL);
59.
60. return 1;
61. }
62.
63. // Store instance handle in our global variable
64. hInst = hInstance;
65.
66. // The parameters to CreateWindowEx explained:
67. // WS_EX_OVERLAPPEDWINDOW : An optional extended window style.
68. // szWindowClass: the name of the application
69. // szTitle: the text that appears in the title bar
70. // WS_OVERLAPPEDWINDOW: the type of window to create
71. // CW_USEDEFAULT, CW_USEDEFAULT: initial position (x, y)
72. // 500, 100: initial size (width, length)
73. // NULL: the parent of this window
74. // NULL: this application does not have a menu bar
75. // hInstance: the first parameter from WinMain
76. // NULL: not used in this application
77. HWND hWnd = CreateWindowEx(
78. WS_EX_OVERLAPPEDWINDOW,
79. szWindowClass,
80. szTitle,
81. WS_OVERLAPPEDWINDOW,
82. CW_USEDEFAULT, CW_USEDEFAULT,
83. 500, 800,
84. NULL,
85. NULL,
86. hInstance,
87. NULL
88. );
89.
90. if (!hWnd)
91. {
92. MessageBox(NULL,
93. _T("Call to CreateWindow failed!"),
94. _T("Windows Desktop Guided Tour"),
95. NULL);
96.
97. return 1;
98. }
99.
100. return 1;
101. }
102.
103. // Main message loop:
104. MSG msg;
105.
106. while (GetMessage(&msg, NULL, 0, 0))
107. {
108. TranslateMessage(&msg);
109. DispatchMessage(&msg);
110. }
111.
112. GdiplusShutdown(gdiplusToken);
113.
114. return (int)msg.wParam;
115. }

And it is giving 2082 COMPILATION ERRORS (which is way too much), and all the errors belong to some or the other header of Gdi+.

Some of them are :-

E0757 variable "OUT" is not a type name WindowsProject1 C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um\gdiplusheaders.h 89

E0757 member "Region::IN" is not a type name WindowsProject1 C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um\gdiplusheaders.h 64

E0757 member "Image::IN" is not a type name WindowsProject1 C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um\gdiplusheaders.h 414

C7525 inline variables require at least '/std:c++17' WindowsProject1 C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um\GdiplusEnums.h 533

C2056 illegal expression WindowsProject1 C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um\GdiplusEnums.h 586

E0020 identifier "INT" is undefined WindowsProject1 C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um\gdiplusflat.h 155

E0020 identifier "META_SETTEXTJUSTIFICATION" is undefined WindowsProject1 C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um\gdiplusenums.h 569

E0020 identifier "GpStatus" is undefined WindowsProject1 C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um\gdiplusflat.h 871

.... and many others.

Can somebody recommend anything. It would be highly appreciable.

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,541 questions
0 comments No comments
{count} votes

Accepted answer
  1. Castorix31 81,831 Reputation points
    2021-08-27T05:32:47.597+00:00

    Fixed sample =>

    #include <windows.h>
    #include <gdiplus.h>
    #include <objidl.h>
    #include <string.h>
    #include <tchar.h>
    
    //using Gdiplus;
    using namespace Gdiplus;
    
    #pragma comment (lib,"Gdiplus.lib")
    
    HWND Button;
    // The main window class name.
    static TCHAR szWindowClass[] = _T("DesktopApp");
    
    // The string that appears in the application's title bar.
    static TCHAR szTitle[] = _T("Windows Desktop Guided Tour Application");
    
    HINSTANCE hInst;
    int i;
    int x = 50;
    int y = 50;
    
    // Forward declarations of functions included in this code module:
    LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
    
    int WINAPI WinMain(
        _In_ HINSTANCE hInstance,
        _In_opt_ HINSTANCE hPrevInstance,
        _In_ LPSTR lpCmdLine,
        _In_ int nCmdShow
    )
    {
        GdiplusStartupInput gdiplusStartupInput;
        ULONG_PTR gdiplusToken;
        GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
    
        WNDCLASSEX wcex;
    
        wcex.cbSize = sizeof(WNDCLASSEX);
        wcex.style = CS_HREDRAW | CS_VREDRAW;
        wcex.lpfnWndProc = WndProc;
        wcex.cbClsExtra = 0;
        wcex.cbWndExtra = 0;
        wcex.hInstance = hInstance;
        wcex.hIcon = LoadIcon(NULL, IDI_EXCLAMATION);
        wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
        wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
        wcex.lpszMenuName = NULL;
        wcex.lpszClassName = szWindowClass;
        wcex.hIconSm = LoadIcon(wcex.hInstance, IDI_APPLICATION);
    
        if (!RegisterClassEx(&wcex))
        {
            MessageBox(NULL,
                _T("Call to RegisterClassEx failed!"),
                _T("Windows Desktop Guided Tour"),
                NULL);
    
            return 1;
        }
    
        // Store instance handle in our global variable
        hInst = hInstance;
    
        // The parameters to CreateWindowEx explained:
        // WS_EX_OVERLAPPEDWINDOW : An optional extended window style.
        // szWindowClass: the name of the application
        // szTitle: the text that appears in the title bar
        // WS_OVERLAPPEDWINDOW: the type of window to create
        // CW_USEDEFAULT, CW_USEDEFAULT: initial position (x, y)
        // 500, 100: initial size (width, length)
        // NULL: the parent of this window
        // NULL: this application does not have a menu bar
        // hInstance: the first parameter from WinMain
        // NULL: not used in this application
        HWND hWnd = CreateWindowEx(
            WS_EX_OVERLAPPEDWINDOW,
            szWindowClass,
            szTitle,
            WS_OVERLAPPEDWINDOW,
            CW_USEDEFAULT, CW_USEDEFAULT,
            500, 800,
            NULL,
            NULL,
            hInstance,
            NULL
        );
    
        if (!hWnd)
        {
            MessageBox(NULL,
                _T("Call to CreateWindow failed!"),
                _T("Windows Desktop Guided Tour"),
                NULL);
    
            return 1;
        }
        ShowWindow(hWnd, SW_SHOWNORMAL);
        UpdateWindow(hWnd);
    
        // Main message loop:
        MSG msg;
        while (GetMessage(&msg, NULL, 0, 0))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
        GdiplusShutdown(gdiplusToken);
        return (int)msg.wParam;
    }
    
    LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        static HWND hWndButton = NULL, hWndStatic = NULL;
        int wmId, wmEvent;
        switch (message)
        {
        case WM_CREATE:
        {
    
            return 0;
        }
        break;  
        case WM_PAINT:
        {
            PAINTSTRUCT ps;
            HDC hDC = BeginPaint(hWnd, &ps);
    
            Graphics* g = Graphics::FromHDC(hDC);
            Rect rect(0, 0, 200, 200);
            ARGB color = Color::MakeARGB(128, 255, 0, 0);
            SolidBrush* brush = new SolidBrush(color);
            g->FillRectangle(brush, rect);
            delete brush;
            delete g;
    
            EndPaint(hWnd, &ps);
        }
        break;
        case WM_DESTROY:
        {
            PostQuitMessage(0);
            return 0;
        }
        break;
        default:
            return DefWindowProc(hWnd, message, wParam, lParam);
        }
        return 0;
    }
    

0 additional answers

Sort by: Most helpful