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
#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;
}
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! :)