openexr-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [Openexr-devel] RE: UNICODE support in openexr file I/O


From: Nick Porcino
Subject: RE: [Openexr-devel] RE: UNICODE support in openexr file I/O
Date: Thu, 26 Jan 2006 13:22:11 -0800

Success. This displays properly in the file browser in Windows. Thanks everyone 
for your help.


#include <stdio.h>
#include <windows.h>
#include <string>

// Kyoto-to encoded as UTF-8.
const char name[] =
{0xe4, 0xba, 0xac, 0xe9, 0x83, 0xbd, 0xe5, 0xb8, 0x82, 0};

using std::wstring;

wstring 
toWideString( const char* pStr , int len )
{
    // figure out how many wide characters we are going to get 
    int nChars = MultiByteToWideChar( CP_UTF8 , 0 , pStr , len , NULL , 0 ) ; 
    if ( len == -1 )
        -- nChars ; 
    if ( nChars == 0 )
        return L"" ;

    // convert the narrow string to a wide string 
    // nb: slightly naughty to write directly into the string like this
    wstring buf ;
    buf.resize( nChars ) ; 
    MultiByteToWideChar( CP_UTF8 , 0 , pStr , len , 
        const_cast<wchar_t*>(buf.c_str()) , nChars ) ; 

    return buf ;
}

int _tmain(int argc, _TCHAR* argv[])
{
    wstring wname = toWideString(name, strlen(name));
    FILE* x = _wfopen(wname.c_str(), L"wb");
        return 0;
}





-----Original Message-----
From: Lutz Latta [mailto:address@hidden 
Sent: Thursday, January 26, 2006 12:45 PM
To: Nick Porcino
Cc: address@hidden
Subject: Re: [Openexr-devel] RE: UNICODE support in openexr file I/O

Your test 4 is basically the correct approach, but you need to change 
the MultiByteToWideChar argument CP_ACP (your system's ANSI code page) 
to CP_UTF8. Additionally don't cast the second argument to _wfopen, 
specify it as wide string with  L"wb", or use CreateFileW on Windows.
    Lutz


Nick Porcino wrote:
> TEST FOUR - _wfopen + UTF-8 -> 16 conversion
> 
> Finally:
> 
> 
> using std::wstring;
> 
> wstring 
> toWideString( const char* pStr , int len )
> {
>     // figure out how many wide characters we are going to get 
>     int nChars = MultiByteToWideChar( CP_ACP , 0 , pStr , len , NULL , 0 ) ; 
>     if ( len == -1 )
>         -- nChars ; 
>     if ( nChars == 0 )
>         return L"" ;
> 
>     wstring buf ;
>     buf.resize( nChars ) ; 
>     MultiByteToWideChar( CP_ACP , 0 , pStr , len , 
>         const_cast<wchar_t*>(buf.c_str()) , nChars ) ; 
> 
>     return buf ;
> }
> 
> int _tmain(int argc, _TCHAR* argv[])
> {
>     wstring wname = toWideString(name, strlen(name));
>     FILE* x = _wfopen(wname.c_str(), (const wchar_t*)"wb");
>       return 0;
> }
> 
> äºéƒ½å¸‚#
> 
> (random junk)






reply via email to

[Prev in Thread] Current Thread [Next in Thread]