{"id":17433,"date":"2009-07-20T10:00:00","date_gmt":"2009-07-20T10:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2009\/07\/20\/why-was-moveto-replaced-with-movetoex\/"},"modified":"2009-07-20T10:00:00","modified_gmt":"2009-07-20T10:00:00","slug":"why-was-moveto-replaced-with-movetoex","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20090720-00\/?p=17433","title":{"rendered":"Why was MoveTo replaced with MoveToEx?"},"content":{"rendered":"<p>\nCommenter Ulric asks,\n&#8220;<a HREF=\"http:\/\/blogs.msdn.com\/oldnewthing\/pages\/407234.aspx#619634\">Where did MoveTo(HDC, int, int) go?<\/a>&#8221;\n<\/p>\n<p>\nBack in the 16-bit days, the function to move the current point\nwas called <code>MoveTo<\/code>,\nand its return value was a <code>DWORD<\/code> which encoded the\nprevious position,\npacking two 16-bit coordinates into a single 32-bit value.\nAs part of the transition to 32-bit Windows,\nGDI switched to using 32-bit coordinates instead of the\nwimpy 16-bit coordinates of old.\nAs a result, it was no longer possible to encode the original\nposition in a single <code>DWORD<\/code>.\nSomething new had to be developed.\n<\/p>\n<p>\nThat new thing was the <code>MoveToEx<\/code> function.\nInstead of returning a single <code>DWORD<\/code>,\nit accepted a final parameter which\nreceived the previous coordinates.\nIf you didn&#8217;t care about the previous coordinates,\nyou could just pass <code>NULL<\/code>.\nAll of the GDI functions which used to pack two 16-bit coordinates\ninto a single <code>DWORD<\/code>\ngot <code>Ex<\/code>-ified in this way so they could accommodate\nthe new 32-bit coordinate system.\n<\/p>\n<p>\nBut why did the old <code>MoveTo<\/cODE> function go away?\nWhy not keep it around for source code compatibility?\n<\/p>\n<p>\nI find this an interesting question,\nsince most people seem to think that maintaining source code\ncompability between the 32-bit and 64-bit versions of Windows\nwas an idea whose\n<a HREF=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2005\/01\/31\/363790.aspx\">\nstupidity<\/a>\nrivals\nprosecuting a land war in Asia.\n(If we had followed this advice,\npeople would just be asking,\n<a HREF=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2008\/12\/08\/9182990.aspx#9191060\">\nwhy did you replace <code>WinExec<\/code> with the much harder-to-use\n<code>CreateProcess<\/code><\/a>?)\nBy the same logic, source code compatibility between 16-bit and 32-bit\nWindows is equally absurd.\nAccording to these people,\nporting 16-bit code to\nto 32-bit Windows is the <i>best time<\/i> to introduce\nthese sorts of incompatibilities,\nin order to force people to rewrite their programs.\n<\/p>\n<p>\nAnyway, the reason we lost <code>MoveTo<\/code> was that there\nwas no way to return 64&nbsp;bits of information in a 32-bit integer.\nNow it's true that in many cases, the caller doesn't actually care\nabout the previous position,\nbut of course the <code>MoveTo<\/code> function doesn't know that.\nIt returns a value; it doesn't know whether the caller is going to\nuse that return value or not.\n<\/p>\n<p>\nI guess one way out would have been to change the return value of\n<code>MoveTo<\/code> to <code>void<\/code>.\nThat way, people who didn't care about the return value would still\ncompile, while people who did try to use the return value\nwould get a compile error and have to switch to <code>MoveToEx<\/code>.\n<\/p>\n<p>\nYeah, I guess that could've been done,\nbut you could also have done that yourself:\n<\/p>\n<pre>\n#define MoveTo(hdc, x, y) ((void)MoveToEx(hdc, x, y, NULL))\n<\/pre>\n<p>\nI find it interesting that most people who write their own\n<code>MoveTo<\/code> macro don't use the <code>(void)<\/code> cast.\nIn most cases, this is a mistake in porting from 16-bit Windows.\n(I can tell because the macro is mixed in with a bunch of other\nporting macros.)\nHowever, in other cases, it could be intentional.\nThe authors of the macro may simply not have known about the old\n16-bit days and simply expected their macro to be used as if it\nwere prototyped as\n<code>BOOL MoveTo(HDC, int, int)<\/code>.\n<\/p>\n<p>\nThese people will probably be baffled if they run across any\nactual 16-bit Windows code that tried to extract the high word\nfrom the return value of <code>MoveTo<\/code>.\n\"Why are you extracting the high word from a <code>BOOL<\/code>?\"\n<\/p>\n<p>\n<b>Historical exercise<\/b>:\nInstead of adding a new parameter, why not just make\n<code>MoveToEx<\/code> return an <code>__int64<\/code>?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Commenter Ulric asks, &#8220;Where did MoveTo(HDC, int, int) go?&#8221; Back in the 16-bit days, the function to move the current point was called MoveTo, and its return value was a DWORD which encoded the previous position, packing two 16-bit coordinates into a single 32-bit value. As part of the transition to 32-bit Windows, GDI switched [&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":[2],"class_list":["post-17433","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-history"],"acf":[],"blog_post_summary":"<p>Commenter Ulric asks, &#8220;Where did MoveTo(HDC, int, int) go?&#8221; Back in the 16-bit days, the function to move the current point was called MoveTo, and its return value was a DWORD which encoded the previous position, packing two 16-bit coordinates into a single 32-bit value. As part of the transition to 32-bit Windows, GDI switched [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/17433","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=17433"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/17433\/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=17433"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=17433"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=17433"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}