summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAkihiko Odaki <nekomanma@pixiv.co.jp>2018-09-26 10:34:19 (GMT)
committerAkihiko Odaki <nekomanma@pixiv.co.jp>2018-09-27 00:59:41 (GMT)
commit5e1632e2cca5b8d537bc66525d631ebd72f6949b (patch)
tree738489333db45bdb069607024d5010607fea21d9 /src
parent0198534ac9fca5ac2ba9c0f9c4c5788849db6b41 (diff)
downloadcv2pdb-5e1632e2cca5b8d537bc66525d631ebd72f6949b.zip
cv2pdb-5e1632e2cca5b8d537bc66525d631ebd72f6949b.tar.gz
cv2pdb-5e1632e2cca5b8d537bc66525d631ebd72f6949b.tar.bz2
Add Visual Studio detection by the COM API
The new COM API is expected to work on Visual Studio 2017 and newer installations. It is also compatible with non-x86 runtime.
Diffstat (limited to 'src')
-rw-r--r--src/cv2pdb.vcxproj10
-rw-r--r--src/main.cpp2
-rw-r--r--src/mspdb.cpp38
-rw-r--r--src/packages.config4
4 files changed, 54 insertions, 0 deletions
diff --git a/src/cv2pdb.vcxproj b/src/cv2pdb.vcxproj
index d79bdc2..af3b87b 100644
--- a/src/cv2pdb.vcxproj
+++ b/src/cv2pdb.vcxproj
@@ -208,8 +208,18 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
</MASM>
</ItemGroup>
+ <ItemGroup>
+ <None Include="packages.config" />
+ </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="$(VCTargetsPath)\BuildCustomizations\masm.targets" />
+ <Import Project="packages\Microsoft.VisualStudio.Setup.Configuration.Native.1.16.30\build\native\Microsoft.VisualStudio.Setup.Configuration.Native.targets" Condition="Exists('packages\Microsoft.VisualStudio.Setup.Configuration.Native.1.16.30\build\native\Microsoft.VisualStudio.Setup.Configuration.Native.targets')" />
</ImportGroup>
+ <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
+ <PropertyGroup>
+ <ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
+ </PropertyGroup>
+ <Error Condition="!Exists('packages\Microsoft.VisualStudio.Setup.Configuration.Native.1.16.30\build\native\Microsoft.VisualStudio.Setup.Configuration.Native.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Microsoft.VisualStudio.Setup.Configuration.Native.1.16.30\build\native\Microsoft.VisualStudio.Setup.Configuration.Native.targets'))" />
+ </Target>
</Project> \ No newline at end of file
diff --git a/src/main.cpp b/src/main.cpp
index 70b1563..608f197 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -122,6 +122,8 @@ int T_main(int argc, TCHAR* argv[])
const TCHAR* pdbref = 0;
bool debug = false;
+ CoInitialize(nullptr);
+
while (argc > 1 && argv[1][0] == '-')
{
argv++;
diff --git a/src/mspdb.cpp b/src/mspdb.cpp
index cb3e812..59c994a 100644
--- a/src/mspdb.cpp
+++ b/src/mspdb.cpp
@@ -6,7 +6,14 @@
#include "mspdb.h"
+#include <atlstr.h>
+#include <comdef.h>
#include <windows.h>
+#include <Setup.Configuration.h>
+
+_COM_SMARTPTR_TYPEDEF(ISetupConfiguration, __uuidof(ISetupConfiguration));
+_COM_SMARTPTR_TYPEDEF(ISetupInstance, __uuidof(ISetupInstance));
+_COM_SMARTPTR_TYPEDEF(IEnumSetupInstances, __uuidof(IEnumSetupInstances));
#pragma comment(lib, "rpcrt4.lib")
@@ -81,6 +88,35 @@ bool tryLoadMsPdb(const char* version, const char* mspdb, const char* path = 0)
return modMsPdb != 0;
}
+bool tryLoadMsPdbCom(const char* mspdb, const char* path = 0)
+{
+ ISetupConfigurationPtr query;
+ ISetupInstancePtr instance;
+ IEnumSetupInstancesPtr instances;
+ BSTR installDir;
+ unsigned long fetched;
+
+ auto result = query.CreateInstance(__uuidof(SetupConfiguration));
+ if ((FAILED(result) && result != REGDB_E_CLASSNOTREG) || FAILED(query->EnumInstances(&instances)))
+ return false;
+
+ while (!modMsPdb)
+ {
+ if (FAILED(instances->Next(1, &instance, &fetched)) || !fetched)
+ return false;
+
+ if (FAILED(instance->GetInstallationPath(&installDir)))
+ continue;
+
+ CStringA modpath = installDir;
+ modpath += "\\Common7\\IDE\\";
+ modpath += mspdb;
+ tryLoadLibrary(modpath);
+ }
+
+ return true;
+}
+
bool tryLoadMsPdbVS2017(const char* mspdb, const char* path = 0)
{
const char* key = "SOFTWARE\\Microsoft\\VisualStudio\\SxS\\VS7";
@@ -178,6 +214,8 @@ void tryLoadMsPdb140(bool throughPath)
if(throughPath)
modMsPdb = LoadLibraryA(mspdb140_dll);
if(!modMsPdb && !throughPath)
+ tryLoadMsPdbCom(mspdb140_dll);
+ if(!modMsPdb && !throughPath)
tryLoadMsPdbVS2017(mspdb140_dll);
if (!modMsPdb && !throughPath)
tryLoadMsPdb("VisualStudio\\14.0", mspdb140_dll, BIN_DIR_GE_VS12);
diff --git a/src/packages.config b/src/packages.config
new file mode 100644
index 0000000..8bfdb5a
--- /dev/null
+++ b/src/packages.config
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+ <package id="Microsoft.VisualStudio.Setup.Configuration.Native" version="1.16.30" targetFramework="native" developmentDependency="true" />
+</packages> \ No newline at end of file