防止Registry.GetValue溢出
我正在尝试使用以下方法获取 DWM colorizationColor: Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\DWM").GetValue("ColorizationColor")
但是它返回 -2144154163 (真实值是2150813133)
我认为这是因为该值无法保存在32位int上...但是事件转换(或转换)为int64失败。
PD:这听起来像是一个很容易回答的问题,但我找不到解决方案:(
I'm trying to get the DWM colorizationColor using:Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\DWM").GetValue("ColorizationColor")
however it is returning -2144154163 (the real value is 2150813133)
I thinks this is because the value cannot be hold on a 32-bit int... however event casting (or Converting) to int64 fails.
PD: It may sound like an easy question to answer but I cannot find a solution :(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
颜色值作为 int 值非常不切实际,最好快速转换它。使用一个小包装来处理密钥也没有什么坏处:
但是不要这样做,有一个记录在案的 API。 P/Invoke DwmGetColorizationColor() 来获取值,您将获得有保证的兼容性行为。如果未来的某个 Windows 版本更改了此注册表详细信息,则很重要。请访问 pinvoke.net 查看声明。
Color values are pretty impractical as int values, it is best to convert it quickly. A little wrapper to dispose the key doesn't hurt either:
But don't do it this way, there's a documented API for it. P/Invoke DwmGetColorizationColor() to get the value, you'll get guaranteed compatibility behavior. Important if some future Windows version changes this registry details. Visit pinvoke.net for the declaration.
您需要进行未经检查的转换:
编辑:
Registry.GetValue
返回一个包含装箱的Int32
值的对象
。您无法在一次转换中取消对值的装箱并转换为不同的值类型< /a>.
当直接从对象进行转换时,您需要首先将其拆箱为其实际类型,然后将其转换为
uint
:You need to make an unchecked cast:
EDIT:
Registry.GetValue
returns anobject
containing a boxedInt32
value.You cannot unbox the value and cast to a different value type in a single cast.
When casting directly from object, you need to first unbox it to its actual type, then cast it to
uint
: