what's wrong with wxFile,can't close file descriptor 3 Topic is solved

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
sunose
Earned a small fee
Earned a small fee
Posts: 16
Joined: Tue Jul 07, 2009 2:01 am

what's wrong with wxFile,can't close file descriptor 3

Post by sunose »

just simple wxForm program with unicode enable wxwidgets 2.8.10

#include <wx/msgdlg.h>
#include <wx/file.h>

on app.cpp has follow code:

Code: Select all

IMPLEMENT_APP(testFApp);

bool testFApp::OnInit()
{
 wxString fileName =_("config.ini");
        wxFile t(fileName,wxFile::write);
//   if(wxFile::Exists(fileName))
//      {
   //     t.Create(fileName,true);
//      }
   wxMessageBox(wxString::Format(_("file descrptior %d,Access read? %d ,write? %d"),t.fd(),t.Access(fileName,wxFile::read ),t.Access(fileName,wxFile::write)));
wxMBConvUTF16 conv;
      t.Write(wxT("this is a test\n"),conv);
      t.Close();
    //(*AppInitialize
    bool wxsOK = true;
    wxInitAllImageHandlers();
    if ( wxsOK )
    {
    	testFFrame* Frame = new testFFrame(0);
    	Frame->Show();
    	SetTopWindow(Frame);
    }
    //*)
    return wxsOK;

}

when app runing get error message box ,please see attachment
Attachments
error.JPG
error.JPG (20.48 KiB) Viewed 1503 times
User avatar
doublemax
Moderator
Moderator
Posts: 19115
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Post by doublemax »

use wxFile::IsOpened to check if the file was properly openened. You don't always have write access to your own application directory.

use wxStandardPaths to find a proper place for your configuration file.
http://docs.wxwidgets.org/stable/wx_wxs ... ndardpaths
Use the source, Luke!
sunose
Earned a small fee
Earned a small fee
Posts: 16
Joined: Tue Jul 07, 2009 2:01 am

Post by sunose »

doublemax wrote:use wxFile::IsOpened to check if the file was properly openened. You don't always have write access to your own application directory.

use wxStandardPaths to find a proper place for your configuration file.
http://docs.wxwidgets.org/stable/wx_wxs ... ndardpaths

Code: Select all

   if(t.IsOpened())
     {
      wxMessageBox(_("open is ok!"));
      t.Write(wxT("this is a test\n"),conv);
      t.Close();
     }else
     {
      wxMessageBox(_("not opened!"));
     }
add isopened check ,not problem,the file is correctly open ,but when Close this file,error happend.

but zero lenght file is created and the data hasn't writed to file .

other way,I use console no gui window cmd the code works

I can't find why under GUi wssmith method ,the wxFile can't work.

the attachment is wxFile under console method.
Attachments
console.cpp
wxFile work without GUI
with gui (wxsmith code wizard by codeblocks) wxFile not work close has can't colose file descriptor xx error.
(521 Bytes) Downloaded 48 times
sunose
Earned a small fee
Earned a small fee
Posts: 16
Joined: Tue Jul 07, 2009 2:01 am

Post by sunose »

I find the Cause!

CodeBlocks generate compiler has some wrong .(I have not find why).

I use wxwidgets samples complier command .

g++ -c testFMain.cpp -o obj\testFMain.o -O2 -mthreads -DHAVE_W32API_H -D__WXMSW__ -D_UNICODE -IG:\wxWidgets-2.8.10\lib\gcc_lib\mswu -IG:\wxWidgets-2.8.10\include -W -Wall -I. -DNOPCH -MD -MP --define __WXMSW__ --define _UNICODE --define NOPCH

g++ -o bin\Release\testF.exe obj\testFApp.o obj\testFMain.o -mthreads -LG:\wxWidgets-2.8.10\lib\gcc_lib -Wl,--subsystem,windows -mwindows -lwxmsw28u_core -lwxbase28u -lwxtiff -lwxjpeg -lwxpng -lwxzlib -lwxregexu -lwxexpat -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lwinspool -lwinmm -lshell32 -lcomctl32 -lole32 -loleaut32 -luuid -lrpcrt4 -ladvapi32 -lwsock32 -lodbc32

the wxFile work!.so I will submit this case to codeblocks.

thanks all reply.
Post Reply