Solved

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

Posted on 1998-11-18
5
161 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
  • 3
  • 2
5 Comments
 
LVL 3

Accepted Solution

by:
GGRUNDY earned 100 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

816 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

11 Experts available now in Live!

Get 1:1 Help Now