Solved

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

Posted on 1998-11-18
5
160 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Looking for a specific application/software 2 104
bigDiff challenge 17 84
sumHeights2  challenge 7 88
Trying to run powershell  in a batch file. How do I do this? 8 67
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…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
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.

895 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

12 Experts available now in Live!

Get 1:1 Help Now