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

Thread: Singleton across DLLs

  1. #1
    Join Date
    Jan 2006
    Posts
    384

    Singleton across DLLs

    Hi,

    It is possible to share a singleton across DLLs.

    For example - can I have a logging module implemented as a singleton class - and when used by code in 2 separate DLLs, I want information to be logged to the same file.

    DLL1 - uses singleton logging module
    DLL2 - uses singleton logging module

    Both DLL1 and DLL2 should access the same logging module (impemented as singleton) for logging.

    Is this possible to achieve this ?

    Thanks

  2. #2
    Join Date
    May 2007
    Location
    Bangalore India
    Posts
    262

    Re: Singleton across DLLs

    why not?
    Dont forget to rate my post if you find it useful.

  3. #3
    Join Date
    May 2007
    Location
    Scotland
    Posts
    1,164

    Re: Singleton across DLLs

    1) Compile the singleton into a DLL (which I'll refer to as Fred from here on)
    2) Create a couple more DLL's (which I'll refer to as Bob and George) and link them to Fred.

    Now when Bob and George request singleton instances, they will both see the same instance of the singleton contained in Fred.

    I hope this helps.
    Last edited by PredicateNormative; June 20th, 2008 at 07:06 AM. Reason: gramma

  4. #4
    Join Date
    Jan 2006
    Posts
    384

    Re: Singleton across DLLs

    Thank you for the answer.

    [1]
    Why will this not work if the Singleton Logger implementation were created as a static library (.lib) instead of a DLL ?

    [2]
    On Unix, would .so counterparts behave the same way as the DLL based solution given above ?
    Last edited by humble_learner; June 24th, 2008 at 05:51 AM.

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)