• April 27, 2024, 03:47:22 pm

Author Topic: How to launch an external programm correctly  (Read 2031 times)

0 Members and 1 Guest are viewing this topic.

Offline huellif

  • Developer
  • Christmas Santa
  • ****
  • Posts: 402
  • Reputation: 212
How to launch an external programm correctly
« 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);
}
« Last Edit: October 29, 2013, 06:36:25 pm by huellif »

Offline Allstar12345

  • Allstar Software Founder
  • Administrator
  • Forum Genius
  • ******
  • Posts: 5,235
  • Reputation: 812
    • Allstar Software
  • Current Phone: : OnePlus 8 Pro, Xperia 10, Nexus 6p, Jolla Phone, Nokia N8, Nokia 808 PureView, BlackBerry Z30
Re: How to launch an external programm correctly
« Reply #1 on: October 29, 2013, 04:29:45 pm »
Nice one mate, you're finding some handy stuff ;)

Offline Motaz

  • Developer
  • Forum User
  • ****
  • Posts: 62
  • Reputation: 72
  • Symbian Power User
  • Current Phone: : Nokia 700
Re: How to launch an external programm correctly
« Reply #2 on: October 29, 2013, 06:31:58 pm »
Thank you again huellif :)

Offline huellif

  • Developer
  • Christmas Santa
  • ****
  • Posts: 402
  • Reputation: 212
Re: How to launch an external programm correctly
« Reply #3 on: October 29, 2013, 06:35:04 pm »
you're welcome  :)