「FreeScriptの練習2」の版間の差分
編集の要約なし |
編集の要約なし |
||
15行目: | 15行目: | ||
--> | --> | ||
<div class="hljs-wrap"><pre data-label="GoogleSearchVBAFunction.bas" class="pre-wrap"> | <div class="hljs-wrap"><pre data-label="GoogleSearchVBAFunction.bas" class="pre-wrap"> | ||
<code class="language-vbnet"> | <code class="language-vbnet">#include <iostream> | ||
#include <fstream> | |||
#include <string> | |||
#include <vector> | |||
#include <filesystem> | |||
#include <windows.h> | |||
#include <winhttp.h> | |||
#include <typeinfo> | |||
& | |||
#include <zip.h> | |||
& | |||
#pragma comment(lib, "winhttp.lib") | |||
#pragma comment(lib, "Version.lib") | |||
#pragma comment(lib, "zip.lib") | |||
std::string GetVersion(const std::string& path) { | |||
DWORD handle; | |||
DWORD size = GetFileVersionInfoSizeA(path.c_str(), &handle); | |||
if (size == 0) { | |||
throw std::runtime_error("Failed to get version info size."); | |||
} | |||
std::vector<char> data(size); | |||
if (!GetFileVersionInfoA(path.c_str(), handle, size, data.data())) { | |||
throw std::runtime_error("Failed to get version info."); | |||
} | |||
VS_FIXEDFILEINFO* versionInfo; | |||
UINT len; | |||
if (!VerQueryValueA(data.data(), "\\", (LPVOID*)&versionInfo, &len)) { | |||
throw std::runtime_error("Failed to query version info."); | |||
} | |||
DWORD major = (versionInfo->dwFileVersionMS >> 16) & 0xffff; | |||
DWORD minor = versionInfo->dwFileVersionMS & 0xffff; | |||
DWORD build = (versionInfo->dwFileVersionLS >> 16) & 0xffff; | |||
DWORD revision = versionInfo->dwFileVersionLS & 0xffff; | |||
return std::to_string(major) + "." + | |||
std::to_string(minor) + "." + | |||
std::to_string(build) + "." + | |||
std::to_string(revision); | |||
}</code></pre><div> | |||
<script></freescript> | <script></freescript> | ||
2024年12月29日 (日) 00:52時点における版
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <filesystem>
#include <windows.h>
#include <winhttp.h>
#include <typeinfo>
#include <zip.h>
#pragma comment(lib, "winhttp.lib")
#pragma comment(lib, "Version.lib")
#pragma comment(lib, "zip.lib")
std::string GetVersion(const std::string& path) {
DWORD handle;
DWORD size = GetFileVersionInfoSizeA(path.c_str(), &handle);
if (size == 0) {
throw std::runtime_error("Failed to get version info size.");
}
std::vector<char> data(size);
if (!GetFileVersionInfoA(path.c_str(), handle, size, data.data())) {
throw std::runtime_error("Failed to get version info.");
}
VS_FIXEDFILEINFO* versionInfo;
UINT len;
if (!VerQueryValueA(data.data(), "\\", (LPVOID*)&versionInfo, &len)) {
throw std::runtime_error("Failed to query version info.");
}
DWORD major = (versionInfo->dwFileVersionMS >> 16) & 0xffff;
DWORD minor = versionInfo->dwFileVersionMS & 0xffff;
DWORD build = (versionInfo->dwFileVersionLS >> 16) & 0xffff;
DWORD revision = versionInfo->dwFileVersionLS & 0xffff;
return std::to_string(major) + "." +
std::to_string(minor) + "." +
std::to_string(build) + "." +
std::to_string(revision);
}
test string.