Skip to content

Commit

Permalink
Windows standalone: Use default entry point, unicode argv
Browse files Browse the repository at this point in the history
  • Loading branch information
mthierman committed Oct 14, 2024
1 parent 0c23f5e commit 6dd324d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 21 deletions.
14 changes: 0 additions & 14 deletions cmake/wrap_standalone.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -133,20 +133,6 @@ function(target_add_standalone_wrapper)
target_compile_definitions(${SA_TARGET} PRIVATE _SILENCE_CLANG_COROUTINE_MESSAGE)
endif()

if(CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC")
target_link_options(
${SA_TARGET}
PRIVATE
/entry:mainCRTStartup
)
elseif(CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "GNU")
target_link_options(
${SA_TARGET}
PRIVATE
-Wl,/entry:mainCRTStartup
)
endif()

target_link_libraries(${SA_TARGET} PRIVATE base-sdk-wil ComCtl32.Lib)

elseif(UNIX)
Expand Down
22 changes: 18 additions & 4 deletions src/detail/standalone/windows/windows_standalone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@

namespace freeaudio::clap_wrapper::standalone::windows_standalone
{
std::pair<int, std::vector<std::string>> getArgs()
{
int argc{0};
wil::unique_hlocal_ptr<wchar_t*[]> buffer;
buffer.reset(::CommandLineToArgvW(::GetCommandLineW(), &argc));

std::vector<std::string> argv;

for (int i = 0; i < argc; i++)
{
argv.emplace_back(toUTF8(buffer[i]));
}

return {argc, argv};
}

::HMODULE getInstance()
{
::HMODULE module;
Expand Down Expand Up @@ -591,11 +607,9 @@ void SystemMenu::populate(::HWND hwnd)
}
}

Plugin::Plugin(const clap_plugin_entry* entry, int argc, char** argv)
Plugin::Plugin(std::shared_ptr<Clap::Plugin> clapPlugin)
{
plugin.clap =
freeaudio::clap_wrapper::standalone::mainCreatePlugin(entry, PLUGIN_ID, PLUGIN_INDEX, argc, argv);

plugin.clap = clapPlugin;
plugin.plugin = plugin.clap->_plugin;
plugin.gui = plugin.clap->_ext._gui;
plugin.state = plugin.clap->_ext._state;
Expand Down
3 changes: 2 additions & 1 deletion src/detail/standalone/windows/windows_standalone.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ using namespace winrt::Windows::Data::Json;

namespace freeaudio::clap_wrapper::standalone::windows_standalone
{
std::pair<int, std::vector<std::string>> getArgs();
::HMODULE getInstance();
::HFONT getFontFromSystem(int name = DEFAULT_GUI_FONT);
::HFONT getScaledFontFromSystem(double scale);
Expand Down Expand Up @@ -372,7 +373,7 @@ struct Plugin final : public Window
const clap_plugin_state_t* state;
};

explicit Plugin(const clap_plugin_entry* entry, int argc, char** argv);
explicit Plugin(std::shared_ptr<Clap::Plugin> clapPlugin);

std::optional<clap_gui_resize_hints> getResizeHints();
void refreshLayout();
Expand Down
16 changes: 14 additions & 2 deletions src/wrapasstandalone_windows.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "detail/standalone/windows/windows_standalone.h"

int main(int argc, char** argv)
int wWinMain(::HINSTANCE, ::HINSTANCE, wchar_t*, int)
{
auto coUninitialize{wil::CoInitializeEx(COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE)};

Expand Down Expand Up @@ -33,7 +33,19 @@ int main(int argc, char** argv)
return 3;
}

freeaudio::clap_wrapper::standalone::windows_standalone::Plugin plugin{entry, argc, argv};
auto args{freeaudio::clap_wrapper::standalone::windows_standalone::getArgs()};

std::vector<char*> argv;

for (int i = 0; i < args.first; i++)
{
argv.emplace_back(args.second[i].data());
}

auto clapPlugin{freeaudio::clap_wrapper::standalone::mainCreatePlugin(entry, PLUGIN_ID, PLUGIN_INDEX,
args.first, argv.data())};

freeaudio::clap_wrapper::standalone::windows_standalone::Plugin plugin{clapPlugin};

return freeaudio::clap_wrapper::standalone::windows_standalone::run();
}

0 comments on commit 6dd324d

Please sign in to comment.