問題GetLastError API windows7
-
21-09-2019 - |
質問
ませていただきました。用すると、サーバーにコピーします。場合はサーバがダウンして、それによっ ERROR_WINHTTP_CANNOT_CONNECT
を使用してい getLastError()
取得するためのAPIこのエラーコードを扱っているこのエラーコード表示の適切なエラーメッセージのユーザーこのプログラムの動作はWindows2003年.きっとWindows7ません断エラー getLastError()
APIは0を返します毎時の場合でもエラーが発生しました。私はC++のプログラミング言語である。
かまいません。
Santhu
解決 2
いるの異なる挙動GetLastError API Windows2003、Windows7です。以下が私の観察内容
Windows2003年
例コード:
WinHttpOpen ()
–が完了した
Winhttpconnect()
–このAPIは失敗により何らかの理由というエラーコード12029
GetLastErrorCode()
–エラーコードを返します12029として期待
WinHttpCloseHandle(hOpen)
; 閉ハンドルを取りHttpOpenを完了successfilly
GetLastErrorCode()
–エラーコードを返します12029
Windows7
例コード:
WinHttpOpen ()
–が完了した
Winhttpconnect()
–このAPIは失敗により何らかの理由というエラーコード12029
GetLastErrorCode()
–エラーコードを返します12029として期待
WinHttpCloseHandle(hOpen);
閉ハンドルを取りHttpOpenを完了し
GetLastErrorCode()
–返すエラーコード0// の比較動画をご覧くださいWindows2003、windows2003年にこのAPIを返します最後のエラーが1209
他のヒント
、エラーコードが0にリセットされますすることができます。
あなたはそれ以降)の直後に障害が発生した後にGetLastError()を呼び出し、むしろ待つし、GetLastError(コールしようとしているよりも、その値を保存する必要があります。
この行動上のMicrosoftからの回答
The rules for GetLastError are:
• If the WinHttp API returns error (for example WinHttpIsHostInProxyBypassList, http://msdn.microsoft.com/en-us/library/ee861268(VS.85).aspx) this is the error and GetLastError should *NOT* be called.
o If GetLastError() is called, regardless of the success or failure of the API, the returned value is unpredictable and may change between Windows versions, Service Packs, or even between runs.
• If the WinHttp API returns BOOL (for example WinHttpSetTimeouts, http://msdn.microsoft.com/en-us/library/aa384116(VS.85).aspx), it indicates failure by returning FALSE. If the caller is interested in the detailed error, (s)he should call GetLastError(). Note that GetLastError should be called *if and only if* the API failed.
o If GetLastError() is called when the API succeded (returned anything but FALSE), the returned value is unpredictable and may change between Windows versions, Service Packs, or even between runs.
• If the WinHttp API returns HINTERNET (pseudo handle) the rules are exactly the same, except failure is indicated by returning NULL.
o If GetLastError() is called when the API succeded (returned anything but NULL), the returned value is unpredictable and may change between Windows versions, Service Packs, or even between runs.