Solved

DLL: ? global var for multiple dll-callers

Posted on 1998-08-13
2
226 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
[X]
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
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

631 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