C语言打开带有中文路径的sqlie3数据库,sqlite3错误14,中文路径转成utf8编码

0 篇文章 0 订阅

参考:

https://blog.csdn.net/u011135902/article/details/50544678

//编码转换
//多字符集(包括ascii) 转 Unicode
WCHAR *mbcs2unicode(const char *mbcsstr)
{
    int nByte;
    WCHAR *unicodestr;
    int codepage = AreFileApisANSI() ? CP_ACP : CP_OEMCP;
    nByte = MultiByteToWideChar(codepage, 0, mbcsstr, -1, NULL, 0);
    unicodestr = (WCHAR *)malloc(nByte * 2);
    if (unicodestr == 0)
    {
        return 0;
    }
    nByte = MultiByteToWideChar(codepage, 0, mbcsstr, -1, unicodestr, nByte);
    if (nByte == 0)
    {
        free(unicodestr);
        unicodestr = 0;
    }
    return unicodestr;
}
//Unicode 转 utf-8
char *unicode2utf8(const WCHAR *unicodestr)
{
    int nByte;
    char *utf8str;
    
    
    nByte = WideCharToMultiByte(CP_UTF8, 0, unicodestr, -1, 0, 0, 0, 0);
    utf8str = (char*)malloc(nByte);
    if (utf8str == 0)
        return 0;
    nByte = WideCharToMultiByte(CP_UTF8, 0, unicodestr, -1, utf8str, nByte, 0, 0);
    if (nByte == 0)
    {
        free(utf8str);
        utf8str = 0;
    }
    return utf8str;
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值