title: Visual Studio 2015 cannot produce an ATL Dll that successfully registers on Windows XP
body: <p>I have a legacy project that I am porting to Win 10. We need to keep compatibility with Windows XP, and I have been unsuccessful in getting the converted projects to even register under XP. In an effort to understand what is necessary (after many weeks of searching both Stack Overflow and MSDN), I attempted to create an ATL-based Dll from scratch using VS 2015 - and it doesn't work. Before going further, let me get a few things out of the way:</p>
  
  <p>1) Yes, I have installed VS 2015 with the C++ support for XP enabled.
  2) Yes, I have set the platform toolset to XP
  3) Yes, I have installed the VS 2015 x86 redistributable package on the XP target</p>
  
  <p>If I just go through the ATL project wizard and stop before adding any COM interfaces, the Dll successfully registers on XP. If I add an interface without any methods, regsvr32 fails with return code 0xc0000005. If I add a method to the interface, and supply an implementation, it continues to fail in the same manner. </p>
  
  <p>If you can supply the missing piece, I'd be grateful. The process I go through to generate a minimal Dll takes about 5 minutes of effort, here are my steps (settings are chosen to best approximate the Dll I want to port):</p>
  
  <p>Required environments:</p>
  
  <p>You will need a Win 10 system with Visual Studio 2015 installed with XP Support enabled (you will get build errors if the XP C++ support option was not checked at install time; it is not a default option), and</p>
  
  <p>A Windows XP system with VS 2015 x86 redistributable installed (available here: <a href="https://www.microsoft.com/en-us/download/details.aspx?id=48145" rel="nofollow">https://www.microsoft.com/en-us/download/details.aspx?id=48145</a>)</p>
  
  <p>Open VS 2015, select File/New/New Project…</p>
  
  <p>• From the Installed/Templates/Visual C++/Windows Tree on the left hand side of the dialog, select “ATL” as the project type filter, 
  • Select “ATL Project” as the project type from the template list in the center of the dialog. 
  • Select “.NET Framework 3.5” as the .NET Framework from the drop down list at the top of the dialog
  • Name the project “DllHoopty”, 
  • Select the “Create directory for solution” option at the bottom right of the dialog. 
  • Click OK to begin the project wizard.</p>
  
  <p>When the Project wizard appears, the current project settings should be “Dynamic-Link Library”. </p>
  
  <p>• Click “Next”, NOT “Finish”</p>
  
  <p>On the “Application Settings” page:</p>
  
  <p>• Select “Allow merging of proxy/stub code”, 
  • DESELECT “Security Development Lifecycle (SDL) checks”. 
  • Leave “Support MFC” and “Support COM+ 1.0” unchecked. 
  • Click “Finish” to create the project &amp; solution.</p>
  
  <p>When the project/solution has been created:</p>
  
  <p>• Select “Release” as the configuration, and “x86” as the platform.
  • Right click on the DllHoopty project, and select “Properties”. 
  • In the properties dialog, make sure the Configuration and Platform are “Release” and “Win32”, respectively
  • If it isn’t already selected, go to the “Configuration Properties/General” panel
  • Change the “Platform Toolset” to “Visual Studio 2015 - Windows XP (v140_xp)”
  • Click OK to save the changes and dismiss the properties panel.</p>
  
  <p>If you stop here and build the solution, the dll that is produced will SUCCESSFULLY register.</p>
  
  <p>Right click on the DllHoopty project, and select “Add/Class…” from the popup menu to bring up the Add Class dialog
  • Select “Installed/Visual C++/ATL” from the tree, and “ATL Simple Object” from the template list
  • Click “Add” to begin the ATL Simple Object Wizard.</p>
  
  <p>• On the “Welcome to the ATL Simple Object Wizard” page, give the object a “Short name” of Hoopty. This will cause all the other fields to be filled in. 
  • Click “Next”.
  • Click “Next” on the “File Type Handler Options” page</p>
  
  <p>On the “Options” page:
  • Select “Single” as the threading model, 
  • Select “No” as the “Aggregation” option, 
  • Select “Custom” as the “Interface” option. 
  • Leave the “Automation compatible” box under “Custom” unchecked. 
  • All of the “Support” boxes should be unchecked.<br>
  • Click “Finish”</p>
  
  <p>At this point and beyond, any dll produced will fail to register with the message “DllRegisterServer in DllHoopty.dll failed. Return code was 0xc0000005”</p>
  
  <p>Open the file “DllHoopty.idl”, 
  • add “HRESULT Wub();” to the “interface IHoopty”, e.g. change it to read:</p>
  
  <pre><code>interface IHoopty : IUnknown{
      HRESULT Wub();
  };
  </code></pre>
  
  <p>Open “Hoopty.h” 
  • add:</p>
  
  <pre><code> STDMETHOD(Wub)();
  </code></pre>
  
  <p>to the public: section at the end of the CHoopty class declaration</p>
  
  <p>Open “Hoopty.cpp” 
  • add:</p>
  
  <pre><code>STDMETHODIMP CHoopty::Wub()
  {
      return S_OK;
  }
  </code></pre>
  
  <p>Build the project (making sure  Release/x86 is the selected config &amp; platform)</p>
  
  <p>• Move “DllHoopty.dll” to local hard drive (NOT a shared folder if you are using VMs with VirtualBox, as I do) on the Win XP machine with the C++ redistributable installed. </p>
  
  <p>On the XP machine:
  • Bring up a command prompt, 
  • Navigate to the location of DllHoopty.dll, 
  • run “regsvr32 DllHoopty.dll”. </p>
  
  <p>If my guess is correct, you will get an error dialog:</p>
  
  <p>“DllRegisterServer in DllHoopty.dll failed. Return code was: 0xc0000005”</p>
  
  <p>I have tried many, many things: Adding defines for WINVER 0x0501, _WIN32_WINNT 0x0501,  _ATL_XP_TARGETING, and so many others I have forgotten. Nothing changes the outcome.</p>