什么是c++ DWORD的c#等价物?
What is the C# equivalent of C++ DWORD?
经过搜索,我听说UInt32是c#中的c++ DWORD。我通过执行算术
来测试结果*(DWORD*)(1 + 0x2C) //C++
(UInt32)(1 + 0x2C) //C#
它们产生完全不同的结果。有人能告诉我c#中DWORD的正确匹配吗?
您的示例使用DWORD
作为指针,这很可能是一个无效的指针。我假设你指的是DWORD
本身。
DWORD
定义为unsigned long
,最终为32位无符号整数。
uint
(System.UInt32
)应该是匹配的。
#import <stdio.h>
// I'm on macOS right now, so I'm defining DWORD
// the way that Win32 defines it.
typedef unsigned long DWORD;
int main() {
DWORD d = (DWORD)(1 + 0x2C);
int i = (int)d;
printf("value: %dn", i);
return 0;
}
输出:45
public class Program
{
public static void Main()
{
uint d = (uint)(1 + 0x2C);
System.Console.WriteLine("Value: {0}", d);
}
}
输出:45
来自microsoft的DWord定义:
typepedef unsigned long DWORD, *PDWORD, *LPDWORD;https://msdn.microsoft.com/en-us/library/cc230318.aspx
Uint32 definition from microsoft
typedef unsigned int UINT32;https://msdn.microsoft.com/en-us/library/cc230386.aspx
现在您可以看到差异....一个是unsigned long,另一个是unsigned int
这两个代码段做的事情完全不同。在c++代码中,由于一些奇怪的原因,您将值(1 + 0x2C)
(一种奇怪的写45的方式)转换为DWORD*
,然后对其解引用,就好像该地址实际上是一个有效的内存位置一样。使用c#,您只需在整数类型之间进行转换。
相关文章:
- 在C++STL中是否有Polyval(Matlab函数)等价物?
- python集合的C++等价物是什么.计数器
- C++中是否存在 std::conditional 的懒惰等价物?
- std::endl,在 Python 中是否有等价物?(返回 + 刷新)
- 以十六进制打印出 DWORD 会在 win32 c++ 中返回0x7FFFFFFF
- 非法,左操作数具有类型 'DWORD [29]'
- 在本征C++中 MKL 的函数"zgges"等价物是多少?
- 编译时出错 - 从 DWORD 到 LPCVOID 的转换
- 如何在 c++ 中将 DWORD 转换为 PVOID?
- C++添加 2 个 DWORD 的算术溢出
- 是否可以将存储在dword中的十六进制与getasynckeystate一起使用
- 三维数组中的C/C++DWORD到BYTE和BYTE到DWORD的转换
- 在C++中使用std或boost库的Qtimer等价物是什么
- GLM中的Java Matrix4.transform等价物
- 对于std::bitset,是否有一个ffs()等价物
- 警告 C4267"参数":从"size_t"转换为"DWORD&quo
- std::move() 或其在局部变量上的显式等价物可以允许 elision 吗?
- 这个 matlab 代码的C++等价物是什么(fread matlab vs fread C/C++)?
- 键入从 DWORD 到 64 位指针的强制转换警告
- 什么是c++ DWORD的c#等价物?