20#pragma comment(lib,"Wininet.lib")
32 struct TPhInternetCloseHandle
34 void operator()(HINTERNET P) { ::InternetCloseHandle(P); }
94 m_handle = other.m_handle;
115 return ! m_handle.
IsNull();
134 bool Open(LPCTSTR lpszAgent, DWORD dwAccessType, LPCTSTR lpszProxy = NULL,
135 LPCTSTR lpszProxyBypass = NULL, DWORD dwFlags = 0)
137 m_handle = ::InternetOpen(lpszAgent, dwAccessType, lpszProxy, lpszProxyBypass, dwFlags);
138 return ! m_handle.
IsNull();
163 LPCTSTR lpszPassword, DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext = 0)
165 return ::InternetConnect(m_handle, lpszServerName, tPort, lpszUserName, lpszPassword, dwService, dwFlags, dwContext);
184 CInternetHandle OpenUrl(LPCTSTR lpszUrl, LPCTSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext = 0)
186 return ::InternetOpenUrl(m_handle, lpszUrl, lpszHeaders, dwHeadersLength, dwFlags, dwContext);
206 return ::HttpOpenRequest(m_handle, lpszVerb, lpszObjectName, lpszVersion, lpszReferrer, NULL, dwFlags, dwContext);
229 loop ( i, acceptTypes )
233 a[acceptTypes.
GetSize()] = NULL;
234 return ::HttpOpenRequest(m_handle, lpszVerb, lpszObjectName, lpszVersion, lpszReferrer, a, dwFlags, dwContext);
246 bool HttpSendRequest(LPCTSTR lpszHeaders, DWORD dwHeadersLength, LPVOID lpOptional, DWORD dwOptionalLength)
248 return !!
::HttpSendRequest(m_handle, lpszHeaders, dwHeadersLength, lpOptional, dwOptionalLength);
260 bool HttpQueryInfo(DWORD dwInfoLevel, LPVOID lpBuffer, LPDWORD lpdwBufferLength, LPDWORD lpdwIndex)
262 return !!
::HttpQueryInfo(m_handle, dwInfoLevel, lpBuffer, lpdwBufferLength, lpdwIndex);
304 bool QueryOption(DWORD dwOption, LPVOID _lpBuffer, LPDWORD _lpdwBufferLength)
const
306 return !! ::InternetQueryOption(m_handle, dwOption, _lpBuffer, _lpdwBufferLength);
320 bool ReadFile(LPVOID _lpBuffer, DWORD dwNumberOfBytesToRead, LPDWORD _lpdwNumberOfBytesRead)
const
322 return !! ::InternetReadFile(m_handle, _lpBuffer, dwNumberOfBytesToRead, _lpdwNumberOfBytesRead);
340 DWORD
SetFilePointer(LONG lDistanceToMove, LONG* pReserved, DWORD dwMoveMethod, DWORD_PTR dwContext = 0)
const
342 return ::InternetSetFilePointer(m_handle, lDistanceToMove, pReserved, dwMoveMethod, dwContext);
371 bool SetOption(DWORD dwOption, LPVOID lpBuffer, DWORD dwBufferLength)
373 return !! ::InternetSetOption(m_handle, dwOption, lpBuffer, dwBufferLength);
387 return ::InternetSetStatusCallback(m_handle, pInetProc);
401 return !! ::InternetFindNextFile(m_handle, pFindData);
414 bool WriteFile(LPCVOID lpBuffer, DWORD dwNumberOfBytesToWrite, LPDWORD lpdwNumberOfBytesWritten)
416 return !! ::InternetWriteFile(m_handle, lpBuffer, dwNumberOfBytesToWrite, lpdwNumberOfBytesWritten);
429 return !! ::FtpCreateDirectory(m_handle, lpszDirName);
442 return !! ::FtpDeleteFile(m_handle, lpszFileName);
458 return ::FtpFindFirstFile(m_handle, lpszSearchFile, lpFindFileData, dwFlags, dwContext);
472 return !! ::FtpGetCurrentDirectory(m_handle, _lpszCurrentDirectory, _lpdwLength);
504 bool GetFile(LPCTSTR lpszRemoteFile, LPCTSTR lpszLocalFile, BOOL fFailIfExists,
505 DWORD dwFlagsAndAttributes, DWORD dwFlags, DWORD_PTR dwContext = 0)
const
507 return !! ::FtpGetFile(m_handle, lpszRemoteFile, lpszLocalFile, fFailIfExists, dwFlagsAndAttributes, dwFlags, dwContext);
519 typedef DWORD (WINAPI* P)(HINTERNET, LPDWORD);
522 return CDynamicFuncT<P>(
"Wininet.dll",
"FtpGetFileSize")()(m_handle, _lpdwFileSizeHigh);
526 ASSERT0(
false,
"CInternetHandle::GetFileSize()",
527 "API FtpGetFileSize()が見つかりません。\nWininet.dll が古い可能性があります。");
558 return ::FtpOpenFile(m_handle, lpszFileName, dwAccess, dwFlags, dwContext);
583 bool PutFile(LPCTSTR lpszLocalFile, LPCTSTR lpszNewRemoteFile, DWORD dwFlags, DWORD_PTR dwContext)
585 return !! ::FtpPutFile(m_handle, lpszLocalFile, lpszNewRemoteFile, dwFlags, dwContext);
598 return !! ::FtpRemoveDirectory(m_handle, lpszDirName);
610 bool RenameFile(LPCTSTR lpszOldFileName, LPCTSTR lpszNewFileName)
612 return !! ::FtpRenameFile(m_handle, lpszOldFileName, lpszNewFileName);
625 return !! ::FtpSetCurrentDirectory(m_handle, lpszDirName);
636 return ::InternetAttemptConnect(0) == ERROR_SUCCESS;
660 static bool CanonicalizeUrl(LPTSTR _lpszDstUrl, DWORD& _dwDstSize, LPCTSTR lpszUrl, DWORD dwFlags, LPCTSTR lpszRelativeUrl = NULL)
663 if ( lpszRelativeUrl == NULL )
665 boRc = ::InternetCanonicalizeUrl(lpszUrl, _lpszDstUrl, &_dwDstSize, dwFlags);
669 boRc = ::InternetCombineUrl(lpszUrl, lpszRelativeUrl, _lpszDstUrl, &_dwDstSize, dwFlags);
#define loop(VAR, CNT)
loop構文.
CInternetHandle Connect(LPCTSTR lpszServerName, INTERNET_PORT tPort, LPCTSTR lpszUserName, LPCTSTR lpszPassword, DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext=0)
[接続] 指定名サーバ接続.
bool GetFile(LPCTSTR lpszRemoteFile, LPCTSTR lpszLocalFile, BOOL fFailIfExists, DWORD dwFlagsAndAttributes, DWORD dwFlags, DWORD_PTR dwContext=0) const
[取得] ローカルへ読込み.
CInternetHandle OpenFile(LPCTSTR lpszFileName, DWORD dwAccess, DWORD dwFlags, DWORD_PTR dwContext=0)
[取得] ファイルオープン.
bool HttpQueryInfo(DWORD dwInfoLevel, LPVOID lpBuffer, LPDWORD lpdwBufferLength, LPDWORD lpdwIndex)
[取得] HTTPリクエストに関連する情報の取得.
CInternetHandle(HINTERNET h=NULL)
コンストラクタ
DWORD GetFileSize(LPDWORD _lpdwFileSizeHigh) const
[取得] ファイルサイズ取得.
CInternetHandle FindFirstFile(LPCTSTR lpszSearchFile, LPWIN32_FIND_DATA lpFindFileData, DWORD dwFlags, DWORD_PTR dwContext=0) const
[検索] 検索開始.
bool FindNextFile(LPVOID pFindData) const
[検索] 検索続行.
static bool CanonicalizeUrl(LPTSTR _lpszDstUrl, DWORD &_dwDstSize, LPCTSTR lpszUrl, DWORD dwFlags, LPCTSTR lpszRelativeUrl=NULL)
[変換] URL変換.
bool RenameFile(LPCTSTR lpszOldFileName, LPCTSTR lpszNewFileName)
[変更] 名前変更.
bool QueryOption(DWORD dwOption, LPVOID _lpBuffer, LPDWORD _lpdwBufferLength) const
[取得] オプション情報取得.
CInternetHandle HttpOpenRequest(LPCTSTR lpszVerb, LPCTSTR lpszObjectName, LPCTSTR lpszVersion, LPCTSTR lpszReferrer, DWORD dwFlags, DWORD_PTR dwContext=0)
[作成] HTTPリクエストの作成.
INTERNET_STATUS_CALLBACK SetStatusCallback(INTERNET_STATUS_CALLBACK pInetProc)
[設定] コールバック設定.
bool Open(LPCTSTR lpszAgent, DWORD dwAccessType, LPCTSTR lpszProxy=NULL, LPCTSTR lpszProxyBypass=NULL, DWORD dwFlags=0)
[設定] 初期化.
bool GetCurrentDirectory(LPTSTR _lpszCurrentDirectory, LPDWORD _lpdwLength) const
[取得] カレントディレクトリ取得.
CInternetHandle OpenUrl(LPCTSTR lpszUrl, LPCTSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext=0)
[接続] 指定URL接続.
bool SetCurrentDirectory(LPCTSTR lpszDirName)
[設定] カレントディレクトリ設定.
bool IsValid(void) const
[確認] ハンドル有効確認
static bool AttemptConnect(void)
[調査] インターネット利用可能調査.
bool ReadFile(LPVOID _lpBuffer, DWORD dwNumberOfBytesToRead, LPDWORD _lpdwNumberOfBytesRead) const
[取得] ファイル読み込み.
bool WriteFile(LPCVOID lpBuffer, DWORD dwNumberOfBytesToWrite, LPDWORD lpdwNumberOfBytesWritten)
[出力] ファイル書き込み.
bool SetOption(DWORD dwOption, LPVOID lpBuffer, DWORD dwBufferLength)
[設定] オプション情報設定
CInternetHandle & operator=(const CInternetHandle &other)
[代入] コピーオペレータ
bool CreateDirectory(LPCTSTR lpszDirName)
[作成] 指定ディレクトリ作成.
void Close(void)
[設定] クローズ.
bool HttpSendRequest(LPCTSTR lpszHeaders, DWORD dwHeadersLength, LPVOID lpOptional, DWORD dwOptionalLength)
[送信] HTTPリクエストを送信.
DWORD SetFilePointer(LONG lDistanceToMove, LONG *pReserved, DWORD dwMoveMethod, DWORD_PTR dwContext=0) const
[設定] ファイルポインタ設定.
CInternetHandle HttpOpenRequest(LPCTSTR lpszVerb, LPCTSTR lpszObjectName, LPCTSTR lpszVersion, LPCTSTR lpszReferrer, const CStrVector &acceptTypes, DWORD dwFlags, DWORD_PTR dwContext=0)
[作成] HTTPリクエストの作成.
bool PutFile(LPCTSTR lpszLocalFile, LPCTSTR lpszNewRemoteFile, DWORD dwFlags, DWORD_PTR dwContext)
[送信] ローカルからファイル送信.
CInternetHandle(const CInternetHandle &other)
コピーコンストラクタ
bool RemoveDirectory(LPCTSTR lpszDirName)
[削除] ディレクトリ削除.
bool DeleteFile(LPCTSTR lpszFileName)
[削除] 指定ファイル削除.
bool IsNull(void) const
[確認] NULLチェック
const TYP * ReferBuffer(void) const
[取得] バッファ参照.
void OnCatch(void) const
[表示] 内容表示
virtual size_t GetSize(void) const
[取得] サイズ取得
virtual const TYP * ReferBuffer(void) const
[取得] データアドレス取得
TNB::CPointerHandleBaseT< HINTERNET, TPhInternetCloseHandle > CInternetHandleHandle
HINTERNET型ハンドルハンドラ―クラス