博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
VC编译iconv库
阅读量:3984 次
发布时间:2019-05-24

本文共 3929 字,大约阅读时间需要 13 分钟。

 

iconv库可以实现编码格式转换,默认为Linux版本,如果要在windows下使用,需要在VC下重新编译

 

1. 下载 iconv 库    在这个地址下载想要的版本

2. VC6新建win32静态库工程,libIconv。复制iconv库lib文件夹所有文件到工程文件夹下

3. 将config.h.in改名为config.h

4. 将libcharset/lib/localcharset.c复制过来

5. 将include文件夹下iconv.h.in复制过来,改名为iconv.h

6. 将库中scrLib/localcharset.h复制过来

7. 工程属性, C/C++,Preprocssor, Addtional include diretory增加当前文件夹"."

8. 修改 iconv.h :

   a. 删除所有的 @ 符号,

   b. 注释掉/*DLL_VARIABLE*/,

   c. ICONV_CONST改为const,

9. 修改localcharset.c:

    注释掉 #include"configmake.h" 

10. 把有main函数的.c文件删掉

 

生成libIconv.lib,头文件即iconv.h

 

注:在VS2008中第2步注意

,可以先建立一个空工程,进入工程属性,常规->配置类型->静态库(.lib)

VC6编译的库不能在VS2008下用,要在VS2008重新编译

 

///

///

///

下面是验证代码(复制自VLC):

#include 
#include
#include
#pragma comment(lib,"libIconv.lib") static char *dvbsi_to_gb2312( char*psz_instring, size_t i_length ){ char *psz_encoding, *psz_stringstart, *psz_outstring, *psz_tmp; char psz_encbuf[12]; size_t i_in, i_out; iconv_t iconv_handle; if( i_length < 1 ) return NULL; if( psz_instring[0] >= 0x20 ) { psz_stringstart = psz_instring; psz_encoding = "ISO_8859-1"; /* should be ISO6937 according tospec,but this seems to be the one used */ }else switch( psz_instring[0] ) { case 0x01: psz_stringstart = &psz_instring[1]; psz_encoding = "ISO_8859-5"; break; case 0x02: psz_stringstart = &psz_instring[1]; psz_encoding = "ISO_8859-6"; break; case 0x03: psz_stringstart = &psz_instring[1]; psz_encoding = "ISO_8859-7"; break; case 0x04: psz_stringstart = &psz_instring[1]; psz_encoding = "ISO_8859-8"; break; case 0x05: psz_stringstart = &psz_instring[1]; psz_encoding = "ISO_8859-9"; break; case 0x06: psz_stringstart = &psz_instring[1]; psz_encoding = "ISO_8859-10"; break; case 0x07: psz_stringstart = &psz_instring[1]; psz_encoding = "ISO_8859-11"; break; case 0x08: psz_stringstart = &psz_instring[1]; /*possibly reserved?*/ psz_encoding = "ISO_8859-12"; break; case 0x09: psz_stringstart = &psz_instring[1]; psz_encoding = "ISO_8859-13"; break; case 0x0a: psz_stringstart = &psz_instring[1]; psz_encoding = "ISO_8859-14"; break; case 0x0b: psz_stringstart = &psz_instring[1]; psz_encoding = "ISO_8859-15"; break; // case 0x10: // if( i_length < 3 ||psz_instring[1] != '\0' || psz_instring[2] > 0x0f // || psz_instring[2]== 0 ) // returnEnsureUTF8(strndup(psz_instring,i_length)); // sprintf( psz_encbuf,"ISO_8859-%d", psz_instring[2] ); // psz_stringstart =&psz_instring[3]; // psz_encoding =psz_encbuf; // break; case 0x11: psz_stringstart = &psz_instring[1]; psz_encoding = "UTF-16"; break; case 0x12: psz_stringstart = &psz_instring[1]; psz_encoding = "KSC5601-1987"; break; case 0x13: psz_stringstart = &psz_instring[1]; psz_encoding = "GB2312";/*GB-2312-1980 */ break; case 0x14: psz_stringstart = &psz_instring[1]; psz_encoding = "BIG-5"; break; // case 0x15: // returnEnsureUTF8(strndup(&psz_instring[1],i_length-1)); // break; default: /* invalid */ return NULL; // todo EnsureUTF8(strndup(psz_instring,i_length)); } iconv_handle = iconv_open( "GB2312", psz_encoding ); i_in = i_length - (psz_stringstart - psz_instring ); i_out = i_in * 6; psz_outstring = psz_tmp = (char*)malloc( i_out * sizeof(char) + 1 ); iconv( iconv_handle, (const char **)&psz_stringstart, &i_in,&psz_tmp, &i_out ); iconv_close( iconv_handle ); *psz_tmp = '\0'; return psz_outstring;} int main(){ char a[] = {0x11, 0x73, 0xAF, 0x74, 0x03, 0x65, 0xC5, 0x6E, 0x38, 0x00}; char *b = dvbsi_to_gb2312(a, sizeof(a)); printf("%s\r\n", b); return 0;}

转载地址:http://tzxui.baihongyu.com/

你可能感兴趣的文章
小谈python 输出
查看>>
Django objects.all()、objects.get()与objects.filter()之间的区别介绍
查看>>
python:如何将excel文件转化成CSV格式
查看>>
Django 的Error: [Errno 10013]错误
查看>>
机器学习实战之决策树(一)
查看>>
[LeetCode By Python] 2 Add Two Number
查看>>
python 中的 if __name__=='__main__' 作用
查看>>
机器学习实战之决策树二
查看>>
[LeetCode By Python]7 Reverse Integer
查看>>
[LeetCode By Python]9. Palindrome Number
查看>>
[LeetCode By Python]13 Roman to Integer
查看>>
[leetCode By Python] 14. Longest Common Prefix
查看>>
[LeetCode By Python]107. Binary Tree Level Order Traversal II
查看>>
[LeetCode By Python]108. Convert Sorted Array to Binary Search Tree
查看>>
[leetCode By Python]111. Minimum Depth of Binary Tree
查看>>
[LeetCode By Python]112. Path Sum
查看>>
[LeetCode By Python]118. Pascal's Triangle
查看>>
[LeetCode By Python]119. Pascal's Triangle II
查看>>
[LeetCode By Python]121. Best Time to Buy and Sell Stock
查看>>
[LeetCode By Python]122. Best Time to Buy and Sell Stock II
查看>>