CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2001
    Location
    Madrid-Spain
    Posts
    1,123

    Unhappy 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

  2. #2
    Join Date
    Sep 2002
    Location
    Belarus - Tirol, Austria
    Posts
    647
    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!"

  3. #3
    Join Date
    May 2001
    Location
    Madrid-Spain
    Posts
    1,123

    Talking

    Thank you dimm_coder
    nice to hear you too
    I am Miss Maiden... Miss Iron Maiden :-D

  4. #4
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured