Should DWORD map to int or uint?

后端 未结 7 2007
抹茶落季
抹茶落季 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:27

    Use int. Reason being, if I change "AutoRestartShell" with a uint variable:

    regKey.SetValue("AutoRestartShell", uintVariable);
    

    the data type in the Registry Editor changes to "REG_SZ". If I ask for that value to be returned with:

    regKey.GetValue("AutoRestartShell");
    

    a string gets returned.

    If, however, I change "AutoRestartShell" with an int variable:

    regKey.SetValue("AutoRestartShell", intVariable);
    

    The data type stays as "REG_DWORD".

    Why does this happen? No idea. All I know is that it does. Logic certainly would tell us that uint should be used but that changes the data type which we don't want.

提交回复
热议问题