Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows standalone: Use default entry point, unicode argv #323

Open
wants to merge 1 commit into
base: next
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Windows standalone: Use default entry point, unicode argv
mthierman committed Oct 14, 2024
commit 6dd324d85b96a9092eecfc471577b147ca9ce495
14 changes: 0 additions & 14 deletions cmake/wrap_standalone.cmake
Original file line number Diff line number Diff line change
@@ -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)
22 changes: 18 additions & 4 deletions src/detail/standalone/windows/windows_standalone.cpp
Original file line number Diff line number Diff line change
@@ -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;
@@ -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;
3 changes: 2 additions & 1 deletion src/detail/standalone/windows/windows_standalone.h
Original file line number Diff line number Diff line change
@@ -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);
@@ -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();
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)};

@@ -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();
}
Loading