简体-繁体内码转换API

 public class ANSIConversionAPI
    {
       
        const int SIMPLIFIED_CHINESE = 0x02000000;
        const int TRADITIONAL_CHINESE = 0x04000000;
       
       
       
        [DllImport("kernel32.dll", EntryPoint = "LCMapStringA")]
        public static extern int LCMapString(int Locale, int dwMapFlags, byte[] lpSrcStr, int cchSrc, byte[] lpDestStr, int cchDest);

 

 


        public  string BigToGb2312Ex(string str)
        {

            byte[] src = Encoding.GetEncoding(936).GetBytes(str);
            byte[] dest = new byte[src.Length];
            LCMapString(0x0804, SIMPLIFIED_CHINESE, src, -1, dest, src.Length);
            return Encoding.GetEncoding(936).GetString(dest);

        }

        public  string Gb2312ToGigEx(string str)
        {

            byte[] src = Encoding.GetEncoding(936).GetBytes(str);
            byte[] dest = new byte[src.Length];
            LCMapString(0x0804, TRADITIONAL_CHINESE, src, -1, dest, src.Length);
            return Encoding.GetEncoding(936).GetString(dest);
        }

 


    }

posted @ 2008-12-08 13:27  阿新  阅读(639)  评论(0编辑  收藏  举报