Getting $(SolutionDir)

May 31, 2011 at 3:59pm
So, I went into the project properties, and added the macro for $(SolutionDir).


How can I access that value from my program?

I tried:

std::string SolDir = getenv("$(SolutionDir)");
std::cout << "My directory is: " << SolDir << std::endl;

But I get a debug assertion error. (Null Pointer)

I want to be able to set the value of SolutionDir to a string.
Last edited on May 31, 2011 at 4:01pm
May 31, 2011 at 4:07pm
I think it should be getenv("SolutionDir"). The $() part is to let the application know that what is contained is the name of an environment variable, but it is not part of the actual name.
May 31, 2011 at 4:08pm
getenv("SolutionDir") throws me the same error... =(
May 31, 2011 at 4:09pm
Did you define that environment variable? In windows, you can open the command prompt and type "set" (no quotation marks) to see all defined env. variables. If SolutionDir is not there, then you did not properly define the macro, or the macro definition engine is storing the macro elsewhere.
May 31, 2011 at 4:14pm
I can't see the environment variable there, but doing that gives me a list of user and system environment variables I can declare from the Windows Control Panel.

What I want to do is load the directory of the current solution into a string, regardless of what box is using it.
May 31, 2011 at 4:28pm
Are you building a post/pre custom action for Visual Studio? If so, you'll have to receive the folder via the command line.
May 31, 2011 at 5:18pm
I'm not building a custom action.

I just want to load the value into a string lol
Last edited on May 31, 2011 at 5:19pm
May 31, 2011 at 5:29pm
Well, if the value is not written into the environment variables, what choice do you have??

Clearly it is not where you are looking for. So where is it? I don't know. Once you find out you can see if you can code something for it. It is impossible otherwise.
May 31, 2011 at 5:56pm
Does anybody know where it could be?
May 31, 2011 at 6:00pm
I don't see what possible use anyone could have for this. Are you sure what you want isn't the working directory?
May 31, 2011 at 6:07pm
Well, I have a bunch of text files that serve as inputs to my program.

I put those in my solution directory, and am going to place my program on a different box.

Thus, I want to be able to access the current solution directory.

I don't want to have to do through the trouble of manually adding all the text files with filters in the solution explorer, so I thought this would be easier.
May 31, 2011 at 6:16pm
I'm pretty much a n00b when it comes to the nitty gritty of this IDE, so I'm not sure if there would be a simpler way...
May 31, 2011 at 6:31pm
Why don't you just put those files in the same directory as the executable?
Topic archived. No new replies allowed.