简体   繁体   English

c++,如何在代码中获取解决方案目录

[英]c++, how to Get the solution directory in the code

I am writing unit test for a dll function that returns its full path.我正在为返回其完整路径的 dll 函数编写单元测试。 the test project and dll project are both in same solution.测试项目和 dll 项目都在同一个解决方案中。

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);在定义的测试项目的预处理器定义中: _SOLUTIONDIR=$(SolutionDir);

but in the test file I get #define _SOLUTIONDIR C:\\*\\Project\\ expands to C:\\*\\Project\\ unrecognized token但在测试文件中,我得到#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))"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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