GitHub #2476 APIが正常値の戻り値0を返すとき最新のエラー情報をクリアしない#2490
Closed
uzanka wants to merge 1 commit into
Closed
Conversation
|
berryzplus
reviewed
Jun 16, 2026
berryzplus
left a comment
Contributor
There was a problem hiding this comment.
GetLastErrorする必要性に疑問があるので、修正に消極的です。
GetWindowTextを呼ぶ目的:
「ウィンドウに設定されているテキスト」を取得したい。
期待する結果:
「ウィンドウに設定されているテキスト」が取得される。
取得した値をどう使うか(≒取得した値がおかしかった場合にどう報告するか)を考えると「値を取得できませんでした。」でなく「入力値が空です。」になる気がします。
文字列長がWindowsのエラーで取れなかった場合とテキスト未入力で取れなかった場合を区別する必要があるかどうか。自分は「その必要はない」ように思ってます。
あと、SetLastErrorはグローバルなAPIエラー状態を更新してしまうので、直し方としてあまり良くない気がしています。ウィンドウのテキスト取得が「グローバルなAPIエラー状態に依存する処理である」とは思えないので。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



PR対象
カテゴリ
PR の背景
#2476
仕様・動作説明
空文字列が設定されているテキストボックスの文字列をApiWrap::Wnd_GetText()で取得したとき、
正常値としての戻り値0とエラーとしての戻り値0の区別をするためにGetLastError()でエラー判定しているが、
GetWindowTextLength()関数はエラーが発生しない場合に最新のエラー情報をクリアしない。
本関数を呼び出す前にSetLastErrorでクリアすることで、エラー判定を正常に動作するようにする。
PR の影響範囲
GetWindowTextLength()関数がエラーとなるのは主にウインドウハンドルが不正(NULL)な場合であるため、
サクラエディタのソースでは問題となるルートには入らないと予想される。
テスト内容
関連 issue, PR
参考資料
GetWindowTextLength
https://learn.microsoft.com/ja-jp/windows/win32/api/winuser/nf-winuser-getwindowtextlengthw