简体   繁体   中英

c++, how to Get the solution directory in the code

I am writing unit test for a dll function that returns its full path. the test project and dll project are both in same solution.

I was thinking of get the solution directory and append rest of path to assert.

in the preprocessor definitions of the test project defined : _SOLUTIONDIR=$(SolutionDir);

but in the test file I get #define _SOLUTIONDIR C:\\*\\Project\\ expands to C:\\*\\Project\\ unrecognized token

How should I cast or convert it to string? or in general what is the best way to get relative paths?

dll file has function returning 
--------------------------------
 EXTERN_C IMAGE_DOS_HEADER __ImageBase;
LPTSTR  strDLLPath1 = new TCHAR[_MAX_PATH];
        ::GetModuleFileName((HINSTANCE)&__ImageBase, strDLLPath1, _MAX_PATH);
        wstring temp1(strDLLPath1);
        string temp2(temp1.begin(), temp1.end());
return temp2;

解决方案是将_SOLUTIONDIR定义如下

_SOLUTIONDIR=R"($(SolutionDir))"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM