Symbian-Developers

The Official Developers Section => Symbian Software Development Discussions => The Developers Section => Symbian Java/C++ Application Development => Topic started by: huellif on October 29, 2013, 04:23:26 pm

Title: How to launch an external programm correctly
Post by: huellif on October 29, 2013, 04:23:26 pm
here's a little tutorial how to launch an external .exe
It needs no caps.

1. add following libs to your pro
Code: [Select]
LIBS += -lapparc -lapgrfx
2. include this headers
Code: [Select]
#include <apacmdln.h>
#include <apgcli.h>

3. use this simple code to launch an app:
Code: [Select]
    CApaCommandLine* commandLine = CApaCommandLine::NewLC();
    commandLine->SetCommandL(EApaCommandRun);
    commandLine->SetExecutableNameL(_L("myapp.exe"));
    RApaLsSession apaLsSession;
    User::LeaveIfError(apaLsSession.Connect());
    CleanupClosePushL(apaLsSession);
    User::LeaveIfError(apaLsSession.StartApp(*commandLine));
    CleanupStack::PopAndDestroy(&apaLsSession);
    CleanupStack::PopAndDestroy(commandLine);

you can also use it dynamically (works from Qt and native code):
Code: [Select]
void launch(const QString &n) const {
    TPtrC exe(reinterpret_cast<const TText*>(n.constData()));
    launch(exe);
}

void launch(const TPtrC &exe) const {
    CApaCommandLine* commandLine = CApaCommandLine::NewLC();
    commandLine->SetCommandL(EApaCommandRun);
    commandLine->SetExecutableNameL(exe);
    RApaLsSession apaLsSession;
    User::LeaveIfError(apaLsSession.Connect());
    CleanupClosePushL(apaLsSession);
    User::LeaveIfError(apaLsSession.StartApp(*commandLine));
    CleanupStack::PopAndDestroy(&apaLsSession);
    CleanupStack::PopAndDestroy(commandLine);
}
Title: Re: How to launch an external programm correctly
Post by: Allstar12345 on October 29, 2013, 04:29:45 pm
Nice one mate, you're finding some handy stuff ;)
Title: Re: How to launch an external programm correctly
Post by: Motaz on October 29, 2013, 06:31:58 pm
Thank you again huellif :)
Title: Re: How to launch an external programm correctly
Post by: huellif on October 29, 2013, 06:35:04 pm
you're welcome  :)