找回密码
 加入
搜索
查看: 3167|回复: 7

[AU3基础] Au3如何读取一个已建立的内存映射?[已解决]

  [复制链接]
发表于 2012-7-23 16:05:42 | 显示全部楼层 |阅读模式
本帖最后由 oceanwind 于 2012-7-23 18:31 编辑

以下的C++控制台可以读出来名为 jzt_output_price的映射对象 但AU3不知道咋个写 求指教 谢谢先

#include "stdafx.h"  
#include <Windows.h>  
#include <iostream>  
#include <string>  
using namespace std;  
  
DWORD WINAPI FirstThread(PVOID pvParam);  
  
int _tmain(int argc, _TCHAR* argv[])  
{  
  
    HANDLE hFilemap1 = OpenFileMapping(FILE_MAP_READ|FILE_MAP_WRITE,FALSE,_T("jzt_output_price")); //打开名为 jzt_output_price的映射对象.  
    if(hFilemap1 == NULL)  
    {  
  
        cout<<"openfilemapping 失败"<<endl;  
    }  
  
    float *pView = (float*)MapViewOfFile(hFilemap1,FILE_MAP_READ|FILE_MAP_WRITE,0,0,0);  
  
    if(pView == NULL)  
    {  
  
        cout<<"map view 失败"<<endl;  
    }  
    else  
    {  
      
            cout<<*pView;  
  
        UnmapViewOfFile(pView);  
  
    }  
  
    CloseHandle(hFilemap1);  
  
    system("pause");  
    return 0;  
}
 楼主| 发表于 2012-7-23 16:06:59 | 显示全部楼层
写了一下 写不下去了
$hFilemap1 = dllcall("Kernel32.dll","HANDLE","OpenFileMappingW","dword","FILE_MAP_READ|FILE_MAP_WRITE","BOOL","FALSE","wstr","jzt_output_price")
$a_hCall =dllcall("Kernel32.dll","ptr","MapViewOfFile","hwnd",$hFilemap1[0],"dword","FILE_MAP_READ|FILE_MAP_WRITE","DWORD",0,"DWORD",0,"DWORD",0)
 楼主| 发表于 2012-7-23 16:31:24 | 显示全部楼层
看到一个贴子发现一种新的AU3进程通信,非wm_copydatahttp://bbs.wglm.net/forum.php?mo ... 1123&highlight=
直接用
_WinAPI_OpenFileMapping
但是在线文档和帮助中没有发现这个函数啊
发表于 2012-7-23 16:58:13 | 显示全部楼层

Const $FILE_MAP_READ = 4
Const $FILE_MAP_WRITE = 2

Const $SECTION_NAME = "jzt_output_price"

Local $hSection = OpenFileMapping(BitOR($FILE_MAP_READ, $FILE_MAP_WRITE), 0, $SECTION_NAME)
Local $pBaseAddress = MapViewOfFile($hSection, BitOR($FILE_MAP_READ, $FILE_MAP_WRITE), 0, 0, 0)

; Do something with the $pBaseAddress

UnmapViewOfFile($pBaseAddress)
CloseHandle($hSection)


Func OpenFileMapping($iDesiredAccess, $fInheritHandle, $sSectionName)
        Local $iResult
        $iResult = DllCall("Kernel32.dll", "handle", "OpenFileMappingW", "dword", $iDesiredAccess, "bool", $fInheritHandle, "wstr", $sSectionName)

        Return $iResult[0]
EndFunc        ;==>OpenFileMapping

Func MapViewOfFile($hSection, $iDesiredAccess, $iOffsetHigh, $iOffsetLow, $iNumberofBytesToMap)
        Local $iResult
        $iResult = DllCall("Kernel32.dll", "ptr", "MapViewOfFile", "handle", $hSection, "dword", $iDesiredAccess, "long", $iOffsetHigh, "long", $iOffsetLow, "long", $iNumberofBytesToMap)

        Return $iResult[0]
EndFunc        ;==>MapViewOfFile

Func CloseHandle($hObject)
        Local $iResult
        $iResult = DllCall("Kernel32.dll", "bool", "CloseHandle", "handle", $hObject)

        Return $iResult[0]
EndFunc        ;==>CloseHandle

Func UnmapViewOfFile($pBaseAddress)
        Local $iResult
        $iResult = DllCall("Kernel32.dll", "bool", "UnmapViewOfFile", "ptr", $pBaseAddress)

        Return $iResult[0]
EndFunc        ;==>UnmapViewOfFile


进程通信必须要满足两个原则,一是能够数据共享,二是必须有线程同步机制。用内存映射的方式来回传递数据并不算真正意义上的进程通信,因为它只有数据共享,而没有线程同步,所以就必须在一个循环中实时监测内存中的数据。

评分

参与人数 2金钱 +40 贡献 +2 收起 理由
haijie1223 + 30 + 2 P侠的windows编程确实很强大!
oceanwind + 10 谢谢

查看全部评分

 楼主| 发表于 2012-7-23 18:30:58 | 显示全部楼层
进程通信必须要满足两个原则,一是能够数据共享,二是必须有线程同步机制。用内存映射的方式来回传递数 ...
pusofalse 发表于 2012-7-23 16:58

太感谢..........
发表于 2013-1-21 22:21:00 | 显示全部楼层
留个名,向高手学习
发表于 2013-3-23 10:32:25 | 显示全部楼层
学习了,今天又小积一点。
发表于 2013-11-27 13:16:08 | 显示全部楼层
大神 分享,学习一下
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-9-28 17:29 , Processed in 0.087588 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表