How can I undeclare DECLARE_HANDLE?

801 Views Asked by At

I'm porting a piece of code from VC6 to VS2008. The code typedefs HSPRITE as int. But Windows SDK 6.1 already declared HSPRITE through DECLARE_HANDLE. I don't want to rename HSPRITE in my code since it will consume a lot of time to rename it in .cpp files. So, how can I undeclare HSPRITE?

2

There are 2 best solutions below

0
On BEST ANSWER

Best is what @ybungalobill says. If you absolutely cannot use his answer, you can also trick windows.h into not declaring it, like this:

#define HSPRITE DeletedWinapi_HSPRITE// prevent windows.h from defining it
#include <windows.h>
#undef HSPRITE

typedef int HSPRITE;
1
On

The only correct way is to not include the header that defines HSPRITE, which may not be an option.

Alternatively you should check out one of the following:

  1. Do you really use HSPRITE as an int? Maybe you can remove the definition of HSPRITE from your code and use the one defined in windows' headers.

  2. Use Find and Replace to rename HSPRITE to some other name in your code; it's a matter of a few seconds.