Visual C++ Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

Visual C++ Examples

CkString
Byte Array
Bounced Mail
Character Encoding
Digital Certificates
Digital Signatures
Email
Encryption
FTP
HTML-to-XML
HTTP
IMAP
MHT / HTML Email
RSA Encryption
S/MIME
Socket
Spider
Tar
Upload
XML
XMP
Zip Compression


More Examples...
Email Object
POP3
SMTP
RSS
Atom
Self-Extractor

Unreleased...
Service
PPMD
Deflate
Bzip2
LZW
Bz2
DH Key Exchange
DSA
Icon

 

 

 

 

 

 

 

 

Convert Shift-JIS to utf-8 and back.

Download Chilkat C++ Libraries for VC++ 8.0 / Win32

Download Chilkat C++ Libraries for VC++ 7.0 / Win32

Download Chilkat C++ Libraries for VC++ 6.0 / Win32

Visual C++ source code showing how to convert Shift-JIS character data to utf-8 and the reverse (converting utf-8 to Shift-JIS).

#define _CRTDBG_MAP_ALLOC
#include "stdafx.h"
#include <stdio.h>
#include <crtdbg.h>
#include "C:/ck2000/components/ChilkatLib/Package/include/CkString.h"
#include "C:/ck2000/components/ChilkatLib/Package/include/CkByteData.h"
#include "C:/ck2000/components/ChilkatLib/Package/include/CkCharset.h"
#include "C:/ck2000/components/ChilkatLib/Package/include/CkSettings.h"

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
    CkCharset *cc = new CkCharset;
    cc->UnlockComponent("UnlockCode");

    // *************************************************
    // Convert from Shift-JIS to utf-8
    // *************************************************

    // Load the Shift-JIS sample data into memory.
    CkByteData *inData = new CkByteData;
    inData->loadFile("shiftJisSample.txt");

    // Convert from Shift-JIS to utf-8
    CkByteData *outData = new CkByteData;
    cc->put_ToCharset("utf-8");
    cc->put_FromCharset("Shift_JIS");
    cc->ConvertData(*inData,*outData);

    // Save the output.
    outData->saveFile("outUtf8.txt");

    // *************************************************
    // Convert from utf-8 to Shift-JIS
    // *************************************************

    // Load the utf-8 sample data into memory.
    inData->clear();
    inData->loadFile("utf8Sample.txt");

    // Convert from utf-8 to Shift-JIS
    // If there are any utf-8 characters that are not representable in SHIFT-JIS,
    // then replace them with a '?' character.
    // ErrorAction = 0, non-convertable characters are dropped.
    // ErrorAction = 1, non-convertable chars are hexidecimalized to the format &#xxxxxx;  where there can be as many as 6 octets in a single utf-8 character.
    // ErrorAction = 2, non-convertable chars are replaced with the error string.
    // More error actions are available, see http://www.chilkatsoft.com/refdoc
    outData->clear();
    cc->SetErrorString("?");
    cc->put_ErrorAction(2);

    cc->put_FromCharset("utf-8");
    cc->put_ToCharset("Shift_JIS");
    cc->ConvertData(*inData,*outData);

    // Save the output.
    outData->saveFile("outShiftJIS.txt");

    delete inData;
    delete outData;
    delete cc;

    // Only necessary if checking for memory leaks.
    // Only call just before exiting the program.
     CkSettings::cleanupMemory();

    _CrtDumpMemoryLeaks();

    return 0;
}




 

 

 

Need a specific example? Send a request to support@chilkatsoft.com

© 2000-2008 Chilkat Software, Inc. All Rights Reserved.

Mail Component · .NET Mail Component · XML Parser