# LoadImage and windows.h

## Recommended Posts

Storyyeller    215
So, I had code like this that worked great. However, one day I decided to include windows.h, and suddenly, it refused to compile.
SDL_Surface* imageManager::LoadImage(const ImgDataStruct& data)
{
QPCTimer mytimer;
SDL_Surface* rval = data.Load();
return rval;
}

SDL_Surface* imageManager::DereferenceID(ImageID h)
{
assert(IsValid(h));
if (loadedimages.at(h) == NULL)
{
}
}



##### Share on other sites
jyk    2094
Quote:
 What the heck? "LoadImageA" does not appear anywhere in my source code. The only guess I had was that there is some macro in the winapi which is changing LoadImage to LoadImageA for some reason.
I believe LoadImage is a macro that resolves to either LoadImage or LoadImageA depending on what character set is being used. In your case, it looks like it's resolving to LoadImageA, which is then generating the error you mentioned.
Quote:
 Is this true? Why on earth would anyone ever create a macro that was a) defined in the main header, and b) not ALLCAPS?
Welcome to Windows :) In Windows' defense though, the Windows API has been around for some time, and a lot of this stuff is left over from the days of C where this sort of macro usage was much more common (at least I believe that to be the case - I'm sure someone will correct me if I'm wrong).
Quote:
 Also, is there any way to prevent the winapi from polluting the namespace? For now, I just renamed my LoadImage function, but ideally there's a better way. If I'm only using one or two of the windows functions, I don't want every single one.
Whenever I run into these problems, I just #undef the offending symbol(s) as necessary.

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account