65.9K
CodeProject 正在变化。 阅读更多。
Home

一个用于访问 UNICODE INI 文件的类

starIconstarIconstarIconemptyStarIconemptyStarIcon

3.00/5 (3投票s)

2006年9月26日

CPOL
viewsIcon

36688

downloadIcon

660

Win API 无法在 UNICODE 中访问 ini 文件。有时,我们可能希望在 INI 文件中添加一些宽字符,因此我编写了一个类来在 UNICODE 中访问 INI 文件。

引言

Windows API 访问 INI 文件的功能不支持 UNICODE 文件。例如,如果有人想将中文字符串写入 INI 文件,并在日语系统中读取它,他将无法获得正确的字符串。

因此,我编写了一个类来在 UNICODE 中访问 INI 文件。你可以像使用 Win API 一样使用它。该类提供了以下接口:

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
  );

历史

  • 2006 年 9 月 26 日:初始发布
© . All rights reserved.