DLL Registration Fails with Exit Code 5 After Upgrading Platform Toolset to v142 in Visual Studio 2019
I'm upgrading a C++ project from Visual Studio 2012 to Visual Studio 2019, changing the Platform Toolset from v110 to v142. The project builds successfully, but during registration of a DLL, I encounter the following error:
error MSB3075: The command "regsvr32 /s /c "Path/dll"
error MSB3075: :VCEnd" exited with code 5. Please verify that you have sufficient rights to run this command.
When attempting to manually register the DLL via an elevated command prompt, I get this error:
The DLL is loaded, but registration failed with exit code 0x80029C4A.
What I’ve tried:
Checked Dependencies: Ran Dependency Walker to ensure all required dependencies are present and in the correct path — no missing DLLs detected.
Registered Dependent Files: Manually registered all dependent DLLs and Type Library (.tlb) files. Permissions: Granted full control permissions to the DLL and its directory.
Platform Toolset Review: Double-checked that no unintended code changes occurred after switching the toolset.
UAC & Admin Rights: Verified that Visual Studio and the command prompt were run as Administrator. Redistributables: Made sure the correct Visual C++ Redistributable for v142 is installed. Additional Investigation:
Debugging Registration: I added MessageBoxes to debug the registration process and found that:
If I pass a hardcoded path to the LoadTypeLib [removed_js], the type library registers successfully.
Issue with _AtlComModule.m_hInstTypeLib: On further debugging, I discovered that _AtlComModule.m_hInstTypeLib is pointing to the path of regsvr32.exe instead of the DLL path.
I checked another similar project (with identical settings) that registers without issues, and its hInstance correctly points to the DLL path, not regsvr32.exe. This makes me think that something in the build or project settings might be messing up the module instance handle, but I can't figure out what could be causing this.
What could cause regsvr32 to fail with exit code 5 (Access Denied) or 0x80029C4A, and why would _AtlComModule.m_hInstTypeLib point to regsvr32.exe instead of the DLL path?
Are there any build/link settings, COM module changes, or Platform Toolset quirks after upgrading that might explain this behavior?