Open With does not set argv

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
Post Reply
M_is_just_2_Ns
In need of some credit
In need of some credit
Posts: 2
Joined: Wed Dec 23, 2020 9:28 pm

Open With does not set argv

Post by M_is_just_2_Ns »

I am creating an application for modifying specific files.
I want the users to be able to just "open with... <my Application>" such a file.
As far as I understand, that would increment wxApp::argc and add the file's path to wxApp::argv, so that the following code should display the path to the chosen file:

Code: Select all

bool App::OnInit()
{
	wxMessageBox(std::string(argc[1]));
	// other stuff...
	return true;
}
And it does work when passing a parameter through the terminal.
But once I put it in a macOS Application-Bundle and actually used open-with on it, an Error occurred(and argc is 1).
Why is this? Am I doing something wrong? Any help is appreciated.
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Open With does not set argv

Post by doublemax »

Let's see what the documentation says:
wxChar** wxAppConsole::argv

Command line arguments (after environment-specific processing).

Under Windows and Linux/Unix, you should parse the command line arguments and check for files to be opened when starting your application. Under macOS, you need to override MacOpenFiles() since command line arguments are used differently there.
https://docs.wxwidgets.org/trunk/classw ... 9f05127d24
Use the source, Luke!
M_is_just_2_Ns
In need of some credit
In need of some credit
Posts: 2
Joined: Wed Dec 23, 2020 9:28 pm

Re: Open With does not set argv

Post by M_is_just_2_Ns »

I have implemented that MacOpenFiles(...) is called after OnInnit().
Why is the timing of that and how can I know if the function will ever be called (so that I can know if I should ask the user to choose a file manually)?
Post Reply