User forums > Using Code::Blocks
Open multiple files in Code::Blocks from the command line
Immint:
Thanks for the confirmation! This weekend I think I'll see if I can find where the list of files to be opened is stored and whether it's easy to empty it up once it's done loading files. It sounds like it should be doable to fix even without prior knowledge of the source code. Alternatively if I get stumped there, I could have a look into how the DDE communication works and write a little wrapper to start Code::Blocks or send files that way. Maybe wxWidgets even offers a way to tackle this for Windows and Linux simultaneously.
Jenna:
--- Quote from: Immint on October 06, 2016, 10:56:47 pm ---Thanks for the confirmation! This weekend I think I'll see if I can find where the list of files to be opened is stored and whether it's easy to empty it up once it's done loading files. It sounds like it should be doable to fix even without prior knowledge of the source code. Alternatively if I get stumped there, I could have a look into how the DDE communication works and write a little wrapper to start Code::Blocks or send files that way. Maybe wxWidgets even offers a way to tackle this for Windows and Linux simultaneously.
--- End quote ---
It's actually an issue in wxWidgets 2.8, which is fixed in wx3.
It was brought up by one of our developers and we most likely have a thread about it, but nevertheless I forgot it, sorry.
See: http://trac.wxwidgets.org/ticket/16503
In other words, it can not be fixed with wxWidgets 2.8 based C::B, but should not be present if build against wx3.
Immint:
After some tinkering, I managed to get the 64 bit version of Code::Blocks to compile against wxWidgets 3.1 into a working executable with corresponding set of dlls. :) Feels a bit different in a way I can't quite put my finger on, but I can confirm the weird starting problems are fixed. Thanks for the help, everybody! :D
Immint:
Just a quick followup (much delayed because I had very little time to actually do any home coding lately)
After having some trouble with the wxWidgets 3 version I compiled, I decided to go another route and toy with DDE for a bit. I ended up writing a little launcher to do what I want. In case anyone runs into the same problem, here's the program in its entirety. You can compile it with any version of wxWidgets with any compiler and use it with any official binary of Code::Blocks; the library will see to it that the communication works correctly. :D
--- Code: ---#include <wx/app.h>
#include <wx/ipc.h>
wxString DdeServiceName(wxString UserId)
{
#ifdef __WXMSW__
return "CODEBLOCKS";
#else
return _T("/tmp/CODEBLOCKS") + UserId + _T(".socket");
#endif
}
class CbLauncherApp : public wxApp
{
public:
virtual bool OnInit();
};
IMPLEMENT_APP(CbLauncherApp);
bool CbLauncherApp::OnInit()
{
wxLogNull ln; // We don't want visible errors on failed connections.
wxClient client;
wxConnection* connection = dynamic_cast<wxConnection*>(
client.MakeConnection(_T("localhost"),
DdeServiceName(wxGetUserId().wx_str()),
_T("CodeBlocksDDEServer")));
if (connection)
{
// We have a connection to an existing instance; send the file list...
for (int i = 1 ; i < argc; ++i)
connection->Execute(_T("[Open(\"") + argv[i] + _T("\")]"));
// ...and raise the window to the top.
connection->Execute(_T("[Raise]"));
connection->Disconnect();
delete connection;
}
else
{
// No running instance, so start a new one.
wxString cmdLine;
for (int i = 1 ; i < argc; ++i)
cmdLine += _T(" \"") + wxString(argv[i]) + _T("\"");
wxExecute(_T("codeblocks.exe") + cmdLine);
}
return false;
}
--- End code ---
Note that it's very limited in what it does; you can't pass any commandline arguments to Code::Blocks after the first instance, and all paths must be absolute. Because it already does what I needed it to, I didn't develop it any further, but I still wanted to leave this here to not ultimately leave the question answered but the problem unsolved! :)
Navigation
[0] Message Index
[*] Previous page
Go to full version