B
barryani
Unregistered / Unconfirmed
GUEST, unregistred user!
我在程序中利用映射系统的页面文件的方法实行在两个进程中<br>通信的时候如果只传递文字,数字的时候就成功,但如果传递<br>TBITMAP就发生错误,大概代码如下:<br>library ShareLib;<br>uses<br> ShareMem,Windows,SysUtils,Graphics,Types,Dialogs,<br> Classes;<br>const<br> MapName: Pchar ='ShareFile';<br><br>Type<br> PGlobalData = ^TGlobalData;<br> TGlobalData = record<br> Information:String[50];<br> Number:Integer;<br> Mybitmap:TBitmap;<br> end;<br>var<br> GlobalDataGlobalData;<br> MapHandle:THandle;<br>procedure GetGlobalData(var MyGlobalDataGlobalData);stdcall;<br>begin<br> MyGlobalData:=GlobalData;<br>end;<br><br>procedure OpenShareData;<br>var<br> size:Integer;<br>begin<br> size:=sizeof(TGlobalData);<br> MapHandle:=CreateFileMapping(DWORD(-1),NIL,PAGE_READWRITE,0,size,MapName);<br> if MapHandle=0 then<br> RaiseLastWin32Error;<br> GlobalData:=MapViewOfFile(MapHandle,FILE_MAP_ALL_ACCESS,0,0,size);<br> GlobalData^.Information:='This is a Test';<br> GlobalData^.Number:=1;<br> GlobalData^.Mybitmap.LoadFromFile('f:/chip.bmp');<br> if GlobalData=nil then<br> begin<br> CloseHandle(MapHandle);<br> RaiseLastWin32Error;<br> end;<br>end;<br><br>procedure CloseShareData;<br>begin<br> UnmapViewOfFile(GlobalData);<br> CloseHandle(MapHandle);<br>end;<br><br>procedure DllEntryPoint(dwReasonWORD);<br>begin<br> case dwReason of<br> DLL_PROCESS_ATTACH:OpenShareData;<br> DLL_PROCESS_DETACH:CloseShareData;<br> DLL_THREAD_ATTACH:;<br> DLL_THREAD_DETACH:;<br> end;<br>end;<br><br>exports<br> GetGlobalData;<br>{$R *.res}<br><br>begin<br> DllProc:=@DllEntryPoint;<br> DllEntryPoint(DLL_PROCESS_ATTACH);<br>end.<br>请帮帮小弟,谢谢!!