ChnconvEx ChnconvStringEx ChnconvCharEx IsChnconvValidCodePage GetChnconvLastError AbortChnconv GetDllVersion |
CHNCONVEXINFO CHNFONTINFO CHNCONV_USERDEF |
Sample 1    Sample 2    Sample 3    Sample 4    |
int WINAPI ChnconvEx ( LPCTSTR pSrcFileName, LPCTSTR pDstFileName, int nSrcCodePage, int nDstCodePage, const CHNCONVEXINFO * pChnconvExInfo ) ;
LPCTSTR pSrcFileName /* Source filename */ LPCTSTR pSrcFileName /* Destination filename */Specifies the filename of the source and the destination. A filename may be a full pathname, a relative pathname, or a UNC. If the filename is NULL, the function will open stdin or stdout.
int nSrcCodePage /* Source code page */ int nDstCodePage /* Destination code page */Specifies the code page of the source and the destination.
GB2312/GBK 936 BIG5 950 Chinese Writer 932 + 0x10000 Nihao 932 + 0x20000 cWnn 932 + 0x30000 Zhongwen Qigao 932 + 0x40000 CX 932 + 0x50000 KOA-TechnoMate Zhongguoyu 932 + 0x60000 Zhuojue 932 + 0x70000 Front Wenhua 932 + 0x80000 HZ 52936These codepages are defined with the following names in "chnconv.h".
GB2312/GBK CP_CHINESE_SIMPLIFIED BIG5 CP_CHINESE_TRADITIONAL Chinese Writer CP_CHINESE_CW Nihao CP_CHINESE_NH cWnn CP_CHINESE_CWN Zhongwen Qigao CP_CHINESE_ZQ CX CP_CHINESE_CX KOA-TechnoMate Zhongguoyu CP_CHINESE_TM Zhuojue CP_CHINESE_ZJ Front Wenhua CP_CHINESE_FW HZ CP_HZ_CHINESE_SIMPLIFIED
const CHNCONVEXINFO * pChnconvExInfo /* Options */Pointer to a CHNCONVEXINFO structure that determines the options of conversion. If this parameter is NULL, the function will perform default conversion.
CHNCONV_SUCCESS Conversion was successful. |
CHNCONV_ERROR_UNKNOWN Occurred unknown errors. |
CHNCONV_ERROR_READ Failed to read the source file. |
CHNCONV_ERROR_WRITE Failed to write the destination file. |
CHNCONV_ERROR_RTFFORMAT Occurred errors of RTF format. |
CHNCONV_ERROR_RTFBRACE Occurred errors of RTF format. |
CHNCONV_ERROR_MEMORY Failed to allocate required memory. |
CHNCONV_ERROR_CODEPAGE The code page is invalid. |
CHNCONV_ERROR_ABORTED Aborted by AbortChnconv during conversion. |
CHNCONV_ERROR_PARAM Specified parameters are invalid. |
intptr_t WINAPI ChnconvStringEx ( const char * pSrcBuffer, char * pDstBuffer, int nSrcCodePage, int nDstCodePage, const CHNCONVEXINFO * pChnconvExInfo, size_t nMaxLen ) ;
const char * pSrcBuffer /* Pointer to the source string */ char * pDstBuffer /* Pointer to the destination buffer */Specifies the pointer to the source string and the destination buffer. The string pointed to by pSrcBuffer must be null-terminated. If the same address is specified to pSrcBuffer and pDstBuffer, the result of conversion is undefined.
int nSrcCodePage /* Source codepage */ int nDstCodePage /* Destination codepage */Specifies the code page of the source and the destination. See nSrcCodePage and nDstCodePage of ChnconvEx for more information.
const CHNCONVEXINFO * pChnconvExInfo /* Options */Pointer to a CHNCONVEXINFO structure that determines the options of conversion. If this parameter is NULL, the function will perform default conversion.
size_t nMaxLen /* Size of destination buffer */Specifies the size of destination buffer, in bytes.
int WINAPI ChnconvCharEx ( int C, int nSrcCodePage, int nDstCodePage, const CHNCONVEXINFO *pChnconvExInfo ) ;
int C /* Character */Specifies a character code.
int nSrcCodePage /* Source codepage */ int nDstCodePage /* Destination codepage */Specifies the code page of the source and the destination. See nSrcCodePage and nDstCodePage of ChnconvEx for more information.
const CHNCONVEXINFO * pChnconvExInfo /* Options */Pointer to a CHNCONVEXINFO structure that determines the options of conversion. If this parameter is NULL, the function will perform default conversion.
int WINAPI IsChnconvValidCodePage ( int nSrcCodePage, int nDstCodePage ) ;
int WINAPI GetChnconvLastError ( void ) ;
CHNCONV_SUCCESS Conversion was successful. |
CHNCONV_ERROR_UNKNOWN Occurred unknown errors. |
CHNCONV_ERROR_READ Failed to read the source file. |
CHNCONV_ERROR_WRITE Failed to write the destination file. |
CHNCONV_ERROR_RTFFORMAT Occurred errors of RTF format. |
CHNCONV_ERROR_RTFBRACE Occurred errors of RTF format. |
CHNCONV_ERROR_MEMORY Failed to allocate required memory. |
CHNCONV_ERROR_CODEPAGE The code page is invalid. |
CHNCONV_ERROR_ABORTED Aborted by AbortChnconv during conversion. |
CHNCONV_ERROR_PARAM Specified parameters are invalid. |
int WINAPI AbortChnconv ( void ) ;
int WINAPI GetDllVersion ( void ) ;
typedef struct { size_t cbSize ; unsigned long dwConversionMode ; unsigned long dwAdditionalMode ; const CHNFONTINFO * pFontInfo ; const CHNCONV_USERDEF * pSrcToDst ; size_t nNumberOfSrcToDst ; const CHNCONV_USERDEF * pSrcToUc ; size_t nNumberOfSrcToUc ; int nFontSize ; const void * pReserved ; } CHNCONVEXINFO ;
CONVMODE_PEEKMESSAGE Peek messages during conversion. |
CONVMODE_OUTPUT_CODE_NUMBER Write its Code Number for unmappable characters. |
CONVMODE_INPUT_CODE_NUMBER Recognize Code Numbers which are written by option CONVMODE_OUTPUT_CODE_NUMBER. |
CONVMODE_ONE_QUESTION_MARK Write one question mark '?' if cannot convert. If not specified this flag, the function will write two question marks for full-width characters. |
CONVMODE_CONVERT_TXT Read files as plain text compulsorily. |
CONVMODE_CONVERT_RTF Read files as rich text format compulsorily. |
CONVMODE_CHNCONV_NO_VARIANT Do not search for character variants. |
CONVMODE_CHNCONV_NO_GBK Do not convert GBK extended characters. |
CONVMODE_PINYIN_BY_ASCII Write pinyin characters by single-byte font on writing RTF. |
CONVMODE_OUTPUT_NEW_FONT Write new font names on writing RTF of Chinese Writer. |
CONVMODE_SENSE_CW_FANTIZI Sense CW/CWN FANTIZI font on reading RTF. |
CONVMODE_CW_TXT_FANTIZI Read CW/CWN text files as FANTIZI. |
CONVMODE_NO_USE_UNICODE Do not use Unicode on converting characters. |
typedef struct { size_t cbSize ; const char *pGbFont ; const char *pGbGothicFont ; const char *pBig5Font ; const char *pBig5GothicFont ; const char *pPinyinFont ; const char *pPinyinGothicFont ; } CHNFONTINFO ;
typedef struct { int nSrc ; int nDst ; } CHNCONV_USERDEF ;
/* Convert a Chinese Writer RTF file to GB. */ #include <windows.h> #include "chnconv.h" typedef int (WINAPI *CHNCONVEX) ( LPCTSTR pSrcFileName, LPCTSTR pDstFileName, int nSrcCodePage, int nDstCodePage, const CHNCONVEXINFO *pChnconvExInfo ) ; int main () { /* DLL */ HINSTANCE hChnconv ; CHNCONVEX pChnconvEx ; /* Reading DLL */ hChnconv = LoadLibrary( TEXT("chnconv.dll") ) ; if ( hChnconv == NULL ) { return 1 ; } #ifdef UNICODE pChnconvEx = (CHNCONVEX) GetProcAddress( hChnconv, "ChnconvExW" ) ; #else pChnconvEx = (CHNCONVEX) GetProcAddress( hChnconv, "ChnconvExA" ) ; #endif if ( pChnconvEx == NULL ) { FreeLibrary( hChnconv ) ; return 1 ; } /* Conversion */ pChnconvEx ( TEXT("c:\\foo.rtf"), TEXT("c:\\poo.rtf"), CP_CHINESE_CW, CP_CHINESE_SIMPLIFIED, NULL ) ; /* Finalization */ FreeLibrary( hChnconv ) ; return 0 ; }
/* Convert a cWnn string to GB. */ #include <windows.h> #include "chnconv.h" typedef intptr_t (WINAPI *CHNCONVSTRINGEX) ( const void *pSrcBuffer, void *pDstBuffer, int nSrcCodePage, int nDstCodePage, const CHNCONVEXINFO *pChnconvExInfo, size_t nMaxLen ) ; int main () { char szGbBuffer [ 0x100 ] ; wchar_t szUcBuffer [ 0x100 ] ; /* DLL */ HINSTANCE hChnconv ; CHNCONVSTRINGEX pChnconvStringEx ; /* Reading DLL */ hChnconv = LoadLibrary( TEXT("chnconv.dll") ) ; if ( hChnconv == NULL ) { return 1 ; } pChnconvStringEx = (CHNCONVSTRINGEX) GetProcAddress( hChnconv, "ChnconvStringEx" ) ; if ( pChnconvStringEx == NULL ) { FreeLibrary( hChnconv ) ; return 1 ; } /* Convert to GB */ pChnconvStringEx( "\x9B\xCE\x8D\x9A", szGbBuffer, CP_CHINESE_CWN, CP_CHINESE_SIMPLIFIED, 0, sizeof(szGbBuffer) ); /* Convert to UNICODE */ MultiByteToWideChar ( CP_CHINESE_SIMPLIFIED, 0, szGbBuffer, -1, szUcBuffer, sizeof(szUcBuffer)/sizeof(wchar_t) ) ; /* Display */ MessageBoxW( NULL, szUcBuffer, L"test", MB_OK ) ; /* Finalization */ FreeLibrary( hChnconv ) ; return 0 ; }
/* Convert a cWnn character to GB. */ #include <windows.h> #include <stdio.h> #include "chnconv.h" typedef intptr_t (WINAPI *CHNCONVCHAREX) ( int C, int nSrcCodePage, int nDstCodePage, int nSrcCodePage, int nDstCodePage, const CHNCONVEXINFO *pChnconvExInfo ) ; int main () { int C ; /* DLL */ HINSTANCE hChnconv ; CHNCONVCHAREX pChnconvCharEx ; hChnconv = LoadLibrary( "chnconv.dll" ) ; if ( hChnconv == NULL ) return 1 ; pChnconvCharEx = (CHNCONVSTRING) GetProcAddress( hChnconv, "ChnconvCharEx" ) ; if ( pChnconvCharEx == NULL ) { FreeLibrary( hChnconv ) ; return 1 ; } C = pChnconvCharEx( 0x9BCE, CP_CHINESE_CWN, CP_CHINESE_SIMPLIFIED, NULL ); if ( C <= 0 ) { FreeLibrary( hChnconv ) ; return 1 ; } if ( C & 0xFF00 ) fputc( ( C >> 8 ) & 0xFF, stdout ) ; fputc( C & 0xFF, stdout ) ; FreeLibrary( hChnconv ) ; return 0 ; }
/* Convert a Chinese Writer RTF file to GB, with "STKaiti" to CJK characters. */ #include <windows.h> #include "chnconv.h" typedef int (WINAPI *CHNCONVEX) ( LPCTSTR pSrcFileName, LPCTSTR pDstFileName, int nSrcCodePage, int nDstCodePage, const CHNCONVEXINFO *pChnconvExInfo ) ; int main () { /* DLL */ HINSTANCE hChnconv ; CHNCONVEX pChnconvEx ; /* Structures */ CHNCONVEXINFO ChnconvExInfo = { sizeof(CHNCONVEXINFO) } ; CHNFONTINFO FontInfo = { sizeof(CHNFONTINFO) } ; /* Reading DLL */ hChnconv = LoadLibrary( TEXT("chnconv.dll") ) ; if ( hChnconv == NULL ) { return 1 ; } #ifdef UNICODE pChnconvEx = (CHNCONVEX) GetProcAddress( hChnconv, "ChnconvExW" ) ; #else pChnconvEx = (CHNCONVEX) GetProcAddress( hChnconv, "ChnconvExA" ) ; #endif if ( pChnconvEx == NULL ) { FreeLibrary( hChnconv ) ; return 1 ; } /* Options */ FontInfo.pGbFont = "STKaiti" ; ChnconvExInfo.pFontInfo = & FontInfo ; /* Conversion */ pChnconvEx ( TEXT("c:\\foo.rtf"), TEXT("c:\\poo.rtf"), CP_CHINESE_CW, CP_CHINESE_SIMPLIFIED, & ChnconvExInfo ) ; /* Finalization */ FreeLibrary( hChnconv ) ; return 0 ; }