c++ GetPrivateProfileString从当前目录读取ini文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22138959/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 23:57:22  来源:igfitidea点击:

c++ GetPrivateProfileString read ini file from current directory

c++visual-studioini

提问by Nurzhan Aitbayev

I'm creating a dll on c++. It is a Visual Studio project. The dll reads some data from ini file. I have decided to use GetPrivateProfileString function. It works almost completely. It does not see file in current directory. How can I provide this parameter (variable called path)?

我正在 C++ 上创建一个 dll。它是一个 Visual Studio 项目。dll 从 ini 文件中读取一些数据。我决定使用 GetPrivateProfileString 函数。它几乎完全有效。它在当前目录中看不到文件。如何提供此参数(称为路径的变量)?

How can I pass last parameter (path)

如何传递最后一个参数(路径)

Code:

代码:

LPCTSTR path = L"\test.ini";
TCHAR protocolChar[32];
int a = GetPrivateProfileString(_T("Connection"), _T("Protocol"), _T(""), protocolChar, 32, path);

String from test.ini:

来自 test.ini 的字符串:

[Connection]
Protocol = HTTP

I also tried this:

我也试过这个:

LPCTSTR path = L"test.ini";

But it did not help me

但这对我没有帮助

回答by HadeS

LPCTSTR path = _T(".\test.ini");

.symbolises current directory. Hope this will work for you.

.表示当前目录。希望这对你有用。

回答by shailendra

WCHAR   cfg_IniName[256];         

GetCurrentDirectory (MAX_PATH, cfg_IniName );    

wcscat ( cfg_IniName, L"\test.ini" );  

way to get full path

获取完整路径的方法