Skip to content

Commit

Permalink
Fix ShellExecute return
Browse files Browse the repository at this point in the history
  • Loading branch information
SupSuper committed Apr 19, 2021
1 parent 10722a7 commit dade93c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/Engine/CrossPlatform.cpp
Expand Up @@ -32,6 +32,7 @@
#include "Logger.h"
#include "Exception.h"
#include "Options.h"
#include "Unicode.h"
#ifdef _WIN32
#ifndef NOMINMAX
#define NOMINMAX
Expand Down Expand Up @@ -1185,11 +1186,12 @@ void crashDump(void *ex, const std::string &err)
bool openExplorer(const std::string &url)
{
#ifdef _WIN32
HINSTANCE ret = ShellExecuteA(NULL, "open", url.c_str(), NULL, NULL, SW_SHOWNORMAL);
HINSTANCE ret = ShellExecuteW(NULL, L"open", Unicode::convMbToWc(url, CP_UTF8).c_str(), NULL, NULL, SW_SHOWNORMAL);
// The return value is not a true HINSTANCE. If the function succeeds, it returns a value greater than 32.
return ((int)ret > 32);
return (static_cast<int>(reinterpret_cast<uintptr_t>(ret)) > 32);
#elif __APPLE__
return false;
std::string cmd = "open \"" + url + "\"";
return (system(cmd.c_str()) == 0);
#else
std::string cmd = "xdg-open \"" + url + "\"";
return (system(cmd.c_str()) == 0);
Expand Down
4 changes: 4 additions & 0 deletions src/Engine/Unicode.h
Expand Up @@ -61,6 +61,10 @@ namespace Unicode
UString convUtf8ToUtf32(const std::string &src);
/// Converts a UTF-32 string to UTF-8.
std::string convUtf32ToUtf8(const UString &src);
/// Converts a wide-char string to multi-byte.
std::string convWcToMb(const std::wstring &src, unsigned int cp = 0);
/// Converts a multi-byte string to wide-char.
std::wstring convMbToWc(const std::string &src, unsigned int cp = 0);
/// Converts a path to a UTF-8 string.
std::string convPathToUtf8(const std::string &src);
/// Converts a UTF-8 string to a path.
Expand Down

0 comments on commit dade93c

Please sign in to comment.