Solved

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

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

747 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