Getting $(SolutionDir)

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
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.
getenv("SolutionDir") throws me the same error... =(
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.
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.
Are you building a post/pre custom action for Visual Studio? If so, you'll have to receive the folder via the command line.
I'm not building a custom action.

I just want to load the value into a string lol
Last edited on
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.
Does anybody know where it could be?
I don't see what possible use anyone could have for this. Are you sure what you want isn't the working directory?
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.
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...
Why don't you just put those files in the same directory as the executable?
Topic archived. No new replies allowed.