Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

DLL: ? global var for multiple dll-callers

Posted on 1998-08-13
2
Medium Priority
?
231 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 140 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

715 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