簡體   English   中英

在winapi中,使用restsdk時出錯

[英]In winapi, using restsdk, error

在winapi中,創建一個使用其余sdk與網絡通信的程序。

它在控制台程序中運行,但在winapi中會生成錯誤。

使用異步方法時,會發生相同的錯誤。

我尋找了類似的問題,但找不到它們。

在winapi中使用restsdk時,沒有足夠的錯誤示例。

請幫我

#include "stdafx.h"

#include <CommCtrl.h>


#include <cpprest\http_client.h>
#include <iostream>
#include <cpprest\json.h>

#include <vector>
#include <iterator>

using namespace web;
using namespace web::http;
using namespace web::http::client;

using namespace std;

using namespace utility;
using namespace concurrency::streams;


void GetHttp2();

int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
    _In_opt_ HINSTANCE hPrevInstance,
    _In_ LPWSTR    lpCmdLine,
    _In_ int       nCmdShow);


LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{

    switch (message)
    {
    case WM_CREATE:


        break;

    case WM_COMMAND:
    {
        int wmId = LOWORD(wParam);
        switch (wmId)
        {
        case IDM_ABOUT:
            DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
            break;
        case IDM_EXIT:
            DestroyWindow(hWnd);
            break;



        case IDC_ADD_BTN: // button clicked

            GetHttp2();
            break;



        default:
            return DefWindowProc(hWnd, message, wParam, lParam);
        }
    }
    break;
    case WM_PAINT:
    {
        PAINTSTRUCT ps;
        HDC hdc = BeginPaint(hWnd, &ps);
        EndPaint(hWnd, &ps);
    }
    break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;


    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
}


void GetHttp2()
{
    http_client client(U("http://en.cppreference.com/w/"));
    auto resp = client.request(U("GET")).get(); // error point, xutiliy error...
}

在“ xutility”文件中,

inline void _Container_base12::_Orphan_all() _NOEXCEPT
{   // orphan all iterators
#if _ITERATOR_DEBUG_LEVEL == 2
    if (_Myproxy != 0)
    {   // proxy allocated, drain it
        _Lockit _Lock(_LOCK_DEBUG);

        for (_Iterator_base12 **_Pnext = &_Myproxy->_Myfirstiter;
            *_Pnext != 0; *_Pnext = (*_Pnext)->_Mynextiter)  /// error point
            (*_Pnext)->_Myproxy = 0;
        _Myproxy->_Myfirstiter = 0;
    }
#endif /* _ITERATOR_DEBUG_LEVEL == 2 */
}

引發異常:讀取訪問沖突。 _Pnext為0xCDCDCDD1。

錯誤圖像捕獲

我只是在猜測request返回的對象會立即被銷毀,然后在被銷毀的對象上調用get

嘗試將request返回的任務存儲為局部變量:

void GetHttp2()
{
    http_client client(U("http://en.cppreference.com/w/"));
    auto task = client.request(U("GET")); 
    auto resp = task.get(); 
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM