Guidance
指路人
g.yi.org
Guidance Forums / wxWidgets (wxWindows) in C++ / Streams

Register 
新用户注册
Search 搜索
首页 
Home Home
Software
Upload

  
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. Streams
#2824
Posted by: 2003-11-01 23:15:17
Hey, I having problems getting a remote file to be fetched. I suspect it's to do with my lack of understanding of pointers.

Here's what I tried first.

    wxURL url(dlg.ThankYou());
    wxInputStream *in_stream;
    in_stream = url.GetInputStream();
    wxOutputStream *out_stream = new wxOutputStream();
    in_stream->Read(*out_stream);
// breaks here

    wxString stringy;
    out_stream->Write(stringy, out_stream->GetSize());
    wxMessageBox(stringy);
Then I changed to

    wxFileSystem* temp = new wxFileSystem();
    wxInputStream *in_stream;
    wxOutputStream *out_stream;
    in_stream = (temp->OpenFile(dlg.ThankYou()))->GetStream();    
    in_stream->Read(*out_stream);
Both crash at the Read, this is what DrMingw says:
NIB2.EXE caused an Access Violation at location 00450c47 in module NIB2.EXE Reading from location 13dfffff.

Registers:
eax=00001000 ebx=00001000 ecx=009efbb4 edx=13dfffff esi=00b1e9a0 edi=009ee7e0
eip=00450c47 esp=009ee7cc ebp=009ef7f8 iopl=0         nv up ei pl nz ac po nc
cs=0167  ss=016f  ds=016f  es=016f  fs=3bef  gs=0000             efl=00010216

Call stack:
00450C47  NIB2.EXE:00450C47
004024C7  NIB2.EXE:004024C7  MyFrame::NewDomainSearch(wxCommandEvent&)  MyFrame.cpp:77
   ...
       wxOutputStream *out_stream;
       in_stream = (temp->OpenFile(dlg.ThankYou()))->GetStream();   
>        in_stream->Read(*out_stream);
      
      
   ...

0043537A  NIB2.EXE:0043537A
004351CD  NIB2.EXE:004351CD
0042671E  NIB2.EXE:0042671E
0040677C  NIB2.EXE:0040677C
00406528  NIB2.EXE:00406528
00415920  NIB2.EXE:00415920
BFF7363B  KERNEL32.DLL:BFF7363B  EnumSystemCodePagesW
BFF94407  KERNEL32.DLL:BFF94407  CopyFileExW
009E8BEA
Can anyone help me?
Message2. Re: Streams
#2826
Posted by: upCASE 2003-11-02 00:48:38
Hmmm...
For me it seems to work.
I used

wxURL url("http://www.google.de" rel="nofollow" target="_blank" class="bt">http://www.google.de");
    wxInputStream *in_stream;
    in_stream = url.GetInputStream();
    wxFileOutputStream *out_stream = new wxFileOutputStream("mock.txt");
    in_stream->Read(*out_stream);

in a simple app to test if it crashes, but it worked fine. Are you sure that
1. reading into a dummy wxOutputStream works?
2. dlg.ThankYou() returns the correct URL?

upcase
upCASE
-----------------------------------
If it was hard to write, it should be hard to read!- Do. Or do not. There is no try!
Message3. Re: Streams
#2849
Posted by: 2003-11-03 05:46:03
Yeah, the url must have been wrong, it seems to working now I added some error checking.

I'm using

wxString UrlError(int a)
{
wxString temp;
switch(a)
{
case wxURL_NOERR:  temp =  "No error";break;  
case wxURL_SNTXERR:  temp =  "Syntax error in the URL string.";break;  
case wxURL_NOPROTO:  temp =  "Found no protocol which can get this URL.";break;  
case wxURL_NOHOST:  temp =  "An host name is required for this protocol.";break;  
case wxURL_NOPATH:  temp =  "A path is required for this protocol.";break;  
case wxURL_CONNERR:  temp =  "Connection error.";break;  
case wxURL_PROTOERR:  temp =  "An error occurred during negotiation.";break;
default: temp =  "Unknown error";break;
}
return temp;
}
int GetAsString(wxString& ac, wxString ca)
{
    wxURL url(ca);
    if(url.GetError() != wxURL_NOERR )
    {wxMessageBox(UrlError(url.GetError()));
    return -1;}
    wxInputStream *in_stream;
    in_stream = url.GetInputStream();
    if(url.GetError() != wxURL_NOERR )
    {wxMessageBox(UrlError(url.GetError()));
    return -1;}
    wxString buff;
    do{
    in_stream->Read(buff.GetWriteBuf(1024), 1024);
    buff.UngetWriteBuf();
    ac += buff;
    } while((in_stream->Eof()) != TRUE);
    return 1;
}
now which seems to be working, but isn't clean yet I know.
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Mon 2021-9-20  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0