CoCreateInstance failing - can't find possible reason why [duplicate]

I'm trying to dump the signature of a PDB on Windows 7 x64 using Visual Studio 2017 and its dia2dump. I loaded C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\DIA SDK\Samples\DIA2Dump\DIA2Dump.sln. It built successfully:

1>------ Rebuild All started: Project: Dia2Dump, Configuration: Debug x64 ------
1>stdafx.cpp
1>regs.cpp
1>PrintSymbol.cpp
1>dia2dump.cpp
1>Generating Code...
1>Dia2Dump.vcxproj -> C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\DIA SDK\Samples\DIA2Dump\x64\Debug\Dia2Dump.exe
1>Dia2Dump.vcxproj -> C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\DIA SDK\Samples\DIA2Dump\x64\Debug\Dia2Dump.pdb (Partial PDB)
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========

When I run it on the PDB, I get the following error:

C:\>"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\DIA SDK\Samples\DIA2Dump\x64\Debug\Dia2Dump.exe" file.pdb
CoCreateInstance failed - HRESULT = 80040154

Just in case, I ran the following and it was successful, but dia2dump failed with the same error (also after reboot):

regsvr32 "C:\Program Files\Common Files\Microsoft Shared\VC\msdia100.dll"

How do I debug this?


Solution 1:

As of 20 June 2018, what I did was:

regsvr32 C:\Program Files\Common Files\Microsoft Shared\VC\msdia100.dll
regsvr32 C:\Program Files\Common Files\Microsoft Shared\VC\msdia90.dll
regsvr32 C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\DIA SDK\bin\msdia140.dll

Then I compiled as x64. It worked for me. If x64 didn't work, you can try x86.

Solution 2:

x64 Class not registered. you need run regsvr32 with x64 bit msdiaXXX.dll

RbMm posted the correct answer as comment already. But if someone faces the same problem: To register a 64-bit-DLL you need to use the regsvr32.exe from the C:/Windows/SYSWOW64 folder! Microsoft should have named it regsvr64.exe...

Solution 3:

I managed to get it to work by building Dia2Dump.exe as a 32-bit application. I did this in Visual Studio Community 2017 by opening the solution's project's properties, opened the Configuration Manage..., then changed the platform for the project to Win32.

I rebuilt the project, and now I no longer have CoCreateInstance failed - HRESULT = 80040154 errors! It works fine with any pdb file I give it.