网上找的转UTF8的代码

···C++
void (*ucnv_convert)(const char *,const char *, char * , int32_t , const char , int32_t,int32_t)=0;

int dllOpencuuc()
{

void* pDL = dlopen("/system/lib/libicuuc.so", RTLD_LAZY); 
ucnv_convert = (void (*)(const char *, const char *, char * , int32_t , const char *, int32_t,int32_t*))dlsym(pDL, "ucnv_convert_44");//ucnv_convert_44(2.3) ucnv_convert_4_2(2.2)

if(pDL)
{
    dlclose(pDL);
}
if(ucnv_convert)
{

    return 1;
}else
{
    ucnv_convert  = (void (*)(const char *, const char *, char * , int32_t , const char *, int32_t,int32_t*))dlsym(pDL, "ucnv_convert_46");//ucnv_convert_44(2.3) ucnv_convert_4_2(2.2) ucnv_convert_46(4.0)

    if(ucnv_convert)
    {

        return 1;
    }
    ucnv_convert  = (void (*)(const char *, const char *, char * , int32_t , const char *, int32_t,int32_t*))dlsym(pDL, "ucnv_convert_4_2");
    if(ucnv_convert)
    {

        return 1;
    }
}

return 0;

}

int GB2312ToUtf8( char *CP, char *inbuf , size_t _in_size , char *outbuf , size_t _out_size )
{

int errcode = 0;  
ucnv_convert("utf-8",CP, outbuf, _out_size, inbuf, _in_size,&errcode); 
if(errcode)
{ 
    return -1;
}
else
{
    return 0;
}

}

int Utf8ToGB2312(char CP,char inbuf, size_t _in_size, char* outbuf, size_t _out_size)
{
int errcode = 0;
ucnv_convert("GBK",CP, outbuf, _out_size, inbuf, _in_size,&errcode);
if(errcode)
{
return -1;
}
else
{
return 0;
}
}
···

你可能感兴趣的:(网上找的转UTF8的代码)