Board index » Visual Studio » Need only one DLL instance to run...

Need only one DLL instance to run...

Visual Studio81
Hi all,



1:

if two apps load the same DLL - LoadLibrary(...) - system will create to

different instance of the DLL...

Now, in my DLL i've a CList and i need it to be visible to all instance and

all apps!!!!



Is there a way!?



2:

I need the dll to remain loaded till machine reboot!!! Is it possible!?



Thanks

Ale


-
 

Re:Need only one DLL instance to run...

Quote
if two apps load the same DLL - LoadLibrary(...) - system will create to

different instance of the DLL...

Now, in my DLL i've a CList and i need it to be visible to all instance and

all apps!!!!



Is there a way!?



It'll be difficult to share a CLis directly between processes.



You can share simple data in a DLL if you specify the data in a shared

section:



#pragma comment(linker, "/SECTION:.shared,RWS")

#pragma data_seg(".shared")

HWND g_hWnd = NULL; // Shared data must be initialised

#pragma data_seg()



However, for larger data, a named memory mapped file may be a better

solution.



Quote
2:

I need the dll to remain loaded till machine reboot!!! Is it possible!?



Some process has got to keep the DLL loaded. If you can arrange that,

then you can.



Dave

--

MVP VC++ FAQ: www.mvps.org/vcfaq">www.mvps.org/vcfaq

-

Re:Need only one DLL instance to run...

Ok, thanks for your answare...



Ale



"David Lowndes" wrote:



Quote
>if two apps load the same DLL - LoadLibrary(...) - system will create to

>different instance of the DLL...

>Now, in my DLL i've a CList and i need it to be visible to all instance and

>all apps!!!!

>

>Is there a way!?



It'll be difficult to share a CLis directly between processes.



You can share simple data in a DLL if you specify the data in a shared

section:



#pragma comment(linker, "/SECTION:.shared,RWS")

#pragma data_seg(".shared")

HWND g_hWnd = NULL; // Shared data must be initialised

#pragma data_seg()



However, for larger data, a named memory mapped file may be a better

solution.



>2:

>I need the dll to remain loaded till machine reboot!!! Is it possible!?



Some process has got to keep the DLL loaded. If you can arrange that,

then you can.



Dave

--

MVP VC++ FAQ: www.mvps.org/vcfaq">www.mvps.org/vcfaq



-

Re:Need only one DLL instance to run...

You can't share a CList. You can't have anything IN the CList that requires 'new',

including CStrings. If you do a shared-data-segment DLL, every bit you need to share must

be statically declared in the sharable data segment. If you do a memory-mapped-file

sharing, likewise. You will have to build your own "storage allocator" in these if you

need dynamic allocation, and if you do this, you need to use fixed-sized blocks if

possible so you avoid memory fragmentation of a very scarce resource. In addition, you

have no guarantees that the block of memory is mapped into the same addresses in each

process (if the debugger tells you this is so, take this as sheer coincidence! You cannot

force the mappings to be the same, although the OS will tend to favor identical mappings

it is not guaranteed). Thus, you must used __based pointers to put any pointers into this

area.



I use this exact problem in my System Programming course. Send me private email and I'll

send you a working example of how this is done.

joe



On Thu, 8 Sep 2005 03:43:02 -0700, Ale <Ale@discussions.microsoft.com>wrote:



Quote
Hi all,



1:

if two apps load the same DLL - LoadLibrary(...) - system will create to

different instance of the DLL...

Now, in my DLL i've a CList and i need it to be visible to all instance and

all apps!!!!



Is there a way!?



2:

I need the dll to remain loaded till machine reboot!!! Is it possible!?



Thanks

Ale



Joseph M. Newcomer [MVP]

email: newcomer@flounder.com

Web: www.flounder.com">www.flounder.com

MVP Tips: www.flounder.com/mvp_tips.htm">www.flounder.com/mvp_tips.htm

-