DirectX SDK

Using Bitmasks

Some DirectX types, such as DDSURFACEDESC2, have Long members that serve as bitmasks. It is usual to assign values to these members in hexadecimal form. However, Visual Basic normally attempts to convert hexadecimal constants to the shortest type, with the result that, for example, &HFF would be converted to an Integer with a value of -1. If this value is then passed back to DirectX for Visual Basic where a Long is expected, it is converted to &HFFFFFFFF.

In order to ensure that a hexadecimal bitmask is properly converted, place a second ampersand after the expression, as follows:

DDSD.ddpfPixelFormat.lRBitMask = &HFF&