Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / desktop / MFC

A Class of Accessing inifile in UNICODE

3.00/5 (3 votes)
25 Sep 2006CPOL 1   642  
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)