本帖最后由 goodabc 于 2009-07-01 08:06:02 编辑

解决方案 »

  1.   

    1、双精度是8个字节的,你才读了4个字节
    2、如果的确是4个字节的,那么目标数据应该是单精度的
    3、确定好源数据的精度类型,更改你Di1、Di2、Di3、Di4、Di5的定义为Double或Single
      

  2.   

    我菜鸟,代码没有全部看,但感觉这些方面有问题:
    1:不知道是不是缺这个常量声明?如果不缺,就继续看下面的
       Const PROCESS_ALL_ACCESS = &H1F0FFF 2:不知道函数的返回值是不是错了,下面的红色Integer应该根据你需要得到的数据属于什么类型的就返回什么类型,如3.14有小数点的就As Single  这里返回长整形就 As Long
    并不是不能用As Integer,你可以都试试,结果肯定是不一样的。
       这个Private Function ncnr(lpADDress As Long) As Integer 
       可以改成Private Function ncnr(lpADDress As Long) As Long 或 其他数据类型。3:用你的代码试了试,确实是这样:窗体上双击添加Label控件6次,timer双击1次,Interval间隔100毫秒Const PROCESS_ALL_ACCESS = &H1F0FFFPrivate Const VK_HP = &H31
    Private Const VK_MP = &H32
    Private Const VK_TL = &H33Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
    Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
    Private Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, ByVal lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
    Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
     
     
     
     Private Function ncnr(lpADDress As Long) As Long
    ' 声明一些需要的变量
    Dim hwnd As Long ' 储存 FindWindow 函数返回的句柄
    Dim pid As Long ' 储存进程标识符( Process Id )
    Dim pHandle As Long ' 储存进程句柄
    hwnd = FindWindow(vbNullString, "计算器")
    ' 取得进程标识符
    GetWindowThreadProcessId hwnd, pid
    ' 使用进程标识符取得进程句柄
    pHandle = OpenProcess(PROCESS_ALL_ACCESS, False, pid)
    ' 在内存地址中读取数据
    ReadProcessMemory pHandle, lpADDress, ByVal VarPtr(ncnr), 4, 0&
    ' 关闭进程句柄
    CloseHandle hProcess
    End FunctionPrivate Sub Form_Load()Di1 = &H400000
    Timer1.Enabled = True
    End Sub
    Private Sub Timer1_Timer()
    Dim hwnd As Long
    hwnd = FindWindow(vbNullString, "计算器")
    If hwnd = 0 Then
    Label6.Caption = "程序未加载"
    Else
    Label6.Caption = "程序已加载"
    Nowhp1 = ncnr(Di1)
    Label1.Caption = "价格:" & str(Nowhp1)
    End If
    End Sub
      

  3.   

    这个Private Function ncnr(lpADDress As Long) As Byte 也可以试试