summaryrefslogtreecommitdiffstats
path: root/src/mspdb.cpp
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/mspdb.cpp
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/mspdb.cpp')
-rw-r--r--src/mspdb.cpp38
1 files changed, 38 insertions, 0 deletions
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);