Tuesday, February 24, 2009

Memory Mapped File in Delphi

One of the recent learning of mine is to use Memory Mapped File in Delphi. These are the great ways to share data among various libraries within the same application instance.

Step 1: Define a Record Structure and a Pointer to the record.
type
PRecordInfo = ^TRecordInfo;
TRecordInfo = packed record
Field1 : ShortString;
Field2 : Integer;
Field3 : Integer;
end; //TInstanceInfo

Step 2 : Variable Declaration. I prefer to do it in implementation section for many good reasons known to Delphi Programmers.
var
FMappingHandle : THandle = 0;
FRecordInfo : PRecordInfo= nil;
FMappingName : String = '';

Step 3: Manipulate Memory mapped file. Use the code snippets below to perform the operation as per your business logic.

{ To Create a Mapping File }
FMappingHandle := CreateFileMapping($FFFFFFFF, nil, PAGE_READWRITE, 0, SizeOf(TRecordInfo), @FMappingName[1]);
FRecordInfo := MapViewOfFile(FMappingHandle, FILE_MAP_ALL_ACCESS, 0, 0, SizeOf(TRecordInfo));
FRecordInfo.Field1 := 'Value 1';
FRecordInfo.Field2 := 0;
FRecordInfo.Field3 := 1;

{ To Open the Memory Map File }
FMappingName := 'SomeNametoUniquelyIdentifyTheMappingFile';
FMappingHandle := OpenFileMapping(FILE_MAP_ALL_ACCESS, false, @FMappingName[1]);

{ To Read the File Contents}
FRecordInfo := MapViewOfFile(FMappingHandle, FILE_MAP_ALL_ACCESS, 0, 0, SizeOf(TRecordInfo));
LVariable1 := FConfigInfo^.Field1;//Read the Contents
LVariable2 := FConfigInfo^.Field2;//Read the Contents
LVariable3 := FConfigInfo^.Field3;//Read the Contents

Enjoy working with Memory mapped files. I found them best way to share data among different modules of the application. They are quite useful if you have one EXE and multiple DLLs in an application.

Thursday, February 19, 2009

Vista - Lost Network Icon and Volume Icon

For sometime I'm having this problem with my Vista machine. I am loosing the Volume Icon, Power , Network icon located in the task bar (System Tray). I tried multiple ways to get them back but so far only one resource helped more than anything else. This is the help from Microsoft Knowledgebase.

But last week after I lost my icon even the trick mentioned in this document did not bring it back. Now I am searching for some ways to get those icons back. Has anyone experienced the similar problem and have a full-proof solutions? I would love to hear from you.

Wednesday, February 18, 2009

Introducing Geek's Voice

A Warm Hello and Welcome to my readers on this new blog of mine. For past 2+ years I've been blogging about various things be it Semantic Database, Mithila Cuisine or various other blogs. But one thing that was missing in all those blogs were the voice of the inner geek of mine. The opinion about the technology I play with sometime and some of the findings of mine.

I as a geek have my opinions about the technology I use and also what I learn in my day to day life. Some of those I can share with people I work and some of them are kept aside. But here I am going to share the unbiased opinion about what I learn in my day-to-day life as a geek.

With these ideas in mind, I started this blog. I hope to share lots of technical insights with the readers in coming days / weeks / months / years.

Until Next Time....