Reading INI File? In eVC++
-
Hi, In My application i have to read settings from some "xx.INI" file. I am using WCEApplication. please help me how can i read .INI file. for this I searched for "GetProfileString" and "SetProfileString" but i didn't get any help related to me. (most material available on CWinApp::GetProfileString etc) but i need these functionality in Win32. Thank You.:rose: anju
-
Hi, In My application i have to read settings from some "xx.INI" file. I am using WCEApplication. please help me how can i read .INI file. for this I searched for "GetProfileString" and "SetProfileString" but i didn't get any help related to me. (most material available on CWinApp::GetProfileString etc) but i need these functionality in Win32. Thank You.:rose: anju
Hi anju! I use the Win32 API functions
RegOpenKeyEx
andRegQueryValueEx
to read the IRDA port index from the registry and it works fine!UINT CIrdaPort::FindPortIndex()
{
// Look into the registry for the IRDA port numberHKEY hKey = NULL; if (RegOpenKeyEx(HKEY\_LOCAL\_MACHINE, \_T("Drivers\\\\BuiltIn\\\\IrCOMM"), 0, 0, &hKey) == ERROR\_SUCCESS) { DWORD dwType = 0; DWORD dwData = 0; DWORD dwSize = sizeof(dwData); if (RegQueryValueEx(hKey, \_T("Index"), NULL, &dwType, (LPBYTE) &dwData, &dwSize) == ERROR\_SUCCESS) { if (dwType == REG\_DWORD && dwSize == sizeof(dwData)) { RegCloseKey(hKey); return (UINT) dwData; } } RegCloseKey(hKey); } return 0;
}
Just take a look on my Pocket PC application Infrared Communication with your Mobile Phone. I hope this will help you! Daniel ;) --------------------------- Never change a running system!
-
Hi anju! I use the Win32 API functions
RegOpenKeyEx
andRegQueryValueEx
to read the IRDA port index from the registry and it works fine!UINT CIrdaPort::FindPortIndex()
{
// Look into the registry for the IRDA port numberHKEY hKey = NULL; if (RegOpenKeyEx(HKEY\_LOCAL\_MACHINE, \_T("Drivers\\\\BuiltIn\\\\IrCOMM"), 0, 0, &hKey) == ERROR\_SUCCESS) { DWORD dwType = 0; DWORD dwData = 0; DWORD dwSize = sizeof(dwData); if (RegQueryValueEx(hKey, \_T("Index"), NULL, &dwType, (LPBYTE) &dwData, &dwSize) == ERROR\_SUCCESS) { if (dwType == REG\_DWORD && dwSize == sizeof(dwData)) { RegCloseKey(hKey); return (UINT) dwData; } } RegCloseKey(hKey); } return 0;
}
Just take a look on my Pocket PC application Infrared Communication with your Mobile Phone. I hope this will help you! Daniel ;) --------------------------- Never change a running system!
Hi Daniel, Thank You for your reply. your idea is nice when we use registry for settings.. But my aim is to read INI file.because i have to put lot of information in file and read when ever necessary. This information is in structure wise. eg: struct Employee { Name, ID, dept, salay, age, DOB } I have to fill this data when ever user given to me and write to file. and i have to get back it when ever necessary to me from file. please give me good idea. Once again thanks to you. regards:rose: anju
-
Hi Daniel, Thank You for your reply. your idea is nice when we use registry for settings.. But my aim is to read INI file.because i have to put lot of information in file and read when ever necessary. This information is in structure wise. eg: struct Employee { Name, ID, dept, salay, age, DOB } I have to fill this data when ever user given to me and write to file. and i have to get back it when ever necessary to me from file. please give me good idea. Once again thanks to you. regards:rose: anju
Did the
GetProfileString
API function don't work on your system? Daniel ;) --------------------------- Never change a running system! -
Did the
GetProfileString
API function don't work on your system? Daniel ;) --------------------------- Never change a running system!Hi, Daniel ---Did the GetProfileString API function don't work on your system? I am aware of GetProfileString. In Win32Application programming i am using GetProfileString as follows TCHAR strRetn[100]; GetProfileString("Aloap","Timer",NULL,strRetn,100); //Aloap is section and //Timer is Key and \\strRetn is value MessageBox(hDlg,strRetn,strRetn,0); by default the GetProfileString function lookint Win.ini file My need is... I have to use same function in Win32CE Application Programming. and also i have to read section values my own INI file instead of win.INI. I hope now my need is clear to you please help me in this context thank you. regards.:rose:
-
Hi, Daniel ---Did the GetProfileString API function don't work on your system? I am aware of GetProfileString. In Win32Application programming i am using GetProfileString as follows TCHAR strRetn[100]; GetProfileString("Aloap","Timer",NULL,strRetn,100); //Aloap is section and //Timer is Key and \\strRetn is value MessageBox(hDlg,strRetn,strRetn,0); by default the GetProfileString function lookint Win.ini file My need is... I have to use same function in Win32CE Application Programming. and also i have to read section values my own INI file instead of win.INI. I hope now my need is clear to you please help me in this context thank you. regards.:rose:
TCHAR szReturn[1024]; GetPrivateProfileString(_T("YourSection"), _T("YourKey"), _T("YourDefault"), szReturn, sizeof(szReturn) / sizeof(TCHAR), _T("YourPath\YourIniFile.ini")); AfxMessageBox(szReturn);
This API function is to read some values from a user defined INI file. Just take a look on the MSDN documentation of theGetPrivateProfileString
API function.DWORD GetPrivateProfileString( LPCTSTR lpAppName, // section name LPCTSTR lpKeyName, // key name LPCTSTR lpDefault, // default string LPTSTR lpReturnedString, // destination buffer DWORD nSize, // size of destination buffer LPCTSTR lpFileName // initialization file name );
There are some things you have to attention: lpDefault [in] Pointer to a null-terminated default string. If the lpKeyName key cannot be found in the initialization file, GetPrivateProfileString copies the default string to the lpReturnedString buffer. This parameter cannot be NULL. lpFileName [in] Pointer to a null-terminated string that specifies the name of the initialization file. If this parameter does not contain a full path to the file, the system searches for the file in the Windows directory. Daniel ;) --------------------------- Never change a running system! -
TCHAR szReturn[1024]; GetPrivateProfileString(_T("YourSection"), _T("YourKey"), _T("YourDefault"), szReturn, sizeof(szReturn) / sizeof(TCHAR), _T("YourPath\YourIniFile.ini")); AfxMessageBox(szReturn);
This API function is to read some values from a user defined INI file. Just take a look on the MSDN documentation of theGetPrivateProfileString
API function.DWORD GetPrivateProfileString( LPCTSTR lpAppName, // section name LPCTSTR lpKeyName, // key name LPCTSTR lpDefault, // default string LPTSTR lpReturnedString, // destination buffer DWORD nSize, // size of destination buffer LPCTSTR lpFileName // initialization file name );
There are some things you have to attention: lpDefault [in] Pointer to a null-terminated default string. If the lpKeyName key cannot be found in the initialization file, GetPrivateProfileString copies the default string to the lpReturnedString buffer. This parameter cannot be NULL. lpFileName [in] Pointer to a null-terminated string that specifies the name of the initialization file. If this parameter does not contain a full path to the file, the system searches for the file in the Windows directory. Daniel ;) --------------------------- Never change a running system!Hi, Daniel Thank you, one more function added into my library (upto now i didn't aware of "GetPrivateProfileString") still i am in truble...... i am getting following error while compiling: what libraries i have to add for this function. i added in stdafx.h --Configuration: TestINI - Win32 (WCE x86em) Debug--- Compiling... TestINI.cpp D:\ClearMe\TestINI\TestINI.cpp(203) : error C2065: 'GetPrivateProfileString' : undeclared identifier Error executing cl.exe. TestINI.obj - 1 error(s), 0 warning(s) Thank you for your extending cooperation.. regards:rose: anju
-
Hi, Daniel Thank you, one more function added into my library (upto now i didn't aware of "GetPrivateProfileString") still i am in truble...... i am getting following error while compiling: what libraries i have to add for this function. i added in stdafx.h --Configuration: TestINI - Win32 (WCE x86em) Debug--- Compiling... TestINI.cpp D:\ClearMe\TestINI\TestINI.cpp(203) : error C2065: 'GetPrivateProfileString' : undeclared identifier Error executing cl.exe. TestINI.obj - 1 error(s), 0 warning(s) Thank you for your extending cooperation.. regards:rose: anju
Oh... :(( Sorry, I found out that the
GetPrivateProfileString
API function are not supported by the Windows CE system. It only works on the desktop Windows systems. I think you should use some of the open source INI file parsers, like the INI Parser Library at Sourceforge. I hope this library will help you! It's a simple ANSI C parser for INI files. Just add it to your project and try it! Daniel ;) --------------------------- Never change a running system! -
Oh... :(( Sorry, I found out that the
GetPrivateProfileString
API function are not supported by the Windows CE system. It only works on the desktop Windows systems. I think you should use some of the open source INI file parsers, like the INI Parser Library at Sourceforge. I hope this library will help you! It's a simple ANSI C parser for INI files. Just add it to your project and try it! Daniel ;) --------------------------- Never change a running system!Hello, Try to use the registry. Use the following registry functions:
RegCreateKeyEx
RegOpenKeyEx
RegCloseKey
RegDeleteValue
RegQueryValueEx
RegSetValueEx
RegEnumKeyEx
Raphael Amorim Dantas Leite VC++, VB, Java, .NET and eMbedded Programmer