Click here to Skip to main content
15,867,851 members
Articles / Desktop Programming / MFC

A Class of Accessing inifile in UNICODE

Rate me:
Please Sign up or sign in to vote.
3.00/5 (3 votes)
25 Sep 2006CPOL 35.5K   639   14   4
The Win API cannot access inifile in UNICODE, sometimes, we may want to add some wide characters into INI file, so I wrote a class to access INI file in UNICODE

Introduction

The Windows API of accessing INI file cannot support UNICODE FILE, for instance, if someone wants to write a Chinese string into an INIFILE and read it in a Japanese system, he will not get the correct string.

So, I wrote a class to access INIFILE in UNICODE. You can use it as using Win API. This class provides such interfaces:

C++
static INT GetPrivateProfileInt(
  LPCWSTR lpAppName,  	// address of section name
  LPCWSTR lpKeyName,  	// address of key name
  INT nDefault,       	// return value if key name is not found
  LPCWSTR lpFileName  	// address of initialization filename
  );

static DWORD GetPrivateProfileSection(
  LPCWSTR lpAppName,       	// address of section name
  LPWSTR lpReturnedString,	// address of return buffer
  DWORD nSize,            	// size of return buffer
  LPCWSTR lpFileName      	// address of initialization filename
  );

static DWORD GetPrivateProfileSectionNames(
  LPWSTR lpszReturnBuffer,	// address of return buffer
  DWORD nSize,            	// size of return buffer
  LPCWSTR lpFileName      	// address of initialization filename
  );

static DWORD GetPrivateProfileString(
  LPCWSTR lpAppName,        // points to section name
  LPCWSTR lpKeyName,        // points to key name
  LPCWSTR lpDefault,        // points to default string
  LPWSTR lpReturnedString,  // points to destination buffer
  DWORD nSize,              // size of destination buffer
  LPCWSTR lpFileName        // points to initialization filename
  );

static BOOL WritePrivateProfileSection(
  LPCWSTR lpAppName,  	// pointer to string with section name
  LPCWSTR lpString,   	// pointer to string with data
  LPCWSTR lpFileName  	// pointer to string with filename
  );

static BOOL WritePrivateProfileString(
  LPCWSTR lpAppName,  	// pointer to section name
  LPCWSTR lpKeyName,  	// pointer to key name
  LPCWSTR lpString,   	// pointer to string to add
  LPCWSTR lpFileName  	// pointer to initialization filename
  );

static BOOL WritePrivateProfileInt(
  LPCWSTR lpAppName,  	// pointer to section name
  LPCWSTR lpKeyName,  	// pointer to key name
  INT nValue,   		// pointer to string to add
  LPCWSTR lpFileName  	// pointer to initialization filename
  );

History

  • 26th September, 2006: Initial post

License

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


Written By
Web Developer
China China
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Generalthe API can do this for you Pin
umeca7413-Apr-10 6:14
umeca7413-Apr-10 6:14 
If you check the documentation for e.g. WritePrivateProfileString you will see that this functionality is already present:

If the file was created using Unicode characters, the function writes Unicode characters to the file. Otherwise, the function writes ANSI characters.

so all you need to do is to create a file with a unicode BOM and use the INI windows API
GeneralRe: the API can do this for you Pin
andreaplanet5-Feb-12 7:04
andreaplanet5-Feb-12 7:04 
GeneralFirst "class"! Pin
barryem9-Apr-08 13:55
barryem9-Apr-08 13:55 
GeneralGreat work Pin
sirnowy10-Sep-07 9:28
sirnowy10-Sep-07 9:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.