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
Solved

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

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
not able to insert into temp table 68 169
sum13 challenge 24 122
fizzArray2 challenge 1 91
mapBully challenge 6 152
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.

860 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