Command line arguments.

Login to reply to this topic.
Wed, 2003-10-08 09:44
Joined: 2003-10-08
Forum posts: 13
Hi group I want to launch an app from another passing it an argument this is
my code:

-----------------------------CalledApp-----------------------------------
CCommandLineArguments* args = CCommandLineArguments::NewLC();
    if (args->Count() > 1)
{
//Access thi param args->Arg(1);  *****//This line always return me
\System\Apps\MyApp\MyApp.APP. Why??***
}
else
{
iEikonEnv->InfoMsg(args->Arg(0));
}
CleanupStack::PopAndDestroy();
--------------------------------------------------------------------------
And to launch the app I do something like this:
--------------------Caller App-------------------------------------------

TFileName AppToLaunch;

TBuf<200> iDoc;

AppToLaunch = _L("z:\\System\\Apps\\MyAppName\\MyAppName.APP");

iDoc = _L("aParam"); //This is the argument.

CApaCommandLine* cmdLine = CApaCommandLine::NewLC();

cmdLine->SetDocumentNameL(iDoc);      <--//Here I pass the argument I'm not
sure if this instruction is well.
cmdLine->SetLibraryNameL(AppToLaunch);
cmdLine->SetCommandL(EApaCommandRun);

RApaLsSession ls;
User::LeaveIfError(ls.Connect());

TInt initialAppCount;
ls.EmbeddableAppCount( initialAppCount );
CleanupClosePushL(ls);
User::LeaveIfError(ls.StartApp(*cmdLine));

CleanupStack::PopAndDestroy(2);
-------------------------------------------------------

When I access to args->Arg(1) or args->Arg(2), where the argument must be in, always return
me this path \System\Apps\MyApp\MyApp.APP

Any idea about how to launch an app with an argument and then recovery this
argument from the launched app??

Thx in advance. WinkWink

Wed, 2003-10-08 10:15
Joined: 2003-05-27
Forum posts: 363
Command line arguments.
Hi,

The code you have pasted should work just fine - looks like the error could be somewhere else. If you have not seen this link yet, have a look here:

http://www.newlc.com/article.php3?id_article=143

Cheers,
Pawel
Wed, 2003-10-08 10:52
Joined: 2003-10-08
Forum posts: 13
Command line arguments.
Hi pawel, i had read this document, but what I need is how to read the params in the called app.
I must do anything more??
My app must support document??
The called app reads the param in the MyAppUi::ConstructL method.
Someone told me that this issue is only in the emulator.
Thx.
Wed, 2003-10-08 11:04
Joined: 2003-05-27
Forum posts: 363
Command line arguments.
Hi,
Overriding this should work:

CEikAppUi::ProcessCommandParametersL(TApaCommand aCommand,TFileName& aDocumentName,const TDesC8& aTail)

There is more info in the Symbian documentation.

Cheers,
Pawel
Wed, 2003-10-08 11:12
NewLC AdministratorSymbian AccreditedForum Nokia Champion
Joined: 2003-01-14
Forum posts: 2009
Command line arguments.
Override the OpenFileL() method in your AppDocument.cpp file.
The methods will be automatically called by the framework with your doc (iDoc) in the aFilename parameter.

Code:
CFileStore* CYourAppDocument::OpenFileL(TBool aDoOpen,const TDesC& aFilename,RFs& aFs)
{
 if(aDoOpen)
 {
      // Do what you want
      // (aFilename is your doc name)
      ...
 }
 return(NULL);
}

Eric Bustarret
NewLC Founder & CEO / Professional Symbian OS Consultant

Fri, 2003-10-10 09:04
Anonymous (not verified)
Forum posts: 2043
Command line arguments.
How can I pass the params recived in this method to MyAppUi class??

Quote from: eric
Override the OpenFileL() method in your AppDocument.cpp file.
The methods will be automatically called by the framework with your doc (iDoc) in the aFilename parameter.

Code:
CFileStore* CYourAppDocument::OpenFileL(TBool aDoOpen,const TDesC& aFilename,RFs& aFs)
{
 if(aDoOpen)
 {
      // Do what you want
      // (aFilename is your doc name)
      ...
 }
 return(NULL);
}
Sun, 2003-10-12 07:18
Joined: 2003-05-27
Forum posts: 363
Command line arguments.
Hi,

Your App Ui owns the document so you can always access it via the Document() method after it has been created.

Cheers,
Pawel
Mon, 2005-11-14 10:21
Joined: 2005-02-17
Forum posts: 26
Re: Command line arguments.
What would be some reasons for the Document class's overloaded OpenFileL( TBool aDoOpen, const TDesC& /*aFilename*/, RFs& /*aFs*/ ) method not being called? I can't seem to retrieve any arguments passed into my application.

Calling app:
      TThreadId threadId;
      _LIT( KAppExtension, ".app" );
      iCmdLine = CApaCommandLine::NewLC();
      TFullName iExeFileName = _L("c:\\system\\apps\\basicapp\\basicapp");
      TFileName newname = iExeFileName;
      newname.Append( KAppExtension );

      _LIT( KDoc, "c:\\documents\\app.dat" );
      iCmdLine->SetDocumentNameL( KDoc );
      iCmdLine->SetLibraryNameL( newname );
      iCmdLine->SetCommandL( EApaCommandRun );
      iCmdLine->SetTailEndL( _L8( "String" ) );

      RApaLsSession ls;
      User::LeaveIfError( ls.Connect() );
      CleanupClosePushL( ls );
      User::LeaveIfError( ls.StartApp( *iCmdLine ) );
      
      CleanupStack::PopAndDestroy( 2 ); // iCmdLine, close ls


Called app has this code:
CFileStore* CQBasicAppDocument::OpenFileL( TBool aDoOpen, const TDesC& /*aFilename*/, RFs& /*aFs*/ )
   {
   if( aDoOpen )
      {
      // (aFilename is your doc name)
      TInt len = RProcess().CommandLineLength();
      iCmdlineBuffer = HBufC::NewLC( len );
      TPtr cmdline( iCmdlineBuffer->Des() );
      RProcess().CommandLine( cmdline );
      }
   return(NULL);
   }
however it is never called.
And also this:

GLDEF_C TInt E32Dll(TDllReason)
   {
   TInt len = RProcess().CommandLineLength();
   if( len > 0 )
      {
      TBuf<256> cmdLineBuf;
      RProcess().CommandLine( cmdLineBuf );      
      }
   TBuf<256> cmdLineBuf;
   RProcess().CommandLine( cmdLineBuf );
   return KErrNone;
   }
len is always 0 and cmdLineBuf never contains anything..

If someone has some ideas please let me know.

Niimidan

  • Login to reply to this topic.