WinSDK - definition of constants

I’ve been experimenting with Swift on Windows a little bit, and found that there seems to be an error in the type specification for a couple of constants:

Constant Name Defined Type Expected Type
GENERIC_READ UInt32 UInt32 (this is a DWORD)
GENERIC_WRITE Int32 UInt32 (this is a DWORD)
GENERIC_EXECUTE Int32 UInt32 (this is a DWORD)
GENERIC_ALL Int32 UInt32 (this is a DWORD)

While this isn't a massive deal, I'm kind of interested to know what may have led to these types being specified.

This is expected behaviour. These are not from the WinSDK overlay but from the WinSDK clang module. The clang importer imports macro values as CInt as per the type promotion rules of C. If you want these constants to be directly usable, I would point you to GitHub - compnerd/swift-platform-core: Currency types for cross-platform support in Swift as the best option for having a more comfortable time working with the Windows APIs.

1 Like

Ah, OK that makes sense, thanks.