{"id":100105,"date":"2018-11-01T07:00:00","date_gmt":"2018-11-01T21:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/?p=100105"},"modified":"2019-03-13T00:13:40","modified_gmt":"2019-03-13T07:13:40","slug":"20181101-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20181101-00\/?p=100105","title":{"rendered":"If the prototypes of DispatchMessageA and DispatchMessageW are identical, why have both?"},"content":{"rendered":"<p>There are a number of functions, mostly in the window manager, which have both ANSI and Unicode variants, even though the prototypes are identical. <\/p>\n<pre>\nLRESULT WINAPI DispatchMessageW(const MSG*);\nLRESULT WINAPI DispatchMessageA(const MSG*);\n\nBOOL WINAPI TranslateMessageW(const MSG*);\nBOOL WINAPI TranslateMessageA(const MSG*);\n\nint WINAPI TranslateAcceleratorW(HWND, HACCEL, LPMSG);\nint WINAPI TranslateAcceleratorA(HWND, HACCEL, LPMSG);\n\nHACCEL WINAPI CreateAcceleratorTableW(LPACCEL, int);\nHACCEL WINAPI CreateAcceleratorTableA(LPACCEL, int);\n<\/pre>\n<p>Why can&#8217;t these pairs of functions be combined into a single function? Clearly there&#8217;s no <code>CHAR<\/code>\/<code>WCHAR<\/code> mismatch, seeing as the parameters are identical. <\/p>\n<p>While it&#8217;s true that there is no type mismatch, there is still a character set dependency. <\/p>\n<p>For the <code>MSG<\/code>-based functions, the system needs to know whether the message was obtained via <code>Get&shy;MessageW<\/code>\/<code>Peek&shy;MessageW<\/code> or via <code>Get&shy;MessageA<\/code>\/<code>Peek&shy;MessageA<\/code>. If the message is <code>WM_<code><\/code>CHAR<\/code>, then the meaning of the <code>WPARAM<\/code> changes depending on the character set of the function that obtained the <code>MSG<\/code>. If you used <code>Get&shy;MessageW<\/code>\/<code>Peek&shy;MessageW<\/code>, then the <code>WPARAM<\/code> is a Unicode code unit, but if you used <code>Get&shy;MessageA<\/code>\/<code>Peek&shy;MessageA<\/code>, then it&#8217;s an ANSI code unit. <\/p>\n<p>The case of <code>Create&shy;Accelerator&shy;Table<\/code> is more subtle. Even though the same <code>ACCEL<\/code> structure is used for both ANSI and Unicode, the meaning of one of the fields changes: <\/p>\n<pre>\ntypedef struct tagACCEL {\n  BYTE fVirt;\n  WORD key;\n  WORD cmd;\n} ACCEL, *LPACCEL;\n<\/pre>\n<p>If the <code>FVIRTKEY<\/code> flag is not set in the <code>fVirt<\/code> member, then the <code>key<\/code> member <a HREF=\"https:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/ms646340(v=vs.85).aspx\">contains a character code<\/a>, and that&#8217;s the place where a character set dependency sneaks in. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Because there&#8217;s still a character set dependency.<\/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-100105","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Because there&#8217;s still a character set dependency.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/100105","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=100105"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/100105\/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=100105"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=100105"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=100105"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}