Win32 SDK 程序!ReadProcessMemory ( hProcess ,(LPVOID)0x00449B40 ,(LPVOID)&dwBase ,sizeof(dwBase) ,NULL );程序可以成功编译,但是给出不少警告!!winmain.cpp
.\winmain.cpp(273) : warning C4312: “类型转换”: 从“DWORD”转换到更大的“LPVOID以前在 VC6 下是没有问题的,我在程序中 sizeof(LPVOID)结果返回 4 ,长度和 DWORD 一样啊,为什么强制转换时会给出 LPVOID 更大的警告!下面这个问题最重要,我怎么做能消掉这个警告!!!

解决方案 »

  1.   

    那是vc6不够严格,你需要用reinterpret_cast
    ReadProcessMemory ( hProcess ,reinterpret_cast<LPVOID>(0x00449B40) ,(LPVOID)&dwBase ,sizeof(dwBase) ,NULL );
      

  2.   

    在64位机上,sizeof(LPVOID)的值是8。
      

  3.   

    ReadProcessMemory ( hProcess ,(LPVOID)(dwBase + 0x10) ,(LPVOID)&szName ,sizeof(szName) ,NULL );这句怎么转换
      

  4.   

    照猫画虎当然会,只是警告仍然存在。这次警告变成了:.\winmain.cpp(278) : warning C4312: “reinterpret_cast”: 从“DWORD”转换到更大的“LPVOID”
      

  5.   

    写全一些,是这样的:ReadProcessMemory ( hProcess ,reinterpret_cast<LPVOID>(dwBase + 0x10) ,(LPVOID)&szName ,sizeof(szName) ,NULL );
    警告是:
    .\winmain.cpp(278) : warning C4312: “reinterpret_cast”: 从“DWORD”转换到更大的“LPVOID”
      

  6.   

    MSDN说的很清楚,如果你使用了/Wp64开关,这个警告必然存在。你试图把一个32位数据赋值给一个64bit的类型(sizeof(LPVOID)=8),又希望系统检测这个问题,这个warning当然会出来感觉你在试图在64bit的系统上沿用32位系统上的那个跨进程访问数据的技术,也许这个技术本身需要思量思量。不过这是题外话不管怎么说,下面的MSDN的说明了如果你不去掉/Wp64开关,就不可能避免这个警告。还是打开MSDN把错误号输入进去仔细研究吧Error Message
    'operation' : conversion from 'type1' to 'type2' of greater size
    This warning detects 64-bit portability issues. You attempted to assign a 32-bit value to a 64-bit type. For example, casting a 32-bit int or 32-bit long to a 64-bit pointer.This can be an unsafe conversion in some circumstances when sign extension occurs. If a negative number is assigned to a pointer type of a size greater than the int, sign extension will occur and the pointer value will refer to a memory address different from the value of the int.This warning is only issued when /Wp64 is used. See /Wp64 for more information. Also, see Rules for Using Pointers.The following code sample generates C4312:
      

  7.   

    谢谢,刚刚我也发现了,关掉 /WP64 OK 了,结题,祝新年快乐