FastMM4 - Help with shared memory ?



Hi all,

I have to write something to help third party vendors to send strings to my application.

What I thought was to write a simple DLL that shares Memory with my application. Third parties just have to load the DLL and call the "PainlessSendAStringToPierreApplication(What: PChar)"

I just have to remember my MainForm Handle to send it messages.

Host Application :

LoadLibrary('SendAStringToPierre.dll');
GetProcAddress(dllHandle, 'InitLibrary')
InitLibrary(Self.Handle)

DLL :

InitLibrary(Hnd: THandle)
begin
[shared] HostHandle := HostHandle; // here
end

PainlessSendAStringToPierreApplication(What: PChar) : Boolean; stdcall;
begin

if [shared] HostHandle = 0 then
Result := false
else
begin
Atom = GlobalAddAtom(What);
Result := SendMessage([shared] HostHandle,
WM_PIERREMESSAGE, Atom, 0) <> 0;
GlobalDeleteAtom(Atom);
end;

end;

Third Party Application :

LoadLibrary('SendAStringToPierre.dll');
GetProcAddress(dllHandle, 'PainlessSendAStringToPierreApplication')
PainlessSendAStringToPierreApplication(PChar('Hello Pierre !'));

Can FastMM help me to share this memory or do I have to create shared memory using CreateFileMapping/MapViewOfFile ?

.... or do you have better ideas to achieve this ?

Best Regards,

--
Pierre Y.


.


Quantcast