Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
A snippet of my code is shown below:
C++
#include "framework.h"
#include "myApp.h"
#include <gdiplus.h>

using namespace Gdiplus;
//#pragma comment (lib,"Gdiplus.lib")

//Some normal declarations go here
int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
                     _In_opt_ HINSTANCE hPrevInstance,
                     _In_ LPWSTR    lpCmdLine,
                     _In_ int       nCmdShow)
{
    UNREFERENCED_PARAMETER(hPrevInstance);
    UNREFERENCED_PARAMETER(lpCmdLine);

    // TODO: Place code here.
    GdiplusStartupInput gdiplusStartupInput;
    ULONG_PTR gdiplusToken;
    GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

    //Some  normal windows code goes here

    GdiplusShutdown(gdiplusToken);

    return (int) msg.wParam;
}

When I comment out everything that has to do with gdiplus, it compiles, but when I don't, it wont't compile. Even after some Googling, I added the #pragma comment like, yet it will not compile until I comment it out. Why is it so?

What I have tried:

I have spent extended time Googling for a solution. It seems there is no relevant one online, not even on Stack Overflow.
Posted
Updated 20-Oct-23 13:44pm
v3
Comments
Richard MacCutchan 19-Oct-23 5:32am    
What do you mean by "it wont"? Please explain clearly what happens when you build or run this program.
Gbenbam 20-Oct-23 19:21pm    
it would give the folowing error messages:


Severity Code Description Project File Line Suppression State
Error (active) E0020 identifier "REAL" is undefined ResultSheets C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um\gdiplusbrush.h 270
Error (active) E0169 expected a declaration ResultSheets C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um\gdiplus.h 82
Error (active) E0020 identifier "IStream" is undefined ResultSheets C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um\gdiplusbitmap.h 50
Error (active) E0020 identifier "IStream" is undefined ResultSheets C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um\gdiplusbitmap.h 85
Error (active) E0020 identifier "Status" is undefined ResultSheets C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um\gdiplusbitmap.h 124
Error (active) E0020 identifier "Status" is undefined ResultSheets C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um\gdiplusbitmap.h 137
Error (active) E0020 identifier "Status" is undefined ResultSheets C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um\gdiplusbitmap.h 150
Error (active) E0020 identifier "IStream" is undefined ResultSheets C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um\gdiplusbitmap.h 152
Error (active) E0020 identifier "Status" is undefined ResultSheets C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um\gdiplusbitmap.h 163
Error (active) E0020 identifier "Status" is undefined ResultSheets C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um\gdiplusbitmap.h 172
Error (active) E0020 identifier "ImageType" is undefined ResultSheets C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um\gdiplusbitmap.h 188
Error (active) E0020 identifier "Status" is undefined ResultSheets C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um\gdiplusbitmap.h 198
Error (active) E0020 identifier "SizeF" is undefined ResultSheets C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um\gdiplusbitmap.h 200
Error (active) E0020 identifier "Status" is undefined ResultSheets C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um\gdiplusbitmap.h 220
Error (active) E0020 identifier "RectF" is undefined ResultSheets C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um\gdiplusbitmap.h 222
Error (active) E0020 identifier "Unit" is undefined ResultSheets C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um\gdiplusbitmap.h 223
Error (active) E0020 identifier "REAL" is undefined ResultSheets C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um\gdiplusbitmap.h 250
Error (active) E0020 identifier "REAL" is undefined ResultSheets C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um\gdiplusbitmap.h 260
Error (active) E0020 identifier "Status" is undefined ResultSheets C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um\gdiplusbitmap.h 280
Error (active) E0020 identifier "PixelFormat" is undefined ResultSheets C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um\gdiplusbitmap.h 286
Error (active) E0020 identifier "Status" is undefined ResultSheets C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um\gdiplusbitmap.h 306
Error (active) E0020 identifier "ColorPalette" is undefined ResultSheets C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um\gdiplusbitmap.h 308
Error (active) E0020 identifier "Status" is undefined ResultSheets C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um\gdiplusbitmap.h 315
Error (active) E0020 identifier "ColorPalette" is undefined ResultSheets C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um\gdiplusbitmap.h 317
Error (active) E0020 identifier "GetThumbnailImageAbort" is undefined ResultSheets C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um\gdiplusbitmap.h 327
Error (active) E0020 identifier "Status" is undefined ResultSheets C:\Program Files (x86)\Windows Kits\10\Inc
Richard MacCutchan 21-Oct-23 4:33am    
If I compile the above code and replace your local includes with #include <windows.h> it compiles without errors. So what exactly are you compiling when you get those errors? And if it really is the code you have shown above, then you need to also show what is in the two header files that you are including.
Gbenbam 20-Oct-23 19:23pm    
By it won,t work? I meant it wont compile successfully.
Richard MacCutchan 21-Oct-23 4:34am    
Well you need to be clear in your question, we cannot guess what you might mean.

What do you mean, exactly, with "when I comment out everything that has to do with gdiplus, it works, but when I don't it wont't"?
Do you get a compilation error (if so, you should post here the exact error message, in order to get better help)?
I've just copied the MSDN GDI+ minimalist example from this page: Drawing a Line - Win32 apps | Microsoft Learn[^] and 'it worked' like a charm (I am using Visual Studio 2022).
 
Share this answer
 
Comments
Gbenbam 20-Oct-23 19:24pm    
Yes, I get compiltion errors:


Severity Code Description Project File Line Suppression State
Error (active) E0020 identifier "REAL" is undefined ResultSheets C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um\gdiplusbrush.h 270
Error (active) E0169 expected a declaration ResultSheets C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um\gdiplus.h 82
Error (active) E0020 identifier "IStream" is undefined ResultSheets C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um\gdiplusbitmap.h 50
Error (active) E0020 identifier "IStream" is undefined ResultSheets C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um\gdiplusbitmap.h 85
Error (active) E0020 identifier "Status" is undefined ResultSheets C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um\gdiplusbitmap.h 124
Error (active) E0020 identifier "Status" is undefined ResultSheets C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um\gdiplusbitmap.h 137
Error (active) E0020 identifier "Status" is undefined ResultSheets C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um\gdiplusbitmap.h 150
Error (active) E0020 identifier "IStream" is undefined ResultSheets C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um\gdiplusbitmap.h 152
Error (active) E0020 identifier "Status" is undefined ResultSheets C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um\gdiplusbitmap.h 163
Error (active) E0020 identifier "Status" is undefined ResultSheets C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um\gdiplusbitmap.h 172
Error (active) E0020 identifier "ImageType" is undefined ResultSheets C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um\gdiplusbitmap.h 188
Error (active) E0020 identifier "Status" is undefined ResultSheets C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um\gdiplusbitmap.h 198
Error (active) E0020 identifier "SizeF" is undefined ResultSheets C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um\gdiplusbitmap.h 200
Error (active) E0020 identifier "Status" is undefined ResultSheets C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um\gdiplusbitmap.h 220
Error (active) E0020 identifier "RectF" is undefined ResultSheets C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um\gdiplusbitmap.h 222
Error (active) E0020 identifier "Unit" is undefined ResultSheets C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um\gdiplusbitmap.h 223
Error (active) E0020 identifier "REAL" is undefined ResultSheets C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um\gdiplusbitmap.h 250
Error (active) E0020 identifier "REAL" is undefined ResultSheets C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um\gdiplusbitmap.h 260
Error (active) E0020 identifier "Status" is undefined ResultSheets C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um\gdiplusbitmap.h 280
Error (active) E0020 identifier "PixelFormat" is undefined ResultSheets C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um\gdiplusbitmap.h 286
Error (active) E0020 identifier "Status" is undefined ResultSheets C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um\gdiplusbitmap.h 306
Error (active) E0020 identifier "ColorPalette" is undefined ResultSheets C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um\gdiplusbitmap.h 308
Error (active) E0020 identifier "Status" is undefined ResultSheets C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um\gdiplusbitmap.h 315
Error (active) E0020 identifier "ColorPalette" is undefined ResultSheets C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um\gdiplusbitmap.h 317
Error (active) E0020 identifier "GetThumbnailImageAbort" is undefined ResultSheets C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um\gdiplusbitmap.h 327
Error (active) E0020 identifier "Status" is undefined ResultSheets C:\Program Files (x86)\Windows Kits\10\Include\10.0.226
Gbenbam 20-Oct-23 19:46pm    
Please, note that none of these errors have anything to do with my code. The are all from gdipus.
If you take out everything from your app that relates to Gdi+, what you are left with is this:
C++
#include "framework.h"
#include "myApp.h"
int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
                     _In_opt_ HINSTANCE hPrevInstance,
                     _In_ LPWSTR    lpCmdLine,
                     _In_ int       nCmdShow)
{
    UNREFERENCED_PARAMETER(hPrevInstance);
    UNREFERENCED_PARAMETER(lpCmdLine);
    return (int) msg.wParam;
}
Which does ... nothing, pretty much.

At a guess, when you put the GDI stuff back in, you get compilation errors, so start here: Using GDI+ - Win32 apps | Microsoft Learn[^]
 
Share this answer
 
The code you are showing uses the Gdiplus functions: GdiplusStartup and GdiplusShutdown so if you are building application without problem then you still referencing gdiplus library somewhere.
You can check the linker parameters of your project or makefile it can reference the library in there.
But it is possible that 3rd party libraries, which you are using linked with the gdiplus and reference it.
Even if the library referenced for the linking you may remove all functions which uses that library from your code and the library will not be linked. Easy way for removing all references just comment #include <gdiplus.h> and resolve building errors, by commenting code or setting up different implementation.
To be sure that you application does not linked with the specified library you can use dependency walker tool. Just load your application in there and check for dependencies.

Regards,
Maxim
 
Share this answer
 
Comments
Gbenbam 20-Oct-23 19:50pm    
I think the application does not compile becuase it did not link with neither gdiplus.lib or gdiplus.dll or both.
I don't remember how to do that in visual stidio. My guese is that part of it is what the #pragma comment is supposed to stop.
Maxim Kartavenkov 21-Oct-23 2:17am    
Yes you can set it with linker option: with project properties: Linker -> Input -> Ignore Specific Default Libraries or with #pragma comment( lib, "/nodefaultlib:<name>")
I use GDI+ extensively without any problems. Maybe you should have a look at some sample programs to see if there is something you are missing. Here is one article at this site : Starting with GDI+[^], and there a number of others here.
 
Share this answer
 
Comments
Gbenbam 20-Oct-23 19:52pm    
I am not new to using Gdiplus. I stopped programming for years. I just resumed this month. I think the application does not compile becuase it did not link with neither gdiplus.lib or gdiplus.dll or both.
I don't remember how to do that in visual stidio. My guese is that part of it is what the #pragma comment is supposed to stop.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900