|
-
October 6th, 2003, 03:58 AM
#1
Global variables
I need a global variable, which will be used from several .exe.
My code:
Log_clnt.cpp
Code:
string text_messages [NUM_MAX_MESSAGES];
With other files, it will generated a logclnt.lib.
SVLog.cpp
Code:
#include "util/log_clnt.h"
extern string text_messages [NUM_MAX_MESSAGES];
int servMain (int argc,char *argv[])
{
string value;
for (int i=0; i < NUM_MAX_MESSAGES; i++)
{
#ifdef WIN32
stringstream strsStream;
#else
strstream strsStream;
#endif
strsStream << i;
if (!c.getValueForVariable (strsStream.str().c_str(), value) )
{
cerr << "Error reading messages values" << endl;
return 1;
}
//Metemos el valor en el array
text_messages [i] = value;
}
}
I link SVLog.cpp with logclnt.lib and I generate an executable logserv.exe
But then, when I try from my logclnt.lib (in other function) to get a value from text_messages, it returns a empty string. However, text_messages is ok in my servmain function.
Any ideas?
I am Miss Maiden... Miss Iron Maiden :-D
-
October 6th, 2003, 04:24 AM
#2
As I understand U want to share data between different processes?
If so, U need to use some IPC. The most easy way is to create a special SHARED SECTION for data in some dll. By simple usage of extrn keyword without putting data into shared section U cannot achive this, by this way every application will have different copies of data.
I haven't MSDN by hand on my Linux system, so try to find about shared sections in your's (as I remember it covered in IPC section).
PS: Hello, Irona, nice to hear U
"UNIX is simple; it just takes a genius to understand its simplicity!"
-
October 6th, 2003, 11:01 AM
#3
-
October 6th, 2003, 02:26 PM
#4
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|