   Cross project variable access
  I think the solution has something to do with externs, but for some reason or another that has always been one of my weaknesses.I have a variable defined in a .cpp file in one project (ProjectA), and I need to access that same variable in a .cpp file in a different project(ProjectB). I would normally have defined the variable in a .h file, but this is code that was not written by me, and there are multiple variables of that same name throughout ProjectA. Any advice would be appreciated, and thanks in advance.edit: Forgot to mention the basics. I am working with C++, in Visual Studio, on windows.   
  Is this variable in two different EXEs? One way would be to wrap these global variables into a class or structure and pass the structure around via some sort of pattern (Visitor or Proxy). If they are in two different memory spaces, you can always package one project into a DLL and export its functions/members.   ;  This is a massive code base, I wanted to try and alter as little as possible. I was thinking about wrapping the variable into a class, which is probably my best solution at this point. And it is between 2 EXEs.   ;Quote:Original post by UltraseamusI think the solution has something to do with externs, but for some reason or another that has always been one of my weaknesses.I have a variable defined in a .cpp file in one project (ProjectA), and I need to access that same variable in a .cpp file in a different project(ProjectB). I would normally have defined the variable in a .h file, but this is code that was not written by me, and there are multiple variables of that same name throughout ProjectA. Any advice would be appreciated, and thanks in advance.edit: Forgot to mention the basics. I am working with C++, in Visual Studio, on windows.1) Is the CPP file actually part of both projects?2) Have you read this?   ;  OK, I decided the easiest solution would be to make a static function in a class from that project that I had access to, and from there I return the variable I need. Problem now is that ProjectB thinks that the function from ProjectA is unresolved, because ProjectB can not see that the function is defined in a .cpp file in ProjectA. Once again, I think this is an extern situation, but it will not allow me to extern the function because it is a member function. And I would define the function in the .h, but the variable is in the .cpp. Before I tried this solution I tired just declaring the variable in the .h, but that caused numerous issues with other files trying to access it.Am I going down a completely wrong path, or will this solution work? One possible solution would be to create a whole new variable in the class, and as early as I can set it to equal the other variable (a pointer by the way). But I hate writing sloppy code, and this just does not seem like the best solution considering the possibility of the original variable being altered in the future.Sorry if this is hard to follow, I confused myself multiple times when writing it.   ;  extern won't help you share across different executables. You'll need to use actual inter process communication. For example, use a memory mapped file to share memory. For Windows  this page lists your options.   ;  SiCrane: The thought of that scares me. I am still new to this code base, so I am going to hope I was wrong about the 2 projects producing 2 EXEs. If that is the case then extern could work to solve my problem?   ;  It should be easy enough to check. Go to your project properties for each project. Go to the Linker/General tab and look at the name of the output files for each project. If they both end in .exe then you've got two executables.   ;  Assuming they are two different executables, an important question is, what are the circumstances under which the two run? Do you just start them both up? Does one execute the other? Do they both have GUIs? Does the one pass data to the other right now? Does it return data?   ;  OK, ProjectB produces an EXE, ProjectA produces a dll. Sorry for not having that information sooner.   