?
Solved

How to have a set global function one per document in an MFC MDI Application

Posted on 1998-11-18
5
Medium Priority
?
166 Views
Last Modified: 2013-11-20
Environment: Windows  95 , Visual C++ 5.0
 
Hi,
 
I have an MDI application that uses a dll file which requires a set of function
pointers for allocating/deallocating a mutex when it requires
These functions have a predefined signature as below.
 
void *Mutex_Alloc(void)
{
// my implementation for the function

 InitializeCriticalSection (&LDAPSessionCriticalSection);
   return ( (void *)&LDAPSessionCriticalSection);
}
 
/*F+F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F
  Function: ShowErrorMsg
 
  Summary:  This function is called by the LDAP library when it
   no longer need to use the mutex.  
 
F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F-F*/
void Mutex_Free(void *mutex)
{
// DeleteCriticalSection (&LDAPSessionCriticalSection);
}
 
/*F+F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F
  Function: ShowErrorMsg
 
  Summary:  This function is called by the LDAP library when it
   need to lock a mutex.  
F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F-F*/
int Mutex_Lock(void *mutex)
{
 EnterCriticalSection (&LDAPSessionCriticalSection);
 return 1;
}

But when mutiple fame windows are created ( MDI App ) they all share the same global functions and the same Critical Section for all the document instances , which is not desired.
 
Is there a method by which I can make these funtions specific to each instance of the doccumet. ( keeping the signatures same )
 
I Tried to load the dll dynamically and give a wrapper to these function making the implemtation specific to each document. But each
LoadLibrary(" Mydll") gives back the same handle thus this technique fails.
 
Please suggest something.
0
Comment
Question by:Preeti_a
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 3

Accepted Solution

by:
GGRUNDY earned 200 total points
ID: 1324910
I'm assuming that the DLL is some 3rd party supplied stuff and therefore something you have
no control over. Otherwise why on earth would you go to all the following bother:
1) your dynamic loading wrapper functions are going to have to make a new
    physical disk file copy of the dll to a  different file name before they load it.
2) if that doesn't work your dynamic loading wrapper functions may even
    have to patch  the dll internal fileanem to a something different name, before they load it.
   (Hopefully they won't need to).
3) your dynamic loading wrapper functions should delete the temporary
    dll file when they have finished with it.
Cheers Greg
0
 

Author Comment

by:Preeti_a
ID: 1324911
Hi Greg,

Thanks for the reply. But could please specify as to why should there be a need for making physical disk file copy of the dll to a different file name before loading it.
Please also send me the details thereof
0
 
LVL 3

Expert Comment

by:GGRUNDY
ID: 1324912
>"But each LoadLibrary(" Mydll") gives back the same handle"
Loading the same dll multiple times normally just causes the
O/S to take out extra locks on the same process, hence
the same handle.

Loading from different files should give you different memory
instances of the dll.
Assuming LDAPSessionCriticalSection
is a global variable in the  dll, then each dll will have their own
address space copy and therefore  effectively separate
signatutures.

Just use CopyFile
0
 

Author Comment

by:Preeti_a
ID: 1324913
Probably the question is misunderstood. The implementation within the function is required to be defined by me ( the user ).
And pointers to those funtions are given to dll; there after I have no knowledge of when the dll might call them for its internal use.( I am not calling these functions directly ).

The problem is how will I give a different implementation of these Global functions for each new doccument in MDI, when there is a restriction imposed on the signature of the function and I have no control over when the function is getting called by the dll internally.( i.e. A wrapper fuction cannot be used in this problem )
Please try to help.
   
0
 
LVL 3

Expert Comment

by:GGRUNDY
ID: 1324914
Perhaps you better take some time and give me all the facts.
What is the third party product?
Is it a static link library or a dll?
What calls to you have to make to:
   - initialise it
   - open it
   - inform it of your dll and Mutex_Allock etc functions.
   - use it
How and where is LDAPSessionCriticalSectio declared?
0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

765 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