Solved

DLL: ? global var for multiple dll-callers

Posted on 1998-08-13
2
199 Views
Last Modified: 2006-11-17
I've a dll. When finished it will be loaded from different applications.
When an application starts working with my dll it first needs an AppId. AppId is given when calling the dll's "int Init()".
Init() increments its global NextApplId by one and returns this new value. So, the first app loading my dll gets "1", the next gets "2" and so on...
How can I do that??? (will also be a thread safe problem I quess)  

Additional Info
WinNT 4.0, MS VC++ 97
0
Comment
Question by:AndyRaschle
  • 2
2 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 70 total points
ID: 1170205
A DLL can have segments of data that are shared among all the processes that use the DLL.  You just need to place the number there.  
0
 
LVL 22

Expert Comment

by:nietod
ID: 1170206
You will need a mutex to control access to the number, unless the number will be used only during the processs attach (or detach) call  (Which is very likely).  Only one thread may attach to or detach from the DLL at a time.  So you can safely access this variable from within the library entry point procedure without using a mutex.  Thus, if you want to increment this counter and copy the new number to a non-shared location, that is one that is private to each process, you can do that in the dll entry point procedure with out a mutex.  Otherwise you will need a mutex.  
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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

912 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

18 Experts available now in Live!

Get 1:1 Help Now