⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jwininet.pas

📁 autoupdate 1.02 source code
💻 PAS
字号:
unit JWinInet;

interface

uses Windows, WinInet, SysUtils;

{
   JWinInet is a WinInet wrapper unit which loads the WININET.DLL at run time
   rather than at load time.  This means that an application can handle a
   missing DLL at runtime rather that the application loader.

   I have only abstracted the functions which I use.  To add more functions
   just copy the function definition out of wininet.pas and adapt it as I
   have done for the current function.

   You can still call the wininet functions directly but it will cause
   wininet.dll to be linked in again.  You can check what procedures are linked
   in by using the Depends tool which comes with VC++.

   The J is of course for John.
}

type TInternetOpenA = function (lpszAgent: PAnsiChar; dwAccessType: DWORD;
  lpszProxy, lpszProxyBypass: PAnsiChar; dwFlags: DWORD): HINTERNET; stdcall;

type TInternetConnectA = function (hInet: HINTERNET; lpszServerName: PAnsiChar;
  nServerPort: INTERNET_PORT; lpszUsername: PAnsiChar; lpszPassword: PAnsiChar;
  dwService: DWORD; dwFlags: DWORD; dwContext: DWORD): HINTERNET; stdcall;

type TInternetQueryOptionA = function(hInet: HINTERNET; dwOption: DWORD;
  lpBuffer: Pointer; var lpdwBufferLength: DWORD): BOOL; stdcall;

type TInternetSetOptionA = function (hInet: HINTERNET; dwOption: DWORD;
  lpBuffer: Pointer; dwBufferLength: DWORD): BOOL; stdcall;

type TInternetCloseHandle = function (hInet: HINTERNET): BOOL; stdcall;

type TInternetWriteFile = function (hFile: HINTERNET; lpBuffer: Pointer;
  dwNumberOfBytesToWrite: DWORD;
  var lpdwNumberOfBytesWritten: DWORD): BOOL; stdcall;

type TInternetReadFile = function (hFile: HINTERNET; lpBuffer: Pointer;
  dwNumberOfBytesToRead: DWORD; var lpdwNumberOfBytesRead: DWORD): BOOL; stdcall;

type THttpOpenRequestA = function (hConnect: HINTERNET; lpszVerb: PAnsiChar;
  lpszObjectName: PAnsiChar; lpszVersion: PAnsiChar; lpszReferrer: PAnsiChar;
  lplpszAcceptTypes: PLPSTR; dwFlags: DWORD;
  dwContext: DWORD): HINTERNET; stdcall;

type THttpSendRequestExA = function (hRequest: HINTERNET; lpBuffersIn: PInternetBuffers;
    lpBuffersOut: PInternetBuffers;
    dwFlags: DWORD; dwContext: DWORD): BOOL; stdcall;

type THttpEndRequestA = function (hRequest: HINTERNET;
  lpBuffersOut: PInternetBuffers; dwFlags: DWORD;
  dwContext: DWORD): BOOL; stdcall;

type THttpQueryInfoA = function (hRequest: HINTERNET; dwInfoLevel: DWORD;
  lpvBuffer: Pointer; var lpdwBufferLength: DWORD;
  var lpdwReserved: DWORD): BOOL; stdcall;



   const WININET_MODULE = 'Wininet.dll';
   procedure LoadWinINet;
var
   JInternetOpen : TInternetOpenA;
   JInternetConnect : TInternetConnectA;
   JInternetQueryOption : TInternetQueryOptionA;
   JInternetSetOption : TInternetSetOptionA;
   JInternetCloseHandle : TInternetCloseHandle;
   JInternetWriteFile : TInternetWriteFile;
   JInternetReadFile : TInternetReadFile;
   JHttpOpenRequest : THttpOpenRequestA;
   JHttpSendRequestEx : THttpSendRequestExA;
   JHttpEndRequest : THttpEndRequestA;
   JHttpQueryInfo : THttpQueryInfoA;

implementation
var
   WinINetLoaded : Boolean = False;

   
procedure LoadWinINet;
var
   hModule : hInst;
   Error : DWORD;

   function GetAddress(ProcName : PChar) : Pointer;
   begin
      Result := GetProcAddress(hModule, ProcName);
      if Result = nil then
      begin
         raise Exception.Create('Could not find procedure ' + ProcName);
      end;
   end;
begin
   if WinINetLoaded then exit;

   // Load WinINET...
   hModule := GetModuleHandle(WININET_MODULE);
   if hModule = 0 then
   begin
      // wininet is not yet loaded...
      hModule := LoadLibrary(WININET_MODULE);
      if hModule = 0 then
      begin
         Error := GetLastError;
         raise Exception.Create('Error loading Windows Internet Library.  ' + SysErrorMessage(Error));
      end;
   end;

   // by here we have an hModule or have raised an exception
   // Map the function addresses...
   JInternetOpen := GetAddress('InternetOpenA');
   JInternetConnect := GetAddress('InternetConnectA');
   JInternetQueryOption := GetAddress('InternetQueryOptionA');
   JInternetSetOption := GetAddress('InternetSetOptionA');
   JInternetCloseHandle := GetAddress('InternetCloseHandle');
   JInternetWriteFile := GetAddress('InternetWriteFile');
   JInternetReadFile := GetAddress('InternetReadFile');
   JHttpOpenRequest := GetAddress('HttpOpenRequestA');
   JHttpSendRequestEx := GetAddress('HttpSendRequestExA');
   JHttpEndRequest := GetAddress('HttpEndRequestA');
   JHttpQueryInfo := GetAddress('HttpQueryInfoA');

   WinINetLoaded := True;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -