Should DWORD map to int or uint?

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

    Sadly,read Registry must use int otherwise throw exception.this microsoft code:

    private static void Get45or451FromRegistry()
    {
        using (RegistryKey ndpKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey("SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v4\\Full\\")) {
            if (ndpKey != null && ndpKey.GetValue("Release") != null) {
                Console.WriteLine("Version: " + CheckFor45DotVersion((int) ndpKey.GetValue("Release")));
            }
          else {
             Console.WriteLine("Version 4.5 or later is not detected.");
          } 
        }
    }
    

    although release is REG_DWORD

提交回复
热议问题