Why does GetWindowText hang with a “closed” handle but not with a random one

前端 未结 2 798
旧巷少年郎
旧巷少年郎 2020-12-21 01:12

Using the following code

    [DllImport(\"user32.dll\", EntryPoint = \"GetWindowText\", ExactSpelling = false, CharSet = CharSet.Auto, SetLastError = true)]
         


        
2条回答
  •  青春惊慌失措
    2020-12-21 01:27

    It's impossible to answer this question in any meaningful way. The Win32 interface makes no guarantees about what happens when you pass invalid window handles to routines. It is an error to do so. Please refrain.

    Having said all that, passing title.Capacity + 1 to GetWindowText is an error even with a valid window handle.

提交回复
热议问题