Chinaunix首页 | 论坛 | 博客

=.=

  • 博客访问: 135707
  • 博文数量: 50
  • 博客积分: 3000
  • 博客等级: 中校
  • 技术积分: 550
  • 用 户 组: 普通用户
  • 注册时间: 2009-09-25 17:22
文章分类

全部博文(50)

文章存档

2010年(7)

2009年(43)

我的朋友

分类: WINDOWS

2010-03-15 09:08:30

char *gbk2utf8( const char *strGBK )
{
    int len;
    wchar_t *strUnicode;
    char *strUTF8;
    if ( !strGBK )
    {
        return NULL;
    }

    len = MultiByteToWideChar( CP_ACP, 0,strGBK, -1, NULL,0 );
    if ( len < 1 )
    {
        return NULL;
    }
    strUnicode = (wchar_t *) malloc( sizeof(wchar_t) * len );
    if ( !strUnicode )
    {
        return NULL;
    }
    len = MultiByteToWideChar( CP_ACP, 0, strGBK, -1, strUnicode, len );
    if ( len < 1 )
    {
        free(strUnicode);
        return NULL;
    }

    len = WideCharToMultiByte( CP_UTF8, 0, strUnicode, -1, NULL, 0, NULL, NULL );
    if ( len < 1 )
    {
        free(strUnicode);
        return NULL;
    }
    strUTF8 = (char *) malloc( sizeof(char) * len );
    if ( !strUTF8 )
    {
        free(strUnicode);
        return NULL;
    }
    len = WideCharToMultiByte( CP_UTF8, 0, strUnicode, -1, strUTF8, len, NULL, NULL );
    free(strUnicode);
    if ( len < 1 )
    {
        free(strUTF8);
        return NULL;
    }
    return strUTF8;
}


阅读(1245) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~