opening file outside wxWidgets

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Jacek Poplawski
Knows some wx things
Knows some wx things
Posts: 38
Joined: Mon Jun 20, 2011 12:03 pm

opening file outside wxWidgets

Post by Jacek Poplawski »

I use following code to get file name to open:

Code: Select all

    wxString type = _T("JPEG/TIFF files (*.jpg;*.jpeg;*.tiff;*.tif;*.TIF;*.TIFF)|*.jpg;*.jpeg;*.tiff;*.tif;*.TIF;*.TIFF");
    wxFileDialog openFileDialog(this, _T("Open source image"), _T(""), _T(""), type, wxFD_OPEN|wxFD_FILE_MUST_EXIST);

    if (openFileDialog.ShowModal() == wxID_CANCEL)
    {
        return;
    }

    wxString fileName = openFileDialog.GetPath();
    char cstring[1024];
    strncpy(cstring, (const char*)fileName.mb_str(wxConvUTF8), 1023);
which of course doesn't work when the filepath uses non-ascii characters, like special polish characters (and probably whole japanese/chinese/etc alphabet)

I need char[] data to pass it to this function:

TIFF* TIFFOpen(const char *filename, const char *mode)

(read "man TIFFOpen" if you are on Linux)

The question is - how to traslate wxWidgets GetPath() to char[] correctly to support non-ascii characters and pass it to TIFFOpen?

PS. Please don't suggest opening TIFF by wxWidgets - I need 16-bit data, wxWidgets doesn't support that
User avatar
doublemax
Moderator
Moderator
Posts: 19159
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: opening file outside wxWidgets

Post by doublemax »

The question is - how to traslate wxWidgets GetPath() to char[] correctly to support non-ascii characters and pass it to TIFFOpen?
You just have to find out with character encoding TIFFOpen expects for the filename and use the proper conversion.

For a starts, try using wxConvLocal instead of wxConvUTF8.
Use the source, Luke!
Post Reply