locked
error C2039: 'Close' : is not a member of 'Windows::Storage::Streams::DataWriter__

    Question

  • When I want to close the current stream and release the system resources

    I I create it like this

    DataReader^ _reader  = ref new DataReader(IInputstream^ receivedata);

    _reader->Close();

    why it says like the title


    • Edited by oishixixi Monday, May 07, 2012 5:33 AM
    Monday, May 07, 2012 5:21 AM

Answers

  • Thanks. I can reproduce that in a basic sample, but it still compiles clean in the File Access sample.

    I'm not sure what is different. I suspect that we may be getting the IDataReader interface (which doesn't define Close) rather than the DataReader object (which defines IDataReader and IClosable), but I'm not sure why yet or why it doesn't occur in my other project.

    If you don't need the DataReader any longer you can delete it rather than calling Close() on it. C++ will deterministically destroy the object and automatically Close it when that occurs. In C# the Close/Dispose() call is more necessary because the object will live until it gets garbage collected.

    --Rob

    • Marked as answer by oishixixi Wednesday, May 09, 2012 3:11 AM
    Wednesday, May 09, 2012 12:46 AM
    Owner

All replies

  • _reader->Close() should compile and run fine. I cannot reproduce the problem adding a call to Close to the DataReader in the File Access sample.

    Can you provide a minimal sample application which demonstrates the problem?

    --Rob

    Tuesday, May 08, 2012 3:17 AM
    Owner
  • Deat Rob

    MainPage::MainPage() { InitializeComponent(); test(); } typedef struct { StreamSocket^ smi_socket; DataReader^ smi_reader_; }SMI_socket; int MainPage::test() { SMI_socket* _socket = NULL; if (NULL == (_socket = (SMI_socket *)malloc(sizeof(SMI_socket)))){ printf("ERROR - malloc failed in SMI_socket()\n"); } memset(_socket, 0, sizeof(SMI_socket)); _socket->smi_socket = ref new StreamSocket(); IInputStream^ smi_receivedata = _socket->smi_socket->InputStream; _socket->smi_reader_ = ref new DataReader(smi_receivedata); _socket->smi_reader_->Close();

    free(_socket);

    return 0; }

    the code like this,

    when compile it also be error

    Tuesday, May 08, 2012 7:18 AM
  • Thanks. I can reproduce that in a basic sample, but it still compiles clean in the File Access sample.

    I'm not sure what is different. I suspect that we may be getting the IDataReader interface (which doesn't define Close) rather than the DataReader object (which defines IDataReader and IClosable), but I'm not sure why yet or why it doesn't occur in my other project.

    If you don't need the DataReader any longer you can delete it rather than calling Close() on it. C++ will deterministically destroy the object and automatically Close it when that occurs. In C# the Close/Dispose() call is more necessary because the object will live until it gets garbage collected.

    --Rob

    • Marked as answer by oishixixi Wednesday, May 09, 2012 3:11 AM
    Wednesday, May 09, 2012 12:46 AM
    Owner
  • Thank you,Rob

    The MSDN library point out that Streamsocket.Close()

    The Close is used by Metro style apps written in JavaScript. For apps written using the .NET Framework 4.5 in C# and VB.NET, the Close method is exposed as the Dispose() method on the StreamSocket. For apps written in C++, the Close method will be called when using the delete keyword on the object.

    but DataReader.Close() or DataWriter.Close() isn't described like that, so I thougnt that if I want to Closes the current stream and releases system resources ,I should call DataReader.Close() or DataWriter.Close() before delete it.

    Now, got it,Thanks

    Wednesday, May 09, 2012 3:11 AM