Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Mobile Development
  3. Mobile
  4. Reading INI File? In eVC++

Reading INI File? In eVC++

Scheduled Pinned Locked Moved Mobile
questionc++help
9 Posts 4 Posters 10 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    anju
    wrote on last edited by
    #1

    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

    D 1 Reply Last reply
    0
    • A 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

      D Offline
      D Offline
      Daniel Strigl
      wrote on last edited by
      #2

      Hi anju! I use the Win32 API functions RegOpenKeyEx and RegQueryValueEx to read the IRDA port index from the registry and it works fine!

      UINT CIrdaPort::FindPortIndex()
      {
      // Look into the registry for the IRDA port number

      HKEY 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!

      A 1 Reply Last reply
      0
      • D Daniel Strigl

        Hi anju! I use the Win32 API functions RegOpenKeyEx and RegQueryValueEx to read the IRDA port index from the registry and it works fine!

        UINT CIrdaPort::FindPortIndex()
        {
        // Look into the registry for the IRDA port number

        HKEY 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!

        A Offline
        A Offline
        anju
        wrote on last edited by
        #3

        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

        D 1 Reply Last reply
        0
        • A 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

          D Offline
          D Offline
          Daniel Strigl
          wrote on last edited by
          #4

          Did the GetProfileString API function don't work on your system? Daniel ;) --------------------------- Never change a running system!

          A 1 Reply Last reply
          0
          • D Daniel Strigl

            Did the GetProfileString API function don't work on your system? Daniel ;) --------------------------- Never change a running system!

            A Offline
            A Offline
            Anonymous
            wrote on last edited by
            #5

            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:

            D 1 Reply Last reply
            0
            • A Anonymous

              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:

              D Offline
              D Offline
              Daniel Strigl
              wrote on last edited by
              #6

              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 the GetPrivateProfileString 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!

              A 1 Reply Last reply
              0
              • D Daniel Strigl

                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 the GetPrivateProfileString 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!

                A Offline
                A Offline
                anju
                wrote on last edited by
                #7

                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

                D 1 Reply Last reply
                0
                • A 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

                  D Offline
                  D Offline
                  Daniel Strigl
                  wrote on last edited by
                  #8

                  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!

                  R 1 Reply Last reply
                  0
                  • D Daniel Strigl

                    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!

                    R Offline
                    R Offline
                    Raphael Amorim
                    wrote on last edited by
                    #9

                    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

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups