CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jul 2009
    Location
    Bangalore, INDIA
    Posts
    45

    how to access a variable from another project in the current project

    Hello...

    I have two projects.. ProjA and ProjB.. ProjA is main executable project and ProjB is compiled into a .lib file and used in ProjA.

    Now, there is a member in the main app file of ProjA called current_transformation.. I need to set or change current_transformation's value in ProjB depending on certain criteria..

    How do i do that without copying all files from PrajB to ProjA..??

    Thanks in advance

  2. #2
    Join Date
    Jun 2001
    Location
    Denmark
    Posts
    453

    Re: how to access a variable from another project in the current project

    Hm....can't you just add a Get() and Set() function to the lib's class? I take it you have an instance of the class holding the variable in the other project?


    If the lib isn't yours, and you're just given a lib and an h file, then it will be a problem unless the variable is public.

  3. #3
    Join Date
    Jul 2009
    Location
    Bangalore, INDIA
    Posts
    45

    Re: how to access a variable from another project in the current project

    No No..

    I got two projects.. along with source code. One is compiled into Lib file and other is compiled into .exe file.. Now i want to write a set statement in lib project, which will set a variable present in exe project...

    i hope you got my problem...

  4. #4
    Join Date
    Jun 2001
    Location
    Denmark
    Posts
    453

    Re: how to access a variable from another project in the current project

    Ah...hm, how about having a pointer to the exe's variable that the lib initializes to null.

    Then when the exe initializes, it sets that pointer to &exe_variable.

    Then whenever the lib needs to access the variable, it can do

    if (pExe_Variable)
    SomeVar=*pExe_Variable; or *pExe_Variable = SomeVar;

    Would that work?

    Or maybe when the exe initializes the class in question from the lib it could add a pointer to itself:
    pLibClass = new LibClass(this);

    and then the lib class could have

    pExeClass->Get() or pExeClass->Set(SomeVar);

    I don't know if the exe class will need to derive from a small class in the lib (that you then cast to) containing Get, Set and perhaps variable.

    Just a thought. Hope it's useful in some way :-)

  5. #5
    Join Date
    Jul 2009
    Location
    Bangalore, INDIA
    Posts
    45

    Re: how to access a variable from another project in the current project

    i am using visual C++.. i added both projects in a single workspace and included main file of exe project in the respective file of lib project and gave all the required include directory paths..

    It worked finally..

    Thanks anyways..

  6. #6
    Join Date
    Apr 2008
    Posts
    725

    Re: how to access a variable from another project in the current project

    no problem..

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