Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I seem have a problem returning a r

Status
Not open for further replies.

csbrmg

Programmer
Jul 1, 2003
9
ZA
I seem have a problem returning a reference to a shared memory location and keep on getting a run time at the specified location below...
this is the code

class function TActivityLogger.NewInstance: TObject;
var
llInit:Boolean;
temp:LoggerPointer;
begin
HMapping:=CreateFileMapping($FFFFFFFF,nil,PAGE_READWRITE,0,MAPFILESIZE,pchar('my mem'));
...
llInit:=(getLastError()<>ERROR_ALREADY_EXISTS);
if ( llInit ) then //first instance
begin
temp:=mapViewOfFile(HMapping,fILE_MAP_all_access,0,0,0);
....
Result:=temp^.instance ;
end
else
begin
HMapping:=openfilemapping( FILE_MAP_all_access,true, pchar('my mem'));
...
temp:=MapViewOfFile(HMapping,FILE_MAP_all_access,0,0,0);
...
Result:=temp^.instance;//<-Runtime error occurs here
end;
end;
 
one last thing!

you might want to look into NamedPipes - depending on what y're trying to acheive with you memory map files :)

I found NamedPipes easier as they handle access synchronisation much more readily :) Otherwise you end up creating events to manage who gets access to your memory map file etc...
 
gah!!!! my previous post was lost!!!

I think the problem is that you have indicated that you don't want the HMapping handle to be inherited but then attempt to inherit it in the OpenFileMapping call. You might need to create some blank SecurityAttributes so that you can share the handle - the code for this is relatively simple:

var
SA: TSecurityAttributes;
PSD: TSecurityDescriptor;
begin
InitializeSecurityDescriptor(@PSD, SECURITY_DESCRIPTOR_REVISION);
SetSecurityDescriptorDacl(@PSD, True, nil, False);
SA.nLength := Sizeof(SA);
SA.lpSecurityDescriptor := @PSD;
SA.bInheritHandle := True;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top