locked
C++ REST SDK problem. argument of type "const wchar_t *" is incompatible with parameter of type "Windows::Storage::StorageFile ^"

    Question

  • Hi,
    I am getting an error trying to make the C++ REST SDK Http Client Tutorial work into an existing VS Express 2013 for Windows project.

    This is the link to the Tutorial:
    https://casablanca.codeplex.com/wikipage?title=Http%20Client%20Tutorial

    I got to make it work in VS Express 2013 for Desktop successfully, but not in VS Express 2013 for Windows.
    The OS is Windows 8.1 64bit.

    These are my unsuccessful steps to make it run in VS Express 2013 for Windows
    Open VS Express 2013 for Windows
    Select New Project, Installed, Templates, Visual C++, Store Apps, Windows Apps, Blank App (Windows).
    Name: App1.
    Click Ok.
    (I previously installed NuGet Package Manager)
    In the Tools menu, select NuGet Package Manager, Manage NuGet Packages for Solution...
    In the "ConsoleApplication1.sln - Manage NuGet Packages" dialog, search field type "casablanca".
    From the result list select "C++ REST SDK" and click the Install button.
    In the "Select Projects" dialog, all checkboxes are checked, click Ok.
    After installation finishes, click Close in the "ConsoleApplication1.sln - Manage NuGet Packages" dialog.
    Open MainPage.xaml.cpp.
    Add the code from the complete example into the MainPage.xaml.cpp in the following manner:
    o Add the following lines after the existing "#include" lines:
    #include <cpprest/http_client.h>
    #include <cpprest/filestream.h>
    o Add the following lines after the existing "using" lines:
    using namespace utility;
    using namespace web;
    using namespace web::http;
    using namespace web::http::client;
    using namespace concurrency::streams;
    o Add the following lines after "InitializeComponent();" inside the MainPage::MainPage() method:
    auto fileStream = std::make_shared<ostream>();

        // Open stream to output file.
        pplx::task<void> requestTask = fstream::open_ostream(U("results.html")).then([=](ostream outFile)
        {
            *fileStream = outFile;
            // Create http_client to send the request.
            http_client client(U("http://www.bing.com/"));
            // Build request URI and start the request.
            uri_builder builder(U("/search"));
            builder.append_query(U("q"), U("Casablanca CodePlex"));
            return client.request(methods::GET, builder.to_string());
        })
        // Handle response headers arriving.
        .then([=](http_response response)
        {
            printf("Received response status code:%u\n", response.status_code());
            // Write response body into the file.
            return response.body().read_to_end(fileStream->streambuf());
        })
        // Close the file stream.
        .then([=](size_t)
        {
            return fileStream->close();
        });
        // Wait for all the outstanding I/O to complete and handle any exceptions
        try
        {
            requestTask.wait();
        }
        catch (const std::exception &e)
        {
            printf("Error exception:%s\n", e.what());
        }

    The only error is in the line:
    pplx::task<void> requestTask = fstream::open_ostream(U("results.html")).then([=](ostream outFile)

    Where U is signaled with a red wiggle line and the tool tip says:
    Error: argument of type "const wchar_t*" is incompatible with parameter of type "Windows::Storage::StorageFile ^"

    In Error List shows:
    IntelliSense: argument of type "const wchar_t *" is incompatible with parameter of type "Windows::Storage::StorageFile ^".

    In other ocurrences of U, it is not marked as am error.

    How can I make it work in VS Express 2013 for Windows?

    These are the steps to make it run ok in VS Express 2013 for Desktop successfully:
    Open VS Express 2013 for Desktop.
    Select New Project, Installed, Templates, Visual C++, Win32 Console Application.
    Name: ConsoleApplication1.
    Click Ok.
    In Win32 Application Wizard dialog click Finish.
    (I previously installed NuGet Package Manager)
    In the Tools menu, select NuGet Package Manager, Manage NuGet Packages for Solution...
    In the "ConsoleApplication1.sln - Manage NuGet Packages" dialog, search field type "casablanca".
    From the result list select "C++ REST SDK" and click the Install button.
    In the "Select Projects" dialog, all checkboxes are checked, click Ok.
    After installation finishes, click Close in the "ConsoleApplication1.sln - Manage NuGet Packages" dialog.
    Replace the ConsoleApplication1.cpp contents by copy and paste the complete example from the Client Tutorial link above.
    Restore the following line inserting it as the first line of the code in the above file:
    #include "stdafx.h"
    Run
    The file results.html is successfully created in Projects\ConsoleApplication1\ConsoleApplication1.


    Tuesday, August 12, 2014 12:17 AM

Answers

  • Hi David,

    Your information is quite detail, but I found the line throw the exception contains  fstream::open_ostream(U("results.html")), which is not accepted in Windows Store App.

    In Windows Store App, when you need open a file, you should use StorageFile, and here is a tutorial: Quickstart: Accessing files programmatically

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Marked as answer by David Hernán Tuesday, August 12, 2014 6:15 PM
    Tuesday, August 12, 2014 2:51 AM
    Moderator

All replies

  • Hi David,

    Your information is quite detail, but I found the line throw the exception contains  fstream::open_ostream(U("results.html")), which is not accepted in Windows Store App.

    In Windows Store App, when you need open a file, you should use StorageFile, and here is a tutorial: Quickstart: Accessing files programmatically

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Marked as answer by David Hernán Tuesday, August 12, 2014 6:15 PM
    Tuesday, August 12, 2014 2:51 AM
    Moderator
  • Thank you Jamles, for orienting me towards StorageFile, I am looking for the steps to implement it, but the tutorial doesn't have any C++ examples to create and write to a file.

    http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh967755.aspx

    "No code example is currently available or this language may not be supported."

    I am looking for the way to make it work.

    David

    Tuesday, August 12, 2014 4:14 PM