Link to home
Start Free TrialLog in
Avatar of paranoid
paranoid

asked on

Can 2 exe use the same handler to a dll?

I have a lotus notes script making use of a dll. I have another mfc exe which calls this dll at some point later. Is it possible for the 2 applications to use the same handler to this dll? From what i notice, 2 different handlers are created, when i do a LoadLibrary from the mfc exe.

Thank you very much.
Avatar of wyy_cq
wyy_cq

no you can't.
because the dll is loaded into the application's memory area . and the every application's memory is devided by OS .

if you want the two application share some data defined in the DLL you may set the data segment be share . but you 'd better not do that. because this action will destroy the application's safety.

of course there are some other way to "cheat" the OS, but that will not be a good idea.

there are a few method provided by OS to enable your applications share memory or communicate.

file mapping can alloc a memory block and many application can access the same copy of it .
named pipe, unnamed pipe ,local socket can be used between applications to communicate.
Avatar of jkr
A DLL instance handle returned by 'LoadLibrary()' represents the base load address of the DLL in the process' memory. Thus, it will _usually_ be different for each program that loads the library... usually, because if you created the DLL, you can direct the linker to use a _fixed_ base load address (Settings->Link->Output->Base Address), which ensures that the instance handle is _always_ the same - but be careful: If there's a address conflict (e.g. 2 DLLs using fixed load addresses that would lead to overlapping memory aread), the program won't run...
In Win16, there is one instance of the DLL shared by all EXEs.  You should still LoadLibrary/FreeLibrary in each EXE.  This means the "usage count" is kept correct.

In Win32, ther eis one instance of a DLL per EXE which uses it.  Don't share the stuff, except shared memory, as wyy_cq states
Avatar of paranoid

ASKER

first, thnks to all who have replied.

jkr, i do not really understand your explanation. i think you did not fully answer my qn. either this, or i am too dumb. :P

i think wyy_cq and Answers2000 provided what i need. :)

may i ask further regarding how can i introduce file mapping? do i alter my 2 applications to cater for it, or is it just the dll that i should change?

if possible, provide a simple example?

thank you very much! :)
Well, i think i misunderstood your question, as i assumed it was mainly about module handles, not about sharing data between apps...
Adjusted points to 70
ASKER CERTIFIED SOLUTION
Avatar of Answers2000
Answers2000

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial