DLL memory information retreival
Good day! The project I'm working on involves a 3rd party client managing software (Ontos). When you select a client, a dll named "DataDLL.DLL" holds the primary keys (4 letter combinations) for the current client. Each of those keys relates to the various databases for employer's, clients, icd9 codes, phone number, etc.etc.
My goal is to access this information held in memory. According to the software designer (Andy) the information in DATADLL.DLL is re-populated each time you switch clients. Andy told me this would be possible to access, therefore he sent me an email containging the following:
"Here is the entirety of DATADLL.DLL. The only call is to the procedure GetDLLData, which kind of initializes everything. After that, all access is done with simple, basic record identifiers. The include file (that is the {$I DLLDATA.INC} reference is attached. It holds the definition on the record. Since it appears in every module, doing it as an include keeps all modules up-to-date if it changes.
************************************
library DataDLL;
{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }
uses
ShareMem,
Windows,
SysUtils,
Classes;
{$IMAGEBASE $4000000}
const
cMMFileName : PChar = 'SharedMapData';
{$I DLLDATA.INC}
var
GlobalData : PGlobalDLLData;
MapHandle : THandle;
{ GetDLLData will be the exported DLL function }
procedure GetDLLData(var AGlobalData : PGlobalDLLData); StdCall;
begin
{Point AGlobalData to the same memory address referred to by GlobalData}
AGlobalData := GlobalData;
end;
procedure OpenSharedData;
var Size : integer;
begin
{Get the siz of the data to be mapped}
Size := SizeOf(TGlobalDLLData);
{Now get a memory-mapped file object. Note the first parameter passes the value $FFFFFFFF or
DWord(-1) so that the space is allocatted from the system's paging file. This requires that
a name for the memory-mapped object gets pasted as the LAST parameter.}
MapHandle := CreateFileMapping(DWord(-1), nil, PAGE_READWRITE, 0, Size, cMMFileName);
if MapHandle = 0 then
RaiseLastWin32Error;
{Now map the data to the calling process's address space and get a pointer to the beginning of this address}
GlobalData := MapViewOfFile(MapHandle, FILE_MAP_ALL_ACCESS, 0, 0, Size);
{Initialize this data}
if GlobalData = nil then
begin
CloseHandle(MapHandle);
RaiseLastWin32Error;
end;
end; {OpenSharedData}
procedure CloseSharedData;
{This procedure un-maps the memory-mapped file and releases the memory-mapped file handle}
begin
UnmapViewOfFile(GlobalData);
CloseHandle(MapHandle);
end; {CloseSharedData}
procedure DLLEntryPoint(dwReason : DWord);
begin
case dwReason of
DLL_PROCESS_ATTACH : OpenSharedData;
DLL_PROCESS_DETACH : CloseSHaredData;
end; {case dwReason}
end; {DLLEntryPoint}
exports GetDLLData;
begin
{First, assign the procedure to the DLLProc variable}
DLLProc := @DLLEntryPoint;
{Now invoke the procedure to reflect that t he DLL is attaching to the process}
DLLEntryPoint(DLL_PROCESS_ATTACH);
end.
***********************************************
The attached information he refers to was:
"{ShareLib include file for data definitions}
type
PGlobalDLLData = ^TGlobalDLLData;
TGlobalDLLData = record
ClientID,
MatterID,
EmployerID,
EmpRepID,
DefenseID,
ProviderID,
PersonelID,
LocationID,
StatusID,
BWCID,
SateliteID,
MCOID,
CoCounselID,
FilingsID,
OtherID : string[4];
RID : longint;
ClientX,
ClientY,
MatterX,
MatterY : word;
s : string[100];
MatterDLLHLib : THandle;
end;
Please keep in mind that i"m relatively new to C++ programming, but have for years been dabbling "around it" in VB, macros, etc. I have not ventured into an area like this which is why I have arrived here to ask. I currently have Visual C++ 6.0 installed.
What I would like to do at the moment, to assure accruacy of the information, is to create a small program that will sit beside the Ontos display and show some of the current information (ie name/address/etc) whenever you change a client in the Ontos program. From that I would then work toward implementing the printing of the state's forms based on that retrieved information.
I would greatly appreciate any assistance or information on whether or not this can be done, the best way I could go about doing this, etc. I'm very eager to learn for future projects as well.
Thanks for your time.
Michael

