当前位置:   article > 正文

Minecraft启动器制作(C++)_c++制作mc启动器

c++制作mc启动器

获取Java路径

INT GetJavaHomePathFromRegedit(wchar_t* retwstr) {
	wchar_t str[MAX_PATH + 1];
	INT flag = GetStrFromRegedit(L"SOFTWARE\\JavaSoft\\Java Runtime Environment\\", L"CurrentVersion", str);
	wprintf(L"%ws\n", str);

	WCHAR keyjp[MAX_PATH + 1] = L"\0";
	swprintf_s(keyjp, MAX_PATH, L"%ws%ws", L"SOFTWARE\\JavaSoft\\Java Runtime Environment\\", str);
	wprintf(L"%ws\n", keyjp);
	flag = GetStrFromRegedit(keyjp, L"JavaHome", str);
	wprintf(L"%ws\n", str);
	swprintf_s(retwstr, MAX_PATH, L"%ws%ws", str, L"\\bin\\java.exe");
	return TRUE;
}

INT GetStrFromRegedit(const wchar_t* hkey, const wchar_t* childkey, wchar_t* str) {
	HKEY retKey;
	BYTE retKeyVal[MAX_PATH + 1] = { 0 };
	DWORD nSize = MAX_PATH + 1;
	LONG ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, hkey, 0, KEY_QUERY_VALUE | KEY_READ, &retKey);
	//记得加KEY_READ来读取多级子键
	if (ret != ERROR_SUCCESS) {
		return -1;
	}
	ret = RegQueryValueEx(retKey, childkey, NULL, NULL, (LPBYTE)retKeyVal, &nSize);
	RegCloseKey(retKey);
	if (ret != ERROR_SUCCESS) {
		return -2;
	}
	int sum = 0;
	wchar_t TEMPSTR[MAX_PATH + 1] = L"\0";
	for (int i = 0; i < int(nSize); i += 1) {
		if (retKeyVal[i + 1] == 0) {
			TEMPSTR[i] = retKeyVal[i];
			if (retKeyVal[i] == 0) break;
		}
	}
	for (int i = 0; i < int(nSize); i += 1) {
		if (retKeyVal[i + 1] == 0) {
			*(str + sum) = retKeyVal[i];
			sum++;
			if (retKeyVal[i] == 0) break;
		}
	}
	return TRUE;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/173164
推荐阅读
相关标签
  

闽ICP备14008679号