Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c++ GetPrivateProfileString read ini file from current directory

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

like image 274
Nurzhan Aitbayev Avatar asked Mar 03 '14 04:03

Nurzhan Aitbayev


2 Answers

WCHAR   cfg_IniName[256];         

GetCurrentDirectory (MAX_PATH, cfg_IniName );    

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

way to get full path

like image 25
shailendra Avatar answered Oct 19 '22 20:10

shailendra


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

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

like image 179
HadeS Avatar answered Oct 19 '22 22:10

HadeS