1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
#include "stdafx.h"
#include <string>
#include "test2.cpp"
#include <httprequest.h>
#define _ATL_ATTRIBUTES 1
#include <atlbase.h>
#include <atlcom.h>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
IWinHttpRequest* pIWhttp;
IUnknown* pIu;
HRESULT hr;
BSTR bstrResponse = NULL;
VARIANT varFalse;
VARIANT varEmpty;
VariantInit(&varFalse);
V_VT(&varFalse) = VT_BOOL;
V_BOOL(&varFalse) = VARIANT_FALSE;
VariantInit(&varEmpty);
V_VT(&varEmpty) = VT_ERROR;
CoInitialize(NULL);
hr = CoCreateInstance(CLSID_WinHttpRequest,NULL,CLSCTX_INPROC_SERVER,IID_IWinHttpRequest,(LPVOID*)&pIWhttp);
pIWhttp->QueryInterface(IID_IUnknown,(LPVOID*)&pIu);
Rep r;
r.StartHook(pIu);
BSTR bstrMethod = SysAllocString(L"GET");
BSTR bstrUrl = SysAllocString(L"http://www.google.com");
// Create an HTTP request.
hr = pIWhttp->Open(bstrMethod,bstrUrl,varFalse);
// Send the HTTP request.
hr = pIWhttp->Send(varEmpty);
// Retrieve the response text.
hr = pIWhttp->get_ResponseText(&bstrResponse);
//WCHAR* blabla(Test::RecorderDrive());
//printf("test");
return 0;
}
[event_receiver(com,false)]
class Rep
{
public:
void OnResponseFinished()
{
//rien
}
void StartHook(IUnknown* pIu)
{
__hook(&IWinHttpRequestEvents::OnResponseFinished,pIu,&Rep::OnResponseFinished);
}
}; |
Partager