Browse Source

读取注册表;

scbc.sat2 5 years ago
parent
commit
d5caec63b4

+ 22 - 0
VideoCapture/VideoCapture/Global.cpp

@@ -222,6 +222,28 @@ namespace Global
 		free(old_locale);//还原区域设定;
 	}
 
+	int ReadReg(char* path, char* key, char* value)
+	{
+		HKEY hKey;
+		int ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, path, 0, KEY_QUERY_VALUE, &hKey);
+		if (ret != ERROR_SUCCESS)
+		{
+			return 1;
+		}
+
+		//读取KEY
+		DWORD dwType = REG_SZ; //数据类型
+		DWORD cbData = 256;
+		ret = RegQueryValueEx(hKey, key, NULL, &dwType, (LPBYTE)value, &cbData);
+		if (ret != ERROR_SUCCESS)
+		{
+			RegCloseKey(hKey);
+			return 1;
+		}
+		RegCloseKey(hKey);
+
+		return 0;
+	}
 
 	// 读取配置文件-预留;
 	void GetConfig()

+ 1 - 0
VideoCapture/VideoCapture/Global.h

@@ -74,6 +74,7 @@ namespace Global
 	//////////////////////////////////////////////////////////////////////////
 	// È«¾Öº¯Êý;
 	void GetConfig();
+	int ReadReg(char* path, char* key, char* value);
 	void WriteTextLog(const TCHAR* format, ...);
 	BOOL LoadImgFromFile(IN Image** pImg, LPCTSTR lpPath);
 	BOOL LoadImgFromBuffer(IN Image** pImg, IN BYTE* pBuffer, IN CONST INT& nBufLen);

+ 3 - 0
VideoCapture/VideoCapture/VideoCapture.cpp

@@ -112,6 +112,9 @@ BOOL CVideoCaptureApp::InitInstance()
 	Global::GetConfig();
 	Global::WriteTextLog("程序启动");
 
+	TCHAR szPythonDir[MAX_PATH] = {0};
+	Global::ReadReg("SOFTWARE\\WOW6432Node\\Python\\PythonCore\\2.7", "InstallPath", szPythonDir);
+
 	CDevice *pdev = new CDevice();
 	pdev->m_iBaudrate = 115200;
 	pdev->m_iDatabit = 8;