Solved

DLL: ? global var for multiple dll-callers

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C++ get user from AD  (VS6) 7 78
How to convert MFC APP to Win32 APP. 19 82
C++ Class Serialization, Encapsulation and Formatted Output 8 71
computer science syllabus 3 83
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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++.

831 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