CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: DLL memory information retreival

  1. #1
    Join Date
    Oct 2007
    Posts
    2

    DLL memory information retreival

    I hope I labeled this correctly.

    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

  2. #2
    Join Date
    Aug 2001
    Location
    Germany
    Posts
    1,384

    Re: DLL memory information retreival

    Could you please explain in more details what exactly you mean by DLL memory info retreival??? Is there any exported function that returns that data/memory??? or you want to sortof read within your program that DLL's memory (which is loaded in another process)???

    Regards,
    Usman.

  3. #3
    Join Date
    Oct 2007
    Posts
    2

    Re: DLL memory information retreival

    Thanks for the reply. First of all, when I speak with Andy he tends to forget that I'm "newer" to programming than his 30+ years, so please forgive me if I use a wrong term or label something "wrong". With that said, I'll try to explain further.

    First a bit of background. The law firm I work for came from an old DOS system that was quite nice but very outdated. Just entering a few keywords in that old system performed multiple tasks without much user input. Since the firm went to this "updated" casemanager, those single-step instance are gone and we now must use multiple programs and multiple steps to do the same thing.

    So, my employer asked me to see if there was a way I could write at least a small program utilizing the current database so in a couple of clicks we could populate and print the forms for the current client the employee is working on. After talking with Andy, using the database ID's stored via the DataDLL.DLL would allow me to do that. In his email to me he explained that "GetDLLData" is the only call to the procedure. The way he presents the idea sounds like it "shouldn't be" too much trouble, but without being paid (which the firm won't do) he won't work with me on how to write what I need to access those database ID's.

    I guess in answer to your question, Usman, it sounds from Andy's description like there is an exported function that provides the data, however I would be happy with whatever would be easiest and most efficient to obtain those ID's.

    I hope that clears up my intentions more than my first post. Again, I'm sorry if I'm lacking in my descriptive skills in regard to the C++ terminology but I can promise that as I learn more, I'll "clean" that up in a manner of speaking

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)