473,397 Members | 1,961 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Storing variables in DLLs

I'm writing a DLL and want to store information internally between
calls to the DLL functions.

For example:

static int i1,i2;

INT APIENTRY StoreInt1(int i) { return i1=i; }
INT APIENTRY StoreInt2(int i) { return i2=i; }
INT APIENTRY GetSum() { return i1+i2 }

I have all the definitions set up correctly... and the test program
compiles fine... but when I run the program:

StoreInt1(5);
StoreInt2(10);
int i = GetSum();

i != 15?

It seems like after the application leaves the DLL it losses all the
static information so when it calls it again, the variables are fresh.
I've also tried making the whole library a static library (.lib vs
..dll) but the same thing happens.

Any ideas?

Evan

Sep 9 '06 #1
2 1761
On 8 Sep 2006 21:48:54 -0700, ew******@gmail.com wrote in
comp.lang.c++:
I'm writing a DLL and want to store information internally between
calls to the DLL functions.
[snip]

Then you need to ask in a group like
news:comp.os.ms-windows.programmer.win32, or one of Microsoft's groups
in the news:microsoft.public.* family. This is specific to your
platform and its mechanisms, the C++ language does not define or
acknowledge the existence of DLLs.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Sep 9 '06 #2

ew******@gmail.com wrote:
I'm writing a DLL and want to store information internally between
calls to the DLL functions.

For example:

static int i1,i2;

INT APIENTRY StoreInt1(int i) { return i1=i; }
INT APIENTRY StoreInt2(int i) { return i2=i; }
INT APIENTRY GetSum() { return i1+i2 }

I have all the definitions set up correctly... and the test program
compiles fine... but when I run the program:

StoreInt1(5);
StoreInt2(10);
int i = GetSum();

i != 15?

It seems like after the application leaves the DLL it losses all the
static information so when it calls it again, the variables are fresh.
I've also tried making the whole library a static library (.lib vs
.dll) but the same thing happens.

Any ideas?

Evan
---------------------------------------------------------
It seems like after the application leaves the DLL it losses all the
?? If your application stops refering the dll, the information is lost.
It should loose. Internally it maintains a reference count. once your
application stops refering it and no other applications are using it ,
even the dll gets unloaded. but even this doesn't matter. if you close
your application, the info would be lost. If you want to have them
stored for future usage, save them in a text file or use a db.

Sep 9 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mark Hannon | last post by:
I am trying to wrap my brain around storing form elements inside variables & arrays before I move on to a more complicated project. I created this simple example to experiment and as far as I can...
2
by: Jax | last post by:
Say for example a user of my website makes a selection on the site and I want to store that value for use on a later page what is the best way to do that? My only method at the moment that I know...
1
by: darrel | last post by:
We've purchased a component that requires us to install two DLLs. One we add as a reference to our project, but the otherone we have to add to the 'environment setup' as a system path reference....
12
by: Alex D. | last post by:
is it possible? pros and cons?
9
by: david | last post by:
I have a class with some business-logic and with every roundtrip, I need an instance of this class, so I have to create it, every time again. That doesn't seem very efficient. I thought it would...
6
by: Stephen Walch | last post by:
Our application environment consists of three basic layers: 1. Third-party unmanaged DLLs that were written before the CLR was invented and maintain a significant amount of information (including...
4
by: =?Utf-8?B?YmFzdWxhc3o=?= | last post by:
Hi; I want to store a datatable (or an arraylist) as a session variable but when I try; Session = al_RecNo; I get an error that; "Cannot implicitly convert type...
6
by: Lint Radley | last post by:
Hi Everyone, I need an opinion here on storing data for a program I am working on the processes DICOM images. Essentially, my program stores 25-45 (it varies depending on the user) ranges of...
1
weaknessforcats
by: weaknessforcats | last post by:
C++: The Case Against Global Variables Summary This article explores the negative ramifications of using global variables. The use of global variables is such a problem that C++ architects have...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.