Click here to Skip to main content
Licence CPOL
First Posted 28 Oct 2009
Views 6,066
Bookmarked 5 times

GetPrivateProfileString for CE

By | 28 Oct 2009 | Article
Loading ini files for Pocket PC requires the unavailable GetPrivateProfileString.

Introduction

This is a function that should be in PocketPC / CE but is not because ini files are considered old news. However, when you're porting C++ applications, you run into this a lot.

Disclaimer: This does not in any means handle all the features of GetPrivateProfileString, nor is it bug free or very well tested. It may destroy the universe etc. etc. All it does currently is read basic ini settings which is all I need it for. I also have wrappers on top of this which handle a lot of functionality which probably should be present here.

Please see GetPrivateProfileString for more details.

I am hoping that others will add to this, one day making it the Win32 equivalent. Here is the code:

static DWORD GetPrivateProfileString(LPCTSTR lpSection, LPCTSTR lpKey, 
       LPTSTR lpDefault, LPTSTR lpBuffer, DWORD dwBufSize, LPCTSTR szPathAndFile) 
{
   fstream clFileOp(szPathAndFile,ios::in);  // File
   string clline;                            // line buffer
   CStringA clkey( lpKey);                   // key in ansii

   if (clFileOp.is_open() == FALSE ) 
   {
      return 1;
   }
   while(!clFileOp.eof()) 
   {
      getline ( clFileOp, clline );
      if ( clline.find( clkey ) != -1 )
      {
         int nEquals = clline.find( "=" );
         if ( nEquals == -1 )
         {
            continue;
         }
         string clres = clline.substr( nEquals +1, clline.length() - nEquals );
         CString clret (  clres.c_str() );
         _tcscpy ( lpBuffer,clret );
         clFileOp.close();
         return 1;
      }
   }

   clFileOp.close();
   return 0;

}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

rj45

Software Developer (Senior)

Canada Canada

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120528.1 | Last Updated 28 Oct 2009
Article Copyright 2009 by rj45
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid