Results 1 to 7 of 7

Thread: Shared Data in a DLL

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2001
    Location
    UK
    Posts
    222

    Question Shared Data in a DLL

    I am working on a dll at the mo which needs to be adapted from the original 16 bit version. Now from what i have read i understand that LibMain would only have been called once, where as dllmain is called for each new process, which gets its own memory address space! So to get round this i added a variable that would toggle once the dll had been entered the first time, and therefore avoid being repeated every new process:

    #pragma data_seg("SHARDATA")
    static HWND hwndMain = NULL;
    static int nLineHeight = 0;
    int calledonce = 0;
    #pragma data_seg()

    calledonce would then be used as follows:

    case DLL_PROCESS_ATTACH:
    // Initialize once for each new process.
    // Return FALSE to fail DLL load.
    if (calledonce == 0)
    {
    hInstance = hModule;
    calledonce = 1;
    MessageBox(NULL, "incremented", " DLL Main", MB_OK);
    }

    HOw ever this dosent work....am i setting the shared data segment incorrectly or have o got the wrong end of the stick with regard to the shared data! The libmain version only had hInstance = hModule; in it and this is all i wish to achieve with the new version.

    Can anybody tell me why my code won't work?! and wether it will solve the random painting problem with my app!?

    the code is here if your interested or need to look at it to solve the prob or shed any light on it.
    http://www.uea.ac.uk/~u9945296/Downloads/key32.zip

    Cheers in advance

    Andy http://www.uea.ac.uk/~u9945296/Downloads/key32.zip

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    I think if you make a global variable in a DLL it's global across all the users of that DLL...not sure though. Check out the documentation for Thread Local Storage and it should come across to something like this
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    why do you use a shared data segment?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  4. #4
    amac
    Guest
    I wonder...

    You could make a chat program... that was made up of a client (exe) and the server (dll)... The DLL could be placed on a network share... somewhere...

    the Server could use a shared data segment to hold whatever...

  5. #5
    amac
    Guest
    What do you think about that idea?

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    May 2001
    Location
    UK
    Posts
    222
    I'm just trying to mimic the original libmain! in the dllmain, as i only want the vraible hInstance = hModule set once.

  7. #7
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Amac - it's shared in memory, it doesn't change the original file, so that won't work

    Andy - I have a nasty feeling that this might not work. I think that DLLs can be mapped anywhere in their calling process's address space, which will be different. When DllMain is called, hDLLInst (or whatever you called it ) could be different. It might not be, but it's all dependent on what order the linker gave for the OS to resolve the names in the DLL.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

Posting Permissions

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



Click Here to Expand Forum to Full Width