UTexture::UpdateResource() overwrote by winbase.h #define

There’s lots of nasty things in winbase that uses the preprocessor to define a reference to either the W (wide character) or A (ASCII character) version of windows functions, based on whether you have the wide character compilation flag raised.

I’ve not come across this exact issue, but if you simply need a resolution, include winbase.h in your precompiled header file, then #undef UpdateResource.

I have a UTexture2D* variable called texture. UTexture2D has a macro called “UpdateResource” that calls “UpdateResourceW()”. When I call “texture->UpdateResource();”, I get the error “class “UTexture2D” has no member “UpdateResourceW””.

EDIT: Going to the definition in VS takes me to WinBase.h. So it’s using some #define from WinBase, which overwrites it, then trying to call the newly named function name UpdateResourceW on the Texture2D reference?.

        texture = UTexture2D::CreateTransient(ImageWrapper->GetWidth(), ImageWrapper->GetHeight(), PF_B8G8R8A8);
        void* textureData = texture->PlatformData->Mips[0].BulkData.Lock(LOCK_READ_WRITE);
        FMemory::Memcpy(textureData, DecodedImage.GetData(), DecodedImage.Num());
        texture->PlatformData->Mips[0].BulkData.Unlock();
        texture->UpdateResource();

Similar to what I did. I just #define UpdateResource UpdateResource right above the call. using #undef is probably a more standard/cleaner way, though.

For those who run into this error later, like I did:

You need to add #include "Windows/MinWindows.h" anywhere before the header that causes your errors!

It works for any similar type of Windows-redefine-errors