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:
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
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.
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):
Required environments:
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
A Windows XP system with VS 2015 x86 redistributable installed (available here: https://www.microsoft.com/en-us/download/details.aspx?id=48145)
Open VS 2015, select File/New/New Project…
• 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.
When the Project wizard appears, the current project settings should be “Dynamic-Link Library”.
• Click “Next”, NOT “Finish”
On the “Application Settings” page:
• 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 & solution.
When the project/solution has been created:
• 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.
If you stop here and build the solution, the dll that is produced will SUCCESSFULLY register.
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.
• 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
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.
• Click “Finish”
At this point and beyond, any dll produced will fail to register with the message “DllRegisterServer in DllHoopty.dll failed. Return code was 0xc0000005”
Open the file “DllHoopty.idl”,
• add “HRESULT Wub();” to the “interface IHoopty”, e.g. change it to read:
interface IHoopty : IUnknown{
HRESULT Wub();
};
Open “Hoopty.h”
• add:
STDMETHOD(Wub)();
to the public: section at the end of the CHoopty class declaration
Open “Hoopty.cpp”
• add:
STDMETHODIMP CHoopty::Wub()
{
return S_OK;
}
Build the project (making sure Release/x86 is the selected config & platform)
• 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.
On the XP machine:
• Bring up a command prompt,
• Navigate to the location of DllHoopty.dll,
• run “regsvr32 DllHoopty.dll”.
If my guess is correct, you will get an error dialog:
“DllRegisterServer in DllHoopty.dll failed. Return code was: 0xc0000005”
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.