<p>In the Windows applications I work on, we have a custom framework that sits directly above Win32 (don't ask).  When we create a window, our normal practice is to put <code>this</code> in the window's user data area via <code>SetWindowLong(hwnd, GWL_USERDATA, this)</code>, which allows us to have an MFC-like callback or a tightly integrated <code>WndProc</code>, depending.  The problem is that this will not work on 64-bit Windows, since LONG is only 32-bits wide.  What's a better solution to this problem that works on both 32- and 64-bit systems?</p>

[{'answer_id': 23101, 'author': 'Chris', 'author_id': 2134, 'author_profile': 'https://Stackoverflow.com/users/2134', 'pm_score': 6, 'selected': True, 'text': '<p><a href="http://msdn.microsoft.com/en-us/library/ms644898%28VS.85%29.aspx" rel="noreferrer">SetWindowLongPtr</a> was created to replace <a href="http://msdn.microsoft.com/en-us/library/ms633591%28VS.85%29.aspx" rel="noreferrer">SetWindowLong</a> in these instances.  It\'s LONG_PTR parameter allows you to store a pointer for 32-bit or 64-bit compilations.</p>\n\n<pre><code>LONG_PTR SetWindowLongPtr(      \n    HWND hWnd,\n    int nIndex,\n    LONG_PTR dwNewLong\n);\n</code></pre>\n\n<p>Remember that the constants have changed too, so usage now looks like:</p>\n\n<pre><code>SetWindowLongPtr(hWnd, GWLP_USERDATA, this);\n</code></pre>\n\n<p>Also don\'t forget that now to retrieve the pointer, you must use <a href="http://msdn.microsoft.com/en-us/library/ms633585%28VS.85%29.aspx" rel="noreferrer">GetWindowLongPtr</a>:</p>\n\n<pre><code>LONG_PTR GetWindowLongPtr(      \n    HWND hWnd,\n    int nIndex\n);\n</code></pre>\n\n<p>And usage would look like (again, with changed constants):</p>\n\n<pre><code>LONG_PTR lpUserData = GetWindowLongPtr(hWnd, GWLP_USERDATA);\nMyObject* pMyObject = (MyObject*)lpUserData;\n</code></pre>\n'}, {'answer_id': 33342, 'author': 'Anders', 'author_id': 3501, 'author_profile': 'https://Stackoverflow.com/users/3501', 'pm_score': 4, 'selected': False, 'text': '<p>The other alternative is SetProp/RemoveProp (When you are subclassing a window that already uses GWLP_USERDATA)</p>\n\n<p>Another good alternative is ATL style thunking of the WNDPROC, for more info on that, see</p>\n\n<ul>\n<li><a href="http://www.ragestorm.net/blogs/?cat=20" rel="noreferrer">http://www.ragestorm.net/blogs/?cat=20</a></li>\n<li><a href="http://www.hackcraft.net/cpp/windowsThunk/" rel="noreferrer">http://www.hackcraft.net/cpp/windowsThunk/</a></li>\n</ul>\n'}]
['https://Stackoverflow.com/questions/23083', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2354/']