Win32API里面要这样的调用么? 应该如何做到呢?
thx

解决方案 »

  1.   

    http://wangjianying.com/html/ba87d05347fa97db.html
      

  2.   

    IsTextUnicode The IsTextUnicode function determines whether a buffer probably contains a form of Unicode text. The function uses various statistical and deterministic methods to make its determination, under the control of flags passed via lpi. When the function returns, the results of such tests are reported via lpi. If all specified tests are passed, the function returns TRUE; otherwise, it returns FALSE.DWORD IsTextUnicode(    CONST LPVOID lpBuffer, // pointer to an input buffer to be examined
        int cb, // the size in bytes of the input buffer
        LPINT lpi // pointer to flags that condition text examination and receive results
       );
      

  3.   

    有bom头使用bom头,没bom头一概先按utf8看待,然后转成国标,数?的个数。与原来相比,?少的话就是utf8,?多的话就是国标。
      

  4.   

    DWORD IsTextUnicode(CONST PVOID pvBuffer, int cb,PINT pResult);
    文本文件存在的问题是,它们的内容没有严格和明确的规则,因此很难确定该文件是包含A N S I 字符还是U n i c o d e 字符。I s Te x t U n i c o d e 使用一系列统计方法和定性方法,以便猜测缓存的内容。由于这不是一种确切的科学方法,因此I s Te x t U n i c o d e 有可能返回不正确的结果。第一个参数p v B u ff e r 用于标识要测试的缓存的地址。该数据是个无效指针,因为你不知道你拥有的是A N S I 字符数组还是U n i c o d e 
    字符数组。第二个参数c b 用于设定p v B u ff e r 指向的字节数。同样,由于你不知道缓存中放的是什么,因此c b 是个字节数,而不是字符数。请注意,不必设定缓存的整个长度。当然,I s Te x t U n i c o d e能够测试的字节越多,得到的结果越准确。第三个参数p R e s u l t 是个整数的地址,必须在调用I s Te x t U n i c o d e 之前对它进行初始化。对该整数进行初始化后,就可以指明你要I s Te x t U n i c o d e 执行哪些测试。也可以为该参数传递N U L L ,在这种情况下,I s Te x t U n i c o d e 将执行它能够进行的所有测试(详细说明请参见Platform SDK 文档)。如果I s Te x t U n i c o d e 认为缓存包含U n i c o d e 文本,便返回T R U E ,否则返回FA L S E 。确实是这样,尽管M i c r o s o f t将该函数的原型规定为返回D W O R D ,但是它实际上返回一个布尔值。如果在p R e s u l t 参数指向的整数中必须进行特定的测试,该函数就会在返回之前设定整数中的信息位,以反映每个测试的结果。Wi n d o w s 9 8 在Windows 98 下,I s Te x t U n i c o d e 函数没有有用的实现代码,它只是返回FA L S E 。
      

  5.   

    读入文本的前2个或3个字节,判断UTF8头就可以了。
      

  6.   

    写入 utf8文本文件头(c#):
      byte[] utf8Header = {0xef, 0xbb, 0xbf};
      File.WriteAllBytes(fileName, utf8Header);