Solved

DLL: ? global var for multiple dll-callers

Posted on 1998-08-13
2
195 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
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 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.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

760 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

21 Experts available now in Live!

Get 1:1 Help Now