VC + + Access to Web source

Source: Internet
Author: User

Using Iwinhttprequest to get the Web source

The first thing to do is to create a dialog-based MFC application,

2.import+ interface Mode

First import Winhttp.dll, use Iwinhttprequest interface

" C:\\windows\\system32\\winhttp.dll " void Chttptestdlg::onbnclickedbutton1 () {    //  Initialize COM component      *phttpreq = NULL ;}

The following error occurred in compiling:

In the debug directory of the project, generate two files: Winhttp.tlh and Winhttp.tli

View WINHTTP.TLH

Workaround:

1) using Namespaces WinHTTP

,

2) do not introduce namespaces when importing a dynamic library

Code:

#import"C:\\windows\\system32\\winhttp.dll"No_namespace//IID for IwinhttprequestConstIID iid_iwinhttprequest = {    0x06f29373,    0x5c5a,    0x4b54,    { 0xb0,0x25,0x6e,0xf1,0XBF,0x8a,0XBF,0x0e }};voidChttptestdlg::onbnclickedbutton1 () {HRESULT hr=NULL; HR=CoInitialize (NULL); Iwinhttprequest*phttpreq =NULL;    CLSID clsid; HR= CLSIDFromProgID (_t ("winhttp.winhttprequest.5.1"), &clsid); IID IID=__uuidof (iwinhttprequest); CLSID Tclsid=__uuidof (WinHttpRequest); HR= CoCreateInstance (CLSID, NULL, Clsctx_inproc_server, Iid_iwinhttprequest, (lpvoid*) &phttpreq); //hr = CoCreateInstance (__uuidof (WinHttpRequest), NULL, Clsctx_inproc_server, __uuidof (iwinhttprequest), (LPVOID*) &PHTTPREQ);    if(FAILED (HR)) {couninitialize (); return; } HR= Phttpreq->open (_t ("GET"), _t ("http://www.baidu.com"));//The default value is Vtmissing    if(FAILED (HR)) {Phttpreq-Release ();        CoUninitialize (); return; } HR= Phttpreq->send ();//The default value is Vtmissing    if(FAILED (HR)) {Phttpreq-Release ();        CoUninitialize (); return; } CString respstr= phttpreq->responsetext;     MessageBox (RESPSTR); Phttpreq-Release (); CoUninitialize ();} 

Note:

1, as long as the registered components can be found in the registry of its GUID, such as I now query the IID of the Iwinhttprequest interface, with Regworkshop This tool can be quickly searched.

2, so many ID does not remember, easy way is to use __uuidof ()

The __UUIDOF keyword is used to obtain the GUID of an expression. The expression can be a type name, a pointer, a reference, or an array of type, a template with this type instantiation, or a variable of this type.

This parameter is valid as long as the compiler can use the parameter to obtain the associated GUID. The special case of this parameter is when it takes 0 or null. In this case, __UUIDOF will return a GUID consisting of 0

,,

Use of ole/com software:

Download Oleviewer (I'm using v10.0)

Right-click Oleview.exe, run as Administrator

Select Menu "File", "View typelib" to open the corresponding file

Use Regworkshop to obtain the GUID of a registered COM component:

With Iwinhttprequest, open regworkshop, search iwinhttprequest

Open the corresponding registry:

Debug results:

VC + + Access to Web source

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.