{"id":43243,"date":"2015-01-01T07:00:00","date_gmt":"2015-01-01T22:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2015\/01\/01\/horrifically-nasty-gotcha-findresource-and-findresourceex\/"},"modified":"2019-03-13T12:11:40","modified_gmt":"2019-03-13T19:11:40","slug":"20150101-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20150101-00\/?p=43243","title":{"rendered":"Horrifically nasty gotcha: FindResource and FindResourceEx"},"content":{"rendered":"<p>The <code>Find&shy;Resource&shy;Ex<\/code> function is an extension of the <code>Find&shy;Resource<\/code> function in that it allows you to specify a particular language fork in which to search for the resource. Calilng the <code>Find&shy;Resource<\/code> function is equivalent to calling <code>Find&shy;Resource&shy;Ex<\/code> and passing zero as the <code>wLanguage<\/code>. <\/p>\n<p>Except for the horrible nasty gotcha: The second and third parameters to <code>Find&shy;Resource&shy;Ex<\/code> are in the opposite order compared to the second and third parameters to <code>Find&shy;Resource<\/code>! <\/p>\n<p>In other words, if you are adding custom language support to a program, you cannot just stick a <code>wLanguage<\/code> parameter on the end when you switch from <code>Find&shy;Resource<\/code> to <code>Find&shy;Resource&shy;Ex<\/code>. You also have to flip the second and third parameters. <\/p>\n<table BORDER=\"0\" CELLPADDING=\"2\">\n<tr>\n<td>Original code<\/td>\n<td>    <code>Find&shy;Resource(hModule,     MAKEINTRESOURCE(IDB_MYBITMAP),     RT_BITMAP)<\/code> <\/td>\n<\/tr>\n<tr>\n<td>You change it to<\/td>\n<td>    <code>Find&shy;Resource&shy;<span STYLE=\"border: solid 1px black\">Ex<\/span>(hModule,     MAKEINTRESOURCE(IDB_MYBITMAP),     RT_BITMAP,     <span STYLE=\"border: solid 1px black\">0<\/span>)<\/code> <\/td>\n<\/tr>\n<tr>\n<td>You should have changed it to<\/td>\n<td>    <code>Find&shy;Resource&shy;<span STYLE=\"border: solid 1px black\">Ex<\/span>(hModule,     <span STYLE=\"border: solid 1px black\">    RT_BITMAP<\/span>,     <span STYLE=\"border: solid 1px black\">    MAKEINTRESOURCE(IDB_MYBITMAP)<\/span>,     <span STYLE=\"border: solid 1px black\">0<\/span>)<\/code> <\/td>\n<\/tr>\n<\/table>\n<p>The nasty part of this is that since the second and third parameters are the same type, the compiler won&#8217;t notice that you got them backward. The only way you find out is that your resource code suddenly stopped working. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>The old switcheroo.<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-43243","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>The old switcheroo.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/43243","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=43243"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/43243\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=43243"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=43243"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=43243"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}