Read and write ini files in VB6 using Windows API functions

zhaozj2021-02-11  176

Read and write ini files in VB6 using Windows API functions

Wininet (Win32 Internet Functions) is provided to a complete set of Internet call functions, which is included in a dynamic link library called Wininet.dll. It can easily complete access to HTTP, FTP, and Gopher through it. For example, download the HTML page; send FTP requests to upload or download files can also browse the directory list, typical applications are available by anonymous logging in to obtain files, and you update your home page to upload files; Gopher's menu system allows you to get The resources on the Internet. For these three protocols, the steps of using them are the same: establishing a join - request a request to the server - close contact. Of course, you can use Wininet to use Wininet more simple (even fool) through the MFC (Microsoft Foundation Class). Because in MFC, you can access HTTP, FTP, and Gopher servers simply like accessing the hard drive (of course, not to refer to the doodle ...); you can ignore Winsock and TCP / IP; of course you have complete May write from the bottom, I think one of the obvious reasons is that you think that MFC is not fast enough, rest assured comrades, this is not writing 3D games ... But if you think it is not flexible enough, then you write, nothing big deal And you can control your data with the chttpfile, cgopherfilefind, because these classes abstract the three protocols to the high-level application programming interface, providing fast and simple ways. So for you to use Visual C , you have at least two ways to use Wininet: Call the Win32 Internet functions and MFC directly. Below, use these two methods to download the web page via HTTP, in order to explain more clearly, assuming that the network is unobstructed, so you will see the following code is not error or exception handling. Prepare a single document interface automatic generation project, its viewing base class is preferably CEDITVIEW, so you can display the obtained information directly; add a toolbar icon, and messages on your message onGethTTP (). Firstly, the default page under http://www.hust.edu.cn is downloaded directly, the following functions will be used: AFXPARSEURL (or its extension AFXPARSEURLEX), Internetopen, InternetConnect, httpopenRequest, httpsendrequest , InternetReadFile, InternetCloseHandle. Don't say more, you can also guess their features from their names, function description, please refer to MSDN.

void CWinInetTestView :: OnGethttp () {// get the page using Win32API CString strURL = "http://www.hust.edu.cn"; HINTERNET hSession; HINTERNET hConnect = NULL; HINTERNET hURL = NULL; try {CString strServer, strObject Internet_port nport; DWORD DWSERVICEPE; // Analyze a given URL, retrieve service information AFXPARSEURL (Strull, DWServiceType, strserver, strobject, nport); // Initialize network dynamic link library, usually users only need to call Internetopen, // But multiple calls Internetopen is allowed, // For example, if you need to provide different proxy servers hsession = :: Internet Open ("Wininet Test", Inter-Net_Open-Type-Preconfig, (LPCTSTSTSTSTSTSTSTSTSTSTSTS) NULL, NULL, 0 ); // Database & Sign In Internet Connect (h session, strserver, inter-net-invalid-port-number, ",", ",", ",,,,,,,,,,,,,,,,, 2] = {_T ("Accept: Text / * / R"), null}; // Get the specified HTTP handle HURL = :: httpopenRequest (httpopenrequest (httpopenrequest (httpopenRequest, strobject, http_version, null, lpszaccepttypes, internet-flag -Existing-connection | inter-net-flag-no_auto-redirect | Internet-flag-dont-cache | Internet-flag-reload, 0); // Send a request to the HTTP server :: HttpsendRequest (HURL, NULL , 0, 0, 0); CString Stext; Tchar SZ [1024]; DWORD DWBYTESREAD; BOOL BOKAY = true; // Cycle Receive while (bokay) {bokay = :: InternetReadFile (HURL, SZ, 1023, & DWBYTESREAD); IF (Bokay && DwbytesRead> 0) {SZ [dwbytesread-1] = '/ 0'; Stext = SZ; Stext.Replace (_T ("/ n"), _t ("/ r / n")); getEditctrl () .Replacesel (stext);} else break;}} catch (...) {} // Close relevant handle :: InternetCloseHandle (HURL); :: InternetCloseHandle (HConnect); :: InternetCloseHandle (hsession);} The following uses MFC to complete The same work,

转载请注明原文地址:https://www.9cbs.com/read-5489.html

New Post(0)