Solved

Can 2 exe use the same handler to a dll?

Posted on 1998-12-07
7
239 Views
Last Modified: 2013-11-20
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.
0
Comment
Question by:paranoid
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 2

Expert Comment

by:wyy_cq
ID: 1325860
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.
0
 
LVL 86

Expert Comment

by:jkr
ID: 1325861
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...
0
 
LVL 8

Expert Comment

by:Answers2000
ID: 1325862
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
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

Author Comment

by:paranoid
ID: 1325863
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! :)
0
 
LVL 86

Expert Comment

by:jkr
ID: 1325864
Well, i think i misunderstood your question, as i assumed it was mainly about module handles, not about sharing data between apps...
0
 

Author Comment

by:paranoid
ID: 1325865
Adjusted points to 70
0
 
LVL 8

Accepted Solution

by:
Answers2000 earned 70 total points
ID: 1325866
What you do is take a look at OpenFileMapping API.  If you look up this API in the help then click "Overview" then the blue Down arrow, there's a nice overview in VC5 help.

Remember what I said about Win32 - each process having it's own copy of the DLL.  The diagram shows 2 process accessing the file mapping memory.

Now if possible (you have control over the DLL source, and the app has an interface to the DLL which doesn't assume it can directly access the DLL's data),  imagine the DLL sitting on the arrow between Process 1 Virtual Memory and the Physical memory, and similarly for Process 2 (go to help page I referred to above, you'll see the diagram).

Basically the steps look like this

1. App #1 - link to DLL - this DLL is instance #1
2. App #1 calls some function in the DLL to store or get back some data
3. The DLL stores/gets the data from the file mapping data.

Similarly App#2 is doing this through it's instance of the DLL.

Does this make sense ?
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Question regarding Copy/Paste 16 95
matchUp  challenge 9 105
Dell Alienware Graphics Amplifier Driver for non-Alienware systems 18 248
Work with App store 7 51
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now