c++ GetPrivateProfileString read ini file from current directory

走远了吗. 提交于 2019-12-10 03:29:05

问题


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)?

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:

[Connection]
Protocol = HTTP

I also tried this:

LPCTSTR path = L"test.ini";

But it did not help me


回答1:


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

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




回答2:


WCHAR   cfg_IniName[256];         

GetCurrentDirectory (MAX_PATH, cfg_IniName );    

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

way to get full path



来源:https://stackoverflow.com/questions/22138959/c-getprivateprofilestring-read-ini-file-from-current-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!