{"id":3123,"date":"2013-09-25T07:00:00","date_gmt":"2013-09-25T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2013\/09\/25\/how-can-i-tell-that-somebody-used-the-makeintresource-macro-to-smuggle-an-integer-inside-a-pointer\/"},"modified":"2013-09-25T07:00:00","modified_gmt":"2013-09-25T07:00:00","slug":"how-can-i-tell-that-somebody-used-the-makeintresource-macro-to-smuggle-an-integer-inside-a-pointer","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20130925-00\/?p=3123","title":{"rendered":"How can I tell that somebody used the MAKEINTRESOURCE macro to smuggle an integer inside a pointer?"},"content":{"rendered":"<p>Many functions and interfaces provide the option of passing either a string or an integer. The parameter is formally declared as a string, and if you want to pass an integer, you smuggle the integer inside a pointer by using the <code>MAKE&shy;INT&shy;RESOURCE<\/code> macro. For example, the <code>Find&shy;Resource<\/code> function lets you load an resource specified by integer identifier by passing the identifier in the form <code>MAKE&shy;INT&shy;RESOURCE(ID)<\/code>. You can tell that it was the resource-loading functions who created the macro in the first place, since the name of the macro is &#8220;make integer <i>resource<\/i>.&#8221;\n But other functions use the <code>MAKE&shy;INT&shy;RESOURCE<\/code> convention, too. The <code>Get&shy;Proc&shy;Address<\/code> function  lets you obtain a function exported by ordinal if you smuggle the ordinal inside a pointer: <code>Get&shy;Proc&shy;Address(hModule, MAKE&shy;INT&shy;RESOURCEA(ordinal))<\/code>. (You have to use <code>MAKE&shy;INT&shy;RESOURCEA<\/code> because  <code>Get&shy;Proc&shy;Address<\/code> explicitly takes an ANSI string.)\n What if you&#8217;re implementing a function whose interface requires you to accept both strings and integers-smuggled-inside strings? For example, maybe you&#8217;re implementing <code>IContext&shy;Menu::Invoke&shy;Command<\/code>, which needs to look at the <code>CM&shy;INVOKE&shy;COMMAND&shy;INFO.lpVerb<\/code> member and determine whether the invoker passed a string or a menu offset.\n You can use the <code>IS_INT&shy;RESOURCE<\/code> macro. It will return non-<code>FALSE<\/code> if the pointer you passed is really an integer smuggled inside a pointer.<\/p>\n<p> How does <code>MAKE&shy;INT&shy;RESOURCE<\/code> work? It just stashes the integer in the bottom 16 bits of a pointer, leaving the upper bits zero. This relies on the convention that the first 64<a href=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2009\/06\/11\/9725386.aspx\">KB<\/a> of address space is never mapped to valid memory, a convention that is enforced starting in Windows&nbsp;7. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Many functions and interfaces provide the option of passing either a string or an integer. The parameter is formally declared as a string, and if you want to pass an integer, you smuggle the integer inside a pointer by using the MAKE&shy;INT&shy;RESOURCE macro. For example, the Find&shy;Resource function lets you load an resource specified by [&hellip;]<\/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-3123","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Many functions and interfaces provide the option of passing either a string or an integer. The parameter is formally declared as a string, and if you want to pass an integer, you smuggle the integer inside a pointer by using the MAKE&shy;INT&shy;RESOURCE macro. For example, the Find&shy;Resource function lets you load an resource specified by [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/3123","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=3123"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/3123\/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=3123"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=3123"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=3123"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}