2017-11-14 2 views
0

winapi에서 나머지 sdk를 사용하여 웹과 통신하는 프로그램을 만듭니다.restapdk를 사용하여 winapi에서 오류

콘솔 프로그램 에서 실행되지만 winapi에서 오류가 발생합니다.

비동기 메서드를 사용할 때도 같은 오류가 발생합니다.

비슷한 문제가있는 찾으 실지 모르지만 찾을 수 없습니다.

winapi에서 restsdk를 사용할 때 오류의 예가 충분하지 않습니다. 액세스 위반을 읽어

는 나에게 'xutility'파일에서

#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... 
} 

, 던져

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입니다.

Error Image Capture

+1

정확히 오류가 무엇입니까 : 로컬 변수로 request에 의해 반환 된 작업을 저장

시도? –

+0

오류 내용을 추가했습니다. – POW

+0

액세스 위반은 사용자가 읽지 않거나 쓰지 않아야한다는 것을 의미합니다. 이와 같은 오류가 발생할 때마다 디버거에서 코드를 실행하여 오류가 발생한 위치를 정확히 확인해야합니다. –

답변

0

난 단지 request에 의해 반환 된 개체가 즉시 파괴되는 것을 추측하고있어 그리고 당신은 파괴 된 객체에 get를 호출합니다.

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

답변 해 주셔서 감사합니다. 그러나 같은 오류가 발생합니다. 콘솔에서 처음에는 아무 것도 잘못되었습니다. – POW

관련 문제