{"id":116,"date":"2009-03-05T00:08:18","date_gmt":"2009-03-05T00:08:18","guid":{"rendered":"http:\/\/entrian.com\/blog\/?p=116"},"modified":"2021-07-15T08:29:33","modified_gmt":"2021-07-15T08:29:33","slug":"setting-a-visual-studio-breakpoint-on-a-win32-api-function-in-user32dll","status":"publish","type":"post","link":"https:\/\/entrian.com\/blog\/setting-a-visual-studio-breakpoint-on-a-win32-api-function-in-user32dll\/","title":{"rendered":"Setting a Visual Studio breakpoint on a Win32 API function in user32.dll"},"content":{"rendered":"<p>I recently had a problem with my Windows application causing the desktop icons to flicker.&nbsp; I knew that the <code>LockWindowUpdate<\/code> API could cause that, but I also knew I didn&#8217;t use it.&nbsp; Maybe one of the libraries I use (MFC?) was doing it.<\/p>\n<p>So I wanted to set a Visual Studio breakpoint on that API&#8217;s location.&nbsp; I tried<br \/>\n<code>{,,user32.dll}_LockWindowUpdate@4<\/code> but that didn&#8217;t work.&nbsp; I knew that <code>{,,user32.dll}_SendMessageA@16<\/code> works for setting a breakpoint on&nbsp;<code>SendMessage<\/code> (which is also in user32.dll), so why doesn&#8217;t the same thing work for <code>LockWindowUpdate<\/code>?<\/p>\n<p>It turns out that the function is called <code>NtUserLockWindowUpdate<\/code> as far as the debugger is concerned, so you need to use <code>{,,user32.dll}_NtUserLockWindowUpdate@4<\/code><\/p>\n<p>I don&#8217;t know which other APIs have that <code>NtUser<\/code> prefix, but I bet there are some.<\/p>\n<p>Interestingly, the exported symbol as reported by <a href=\"http:\/\/www.dependencywalker.com\/\">Dependency Walker<\/a> is called <code>LockWindowUpdate<\/code> &#8211; it&#8217;s only in the debug symbols that it&#8217;s <code>NtUserLockWindowUpdate<\/code>.&nbsp; I used Dependency Walker to find the symbol&#8217;s address: my breakpoint for <code>SendMessage<\/code> was at 7D94B5BA and Dependency Walker told me that its export address was 1b5ba.&nbsp; <code>LockWindowUpdate<\/code> was exported at 27d5c, so a quick bit of maths pointed me to 7D957D5C, and hence the real name of the function:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-118\" title=\"NtUserLockWindowUpdate\" src=\"https:\/\/entrian.com\/blog\/wp-content\/uploads\/2009\/02\/ntuserlockwindowupdate1.png\" alt=\"NtUserLockWindowUpdate\" width=\"350\" height=\"130\" srcset=\"https:\/\/entrian.com\/blog\/wp-content\/uploads\/2009\/02\/ntuserlockwindowupdate1.png 350w, https:\/\/entrian.com\/blog\/wp-content\/uploads\/2009\/02\/ntuserlockwindowupdate1-300x111.png 300w\" sizes=\"auto, (max-width: 350px) 100vw, 350px\" \/><\/p>\n<p>(By the way, Raymond Chen&#8217;s series of posts on <code>LockWindowUpdate<\/code> are required reading for anyone thinking of using it: <a href=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2007\/02\/19\/1716211.aspx\">What does LockWindowUpdate do?<\/a>)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to set a breakpoint in a user32.dll function when Microsoft&#8217;s debug symbols give it an unexpected name.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-116","post","type-post","status-publish","format-standard","hentry","category-30days"],"_links":{"self":[{"href":"https:\/\/entrian.com\/blog\/wp-json\/wp\/v2\/posts\/116","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/entrian.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/entrian.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/entrian.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/entrian.com\/blog\/wp-json\/wp\/v2\/comments?post=116"}],"version-history":[{"count":1,"href":"https:\/\/entrian.com\/blog\/wp-json\/wp\/v2\/posts\/116\/revisions"}],"predecessor-version":[{"id":1161,"href":"https:\/\/entrian.com\/blog\/wp-json\/wp\/v2\/posts\/116\/revisions\/1161"}],"wp:attachment":[{"href":"https:\/\/entrian.com\/blog\/wp-json\/wp\/v2\/media?parent=116"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/entrian.com\/blog\/wp-json\/wp\/v2\/categories?post=116"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/entrian.com\/blog\/wp-json\/wp\/v2\/tags?post=116"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}