Sign in to follow this  
Storyyeller

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();
    Debug2("Loading time", mytimer.milliseconds());
    return rval;
}

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

Eventually, I figured out that there was a windows function called LoadImage which was confusing the compiler. So I changed the line loadedimages.at(h) = LoadImage( loadedimgdata.at(h) ); to loadedimages.at(h) = imageManager::LoadImage( loadedimgdata.at(h) ); This fixed most of the problems, but there was still one, baffling compiler error. Something like SDL_Surface* LoadImageA(const ImgDataStruct& data) not defined 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. Is this true? Why on earth would anyone ever create a macro that was a) defined in the main header, and b) not ALLCAPS? 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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

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

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this