Recent

Author Topic: How to start another application in WinCE  (Read 29311 times)

AndieSphinx

  • New Member
  • *
  • Posts: 23
How to start another application in WinCE
« on: April 16, 2007, 09:07:56 am »
Hi all,

my previous topic has disappeared somehow, so I need to ask again:

I have program on PDA, and want to start another one (notes.exe, calculator.exe, or anything) with a buttonclick.
I'm using ShellExecute, but the windows on the PDA says : There is no application associated with "notes.exe"
Btw, I don't want to associate anything, I just want WindowsCE to start this another application, if I ask it.

Any idea? :roll:

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
RE: How to start another application in WinCE
« Reply #1 on: April 16, 2007, 02:45:24 pm »

AndieSphinx

  • New Member
  • *
  • Posts: 23
RE: How to start another application in WinCE
« Reply #2 on: April 16, 2007, 03:42:19 pm »
Hi Sekel!

Thanx for the answer, I tried to used this, but unfortunately I got an error:
"Failed to execute \Windows\hello.exe" : 87.

Both starter.exe and hello.exe is in the same directory, in \Windows on my PDA. Hello.exe can be started manually, and works fine. (does nothing, only a form and a button).

My source is:

Code: [Select]

var
  Form1: TForm1;
  AProcess: TProcess;

implementation

{ TForm1 }

procedure TForm1.Button1Click(Sender: TObject);
var
 appath: string;
begin
  AProcess := TProcess.Create(nil);
  appath:=ExtractFilepath(application.exename);
  AProcess.CommandLine := appath+'hello.exe';
  AProcess.Options := AProcess.Options + [poWaitOnExit];
  AProcess.Execute;
  AProcess.Free;
end;


I already tried without the WaitOnExit and Free, only execute, the result is the same :(

Any idea, why am I unable to run my own program?

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
RE: How to start another application in WinCE
« Reply #3 on: April 16, 2007, 03:59:56 pm »
I don´t know. Search microsoft website and google to find out what this error means. Try both the error code and the error string.

AndieSphinx

  • New Member
  • *
  • Posts: 23
RE: How to start another application in WinCE
« Reply #4 on: April 16, 2007, 04:08:34 pm »
Hey!!!
  SysUtils.ExecuteProcess(appath+'hello.exe',[]);
is working!!! :)))

Btw, I'll check microsoft regarding why TProcess-stlye doesn't work...

Thanks Sekel!

AndieSphinx

  • New Member
  • *
  • Posts: 23
How to start another application in WinCE
« Reply #5 on: April 16, 2007, 09:01:57 pm »
Sorry Guys,

I have to wake up the thread :(

The > SysUtils.ExecuteProcess(appath+'hello.exe',[]); < is working, but unfortunately wait for the termination of the new process. So Starter.exe hangs up, till Hello.exe doesn't close. This is not OK for me, starter has to work further.
Btw, I couldn't find any property or setting for ExecuteProcess to _don't_wait_ for the end of the started process.

Back to TProcess.
If I try

  appath:=ExtractFilepath(application.exename);
  AProcess := TProcess.Create(nil);
  AProcess.CommandLine := appath+'hello.exe';
  AProcess.Execute;

It occurs an error, as I wrote before: "Failed to execute hello.exe : 87."
It doesn't matter, if I write "hello2.exe", "anything.exe", I always get "Failed to execute .... : 87"
Regarding to MSDN, I've found only one topic: http://msdn2.microsoft.com/en-us/library/ms932980.aspx
Here, as far as I see, ErrorCode 87 is: The parameter is incorrect.
But which parameter?
Do I need set something more? Checking the TProcess, I cat get more :(

Please help, it would be important to start an application!  :roll:

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
How to start another application in WinCE
« Reply #6 on: April 16, 2007, 09:25:15 pm »
When things get nasty go back to the lowest level: Call the windows API directly to do what you want.

Here is the page about CreateProcess:

http://msdn2.microsoft.com/en-us/library/ms682425.aspx

Then check for error with GetLastError from winapi and show a error message with the error code.

There is probably a page about CreateProcess specific for Windows CE somewhere, you could also check that.

AndieSphinx

  • New Member
  • *
  • Posts: 23
How to start another application in WinCE
« Reply #7 on: April 16, 2007, 11:02:56 pm »
You are the greatest sekel!  :lol:

Code: [Select]
CreateProcess(pwidechar('\program files\test\hello.exe'), Nil, Nil, Nil, False, CREATE_NEW_CONSOLE, Nil, Nil, StartupInfo, ProcessInformation);

works very fine! (and starter.exe can be closed meantime!) I think, the problem should be around the "create_new_console" const... but I don't care :)

Thank you very much!!!  :wink:

Btw, I don't understand something.
If I use a variable as path of the hello.exe, just like:

Code: [Select]
appath:='\program files\test\';
CreateProcess(pwidechar(appath+'hello.exe'), Nil, Nil, Nil, False, CREATE_NEW_CONSOLE, Nil, Nil, StartupInfo,ProcessInformation);


then I get errorcode 2, means: The system cannot find the file specified.
Somehow the CreateProcess couldn't find the exe, altought, appath is the same like the directpath before.

I think, there should be some mistake among string and pwidechar, but I'm a bit lack of knowledge regarding low-level variable types and classes  :roll:

How could I use dinamic-path in the CreateProcess? ( ExtractFilePath(Application.Exename) )

Wanagen

  • New Member
  • *
  • Posts: 30
How to start another application in WinCE
« Reply #8 on: April 17, 2007, 12:08:58 am »
did you try :

appath:='\program files\test\';
appath:=appath+'hello.exe';
CreateProcess(pwidechar(appath), Nil, Nil, Nil, False, CREATE_NEW_CONSOLE, Nil, Nil, StartupInfo,ProcessInformation);

AndieSphinx

  • New Member
  • *
  • Posts: 23
How to start another application in WinCE
« Reply #9 on: April 17, 2007, 09:17:45 am »
Quote from: "Wanagen"
did you try :
appath:='\program files\test\';
appath:=appath+'hello.exe';
CreateProcess(pwidechar(appath), Nil, Nil, Nil, False, CREATE_NEW_CONSOLE, Nil, Nil, StartupInfo,ProcessInformation);


Thanx for the tip, unfortunately, same error :(
Just for sure, I've copied both EXE into a simple directory, in the root, called "Temp", to avoid spaces in the path, so my "appath" become "\Temp\". Its sad, but still not working :(

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
How to start another application in WinCE
« Reply #10 on: April 17, 2007, 09:25:18 am »
Maybe something more manual, like creating a static array of WideChar.

appath: array[0..255] of WideChar;

appath:='\program files\test\';
appath:=appath+'hello.exe';

CreateProcess(@appath, Nil, Nil, Nil, False, CREATE_NEW_CONSOLE, Nil, Nil, StartupInfo,ProcessInformation);

And if still doesn´t work, you could check and try to make sure that appath has a null terminator.

AndieSphinx

  • New Member
  • *
  • Posts: 23
How to start another application in WinCE
« Reply #11 on: April 17, 2007, 11:08:10 am »
Wouw, now it works this way :) Thanx!

New problem:  :)

- if I put a TEdit (edit1) on the form, and try to write something into it (edit1.text:='hello') or
- put a simple TCombobox on the form
I get an error from the WinCE: "Bus error or misaligned data access"

Is it possible, that these controls are not allowed on WinCE? I don't make anything with the combobox, for example, only drop it on the form, and start my application, I get this error...

leandrojcbh

  • Newbie
  • Posts: 5
Re: How to start another application in WinCE
« Reply #12 on: December 05, 2013, 12:16:43 am »
Hello!

I try to use in Lazarus:

(CreateProcess(pwidechar('\program files\test\hello.exe'), Nil, Nil, Nil,
  False, CREATE_NEW_CONSOLE, Nil, Nil, StartupInfo, ProcessInformation));

but i found this error:

unit1.pas(36,17) Error: Identifier not found "CreateProcess"

Help!



engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: How to start another application in WinCE
« Reply #13 on: December 05, 2013, 01:45:52 am »
Hi leandrojcbh, and welcome to the Lazarus forum.

This is an old post from 2007, to ask a question just create a new one please.

I guess you need to add Windows to your uses section:
Code: [Select]
  uses
    ..., Windows;
....
   CreateProcess(...

 

TinyPortal © 2005-2018