【2010年1月4日】今天基本完成了IIniManager模块

本文介绍了在Windows环境下ANSI与Unicode编码之间的转换方法,重点讲解了MultiByteToWideChar和WideCharToMultiByte两个API函数的使用。此外,还提供了一个配置文件接口IIniManager的实现示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

起初都是用ANSI字符集编写代码,但考虑到以后编写国际化程序的需要,我还是选择了通用编程。

这当中,由于有VC大量的宏使得编程还算顺利,但是有些api无法同时支持两种字符集,故在ansi和unicode编码的转换就很重要了

以下是最重要的两个函数,也是我今天所使用的。

MultiByteToWideChar

Maps a character string to a wide character (Unicode UTF-16) string. The character string mapped by this function is not necessarily from a multibyte character set.

 

int MultiByteToWideChar(
  UINT CodePage, 
  DWORD dwFlags,         
  LPCSTR lpMultiByteStr, 
  int cbMultiByte,       
  LPWSTR lpWideCharStr,  
  int cchWideChar        
);

WideCharToMultiByte

int WideCharToMultiByte(
  UINT CodePage,
  DWORD dwFlags,
  LPCWSTR lpWideCharStr,
  int cchWideChar,
  LPSTR lpMultiByteStr,
  int cbMultiByte,
  LPCSTR lpDefaultChar,   
  LPBOOL lpUsedDefaultChar
);

具体使用查看msdn platform sdk。
贴下我IIniManager接口代码
////////////////////////////////////////////////////////////////////////////
// Copyright(c) 1999-2010, RIPPLE , All Rights Reserved
// Author:  RIPPLE
// Created: 2010/01/03
//
/// @file  IIniManager.hpp
/// @brief  配置文件接口
/// @version 0.1
////////////////////////////////////////////////////////////////////////////
#ifndef _H_IINIMANAGER_H_
#define _H_IINIMANAGER_H_
#include "ApplicationConfig.h"
#include <windows.h>
#include <iostream>
using namespace std;
#include <tchar.h>

//INIMANAGERDLL 已经在ILogManager接口实现的工程设置的预处理器中定义,对于其他工程,将是没有定义的
#ifdef  INIMANAGERDLL
#define IniManagerDLL  __declspec(dllexport)
#else
#define IniManagerDLL  __declspec(dllimport)
#endif
//////////////////////////////////////////////////////////////////////////
/// @class IIniManager
/// @brief 配置文件接口
//////////////////////////////////////////////////////////////////////////
class IniManagerDLL IIniManager
{
 public:
  ~IIniManager(){}
  virtual void add() = 0;
  virtual bool SetInt(LPCTSTR key, int value)  = 0;  //设置Int
  virtual int  GetInt(LPCTSTR key)     = 0;  

   virtual bool SetString(LPCTSTR key, LPCTSTR value) = 0;
   virtual bool GetString(LPCTSTR key, OUT LPTSTR value, size_t count) = 0;
};
/////////////////////////////////////
///  @brief 创建配置模块实例
///  @param [in] string SectionName = "APPLICATION"
///  @param [in] string FileName = ".//AppSetting.ini"
///  @return IIniManager*
/////////////////////////////////////
IniManagerDLL IIniManager* CreateIIniManagerInstance(LPCTSTR SectionName = _T("APPLICATION"), LPCTSTR FileName = _T(".//AppSetting.ini") );
#endif
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值