首 页文章中心下载中心繁體中文
设为首页
加入收藏
联系我们
您当前的位置:开源盛世-源代码下载网 -> 文章中心 -> VC++专区 -> 文章内容 退出登录 用户管理
投票调查
栏目导航
· VC++专区 · V B 专区
· GIS 专区 · PDA 专区
· 其他编程 · 网站开发类
· 数据库类 · 软件应用
· 网络安全 · 论文专区
· 综合资讯
热门文章
· Tab Control控件使用...
· 学生档案管理系统
· [图文] 排列组合公式
· UTF-8与GB2312之间的...
· DirectShow下载安装...
· Virtual PC 在PAE模...
· Windows2000终端服务...
· MapInfo上的GIS系统...
· kalman filter 卡尔...
· Windows2000终端服务...
相关文章
· PPC程序打包CAB时包...
· Unicode简介
· 让静态库支持Unicod...
· 要怎么分辨出一般的...
· 在 VB 中使用 Unico...
· UNICODE、DBCS的一点...
· Unicode vs Ansi
· VB中的Unicode 和 A...
· byte2unicode得函数...
· 来自Moto得GB2Unico...
Unicode转换
作者:Polaris  来源:开源盛世-源代码下载网  发布时间:2005-6-28 7:13:25  发布人:Polaris

减小字体 增大字体

MultiByteToWideChar
WideCharToMultiByte

例程:
char ToGBTable[0xffff][3];

memset(ToGBTable, 0, sizeof(ToGBTable));

for(wchar i=0; i++; i<0xffff)
{
  if (i<0xff)
  {
    ToGBTable[i][0] = (char)i;
  }
  else
  {
     WideCharToMultiByte(CP_ACP
                         WC_DEFAULTCHAR,
                         &i,
                         1,
                         ToGBTable[i],
                         3,
                         "?",
                         NULL);
  }
}

 


CharToUnicode(BYTE* buf, DWORD bufSize)
{
 CString csTemp;
 WCHAR *UnicodeStr=new WCHAR[bufSize+1];
 DWORD UnicodeSize=MultiByteToWideChar(CP_ACP,0,
             (LPCSTR)buf,bufSize+1,UnicodeStr,(DWORD)bufSize+1);
 csTemp=UnicodeStr;
 delete [] UnicodeStr;
}

The Windows function MultiByteToWideChar converts multibyte-character strings to wide-character strings.
int MultiByteToWideChar(

    UINT CodePage, // code page
    DWORD dwFlags, // character-type options
    LPCSTR lpMultiByteStr, // address of string to map
    int cchMultiByte, // number of characters in string
    LPWSTR lpWideCharStr, // address of wide-character buffer
    int cchWideChar  // size of buffer
   );

#include <string.h>
#include "CharsetConversion.h"

int AsciiToUnicode(const char * szAscii, wchar_t * szUnicode)
{
 int len, i;

 if((szUnicode == NULL) || (szAscii == NULL))
  return 0;

 len = strlen(szAscii);

 for(i=0;i<len+1;i++)
  *szUnicode++ = static_cast<wchar_t>(*szAscii++);

 return i;
}

int UnicodeToAscii(const wchar_t * szUnicode, char * szAscii)
{
 int len, i;

 if((szUnicode == NULL) || (szAscii == NULL))
  return 0;

 len = wcslen(szUnicode);

 for(i=0;i<len+1;i++)
  *szAscii++ = static_cast<char>(*szUnicode++);

 return i;
}

_T or _TEXT
converts following character or string to its Unicode counterpart

HRESULT __fastcall AnsiToUnicode(LPCSTR pszA, LPOLESTR* ppszW)
{
    ULONG cCharacters;
    DWORD dwError;
    if (NULL == pszA)
    {
        *ppszW = NULL;
        return NOERROR;
    }
    cCharacters =  strlen(pszA)+1;
    *ppszW = (LPOLESTR) CoTaskMemAlloc(cCharacters*2);
    if (NULL == *ppszW)
        return E_OUTOFMEMORY;
    if (0 == MultiByteToWideChar(CP_ACP, 0, pszA, cCharacters,*ppszW, cCharacters))
    {
        dwError = GetLastError();
        CoTaskMemFree(*ppszW);
        *ppszW = NULL;
        return HRESULT_FROM_WIN32(dwError);
    }

    return NOERROR;
}

End of《Unicode转换》

[] [返回上一页] [打 印] [收 藏]
 
∷相关“Unicode转换”文章评论∷
(评论内容只代表网友观点,与本站立场无关!) [更多评论...]
关于本站 - 网站帮助 - 广告合作 - 下载声明 - 友情连接 - 网站目录 鄂ICP备06007162
开源盛世 版权所有Copyright © 2003-2005 VSCodes.Com. All Rights Reserved.