Results 1 to 8 of 8

Thread: Make a DLL only load 1 instance through the Windows

  1. #1

    Thread Starter
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    Make a DLL only load 1 instance through the Windows

    How can i made my DLL writted in VC++ to be only have one instance in the Windows?

    That mean, no matter how many times it being call by LoadLibary or using implicit link, there still using the same DLL that was loaded priviously by the same application or others application.

    regards,
    Chris

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    It IS the same DLL. That's the concept: the code will be loaded only once.
    But the data is stored in seperate places for each process. There is a keyword to avoid that (some __declspec thing).
    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.

  3. #3

    Thread Starter
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    em... let me make my question more clearer

    let said, i have a DLL (abcdefg.dll) and there is fews variable within this Dll.

    example:

    IDBProperties *pIDBProperties = NULL;

    and this variable must be the same through out all the application which calling the this Dll. For instance, the variable will be initialize by the first application that load the mention DLL into memory.

    Then the second application load this dll. Which call one of the export function from this dll and the function will refer to this initialized varible for the rest of the code.

    How this make it more clear

    regards,
    Chris

  4. #4

    Thread Starter
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    I resolve the data segment with the following code,

    #pragma data_seg("MY_SHARED_DATA")
    IDBProperties *pIDBProperties = NULL;
    #pragma data_seg()
    #pragma comment(linker, "/section:MY_SHARED_DATA,RWS")

    But i get an exception error when i execute the export function from the second exe which load the same dll.

    The error code is: 120
    Which mean This function is not supported on this system. from MSDN library.

    why others app can used the shared variable? it that because it is a pointer?

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Really strange. Might have something to do with process memory spaces. Since your var is a pointer (interface pointer), it points to a location in memory. This memory belongs to the app that first loaded your dll. It might well be that other apps can't access this memory.

    Sorry, can't help you there.
    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.

  6. #6

    Thread Starter
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    i see some people doing with the interprocess syncronization by sending (SendMessage/PostMessage) own register message (RegisterWindowMessage). This can resolve some of my problem by the pointer variable remain hanging

  7. #7
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    Its called TLS (Thread Local Storage). MSDN it =).

    Z.

  8. #8
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    There is some DDE technique you could use... some special message... forgot how it was called...
    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.

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