Should DWORD map to int or uint?

后端 未结 7 1989
抹茶落季
抹茶落季 2021-02-06 22:58

When translating the Windows API (including data types) into P/Invoke, should I replace DWORD with int or uint?

It\'s normally unsigned, but I

7条回答
  •  粉色の甜心
    2021-02-06 23:34

    A DWORD is, by (Microsoft's) definition, an unsigned 32-bit integer. It should map to whichever type your compiler uses to represent that.

    These days it's most likely an unsigned int, but that's not a portable implementation. I know you're using C#, but to give you an example in a language I'm more familiar with, a typical implementation in C might be:

    #if defined(SOME_HARDWARE_IMPLEMENTATION)
    #define DWORD unsigned int
    #elif #defined(SOME_OTHER_IMPLEMENTATION)
    #define DWORD unsigned long
    #elif #defined(YET_ANOTHER_IMPLEMENTATION)
    #define DWORD something_else
    #else
    #error Unsupported hardware; cannot map DWORD
    #endif
    

提交回复
热议问题