April 27, 2024, 12:30:04 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Running an exernal program

Started by rkstuart, December 27, 2006, 03:37:20 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

rkstuart

Maybe I've missed it in the documentation but I'm trying to run an external program, specifically bring up a command prompt box.  Since I didn't see anything in the regular docs under 'shell", 'execute' or 'run', these being the typical calls to do this, I browsed through the includes and found _ShellExecute in 'Windows.inc', so I've tried adding $INCLUDE "windows.inc" to the top of my program and I've added the line:
_ShellExecute(win,"Open","CMD.EXE","","C:Windows\System32",1), with and without a variable to receive a return value, but I get the error message 'no appropriate conversion exists - )' with or without a smiley face at the end depending on whether or not I'm using the variable.  I even tried just putting in my own function with a different name but got the same result.  Any ideas about where to go from here?

Thanks, Ron

Copex

this help ??

QuoteSYSTEM

SYSTEM(command as STRING, OPT param as STRING)

Description
Runs another executable.

Parameters
command - Executable to run.
param - Parameter for executable.

Return value
None

Remarks
Command must be full pathname to executable or the executable needs to be in the system path.

Example usage
.SYSTEM "notepad.exe" , "c:\\mydocs\\prog.txt"

-
I really should learn how to use a spell checker! though im not sure how it will help someone who can not spell?
-
Except where otherwise noted, content Posted By Copex is
licensed under a Creative Commons Attribution 3.0 License

http://creativecommons.org/licenses/by/3.0/

Copex

December 27, 2006, 04:19:07 PM #2 Last Edit: December 27, 2006, 04:25:55 PM by Copex
More out of intrest than requirement as it dose more or less the same as the "System()" as you went down the
ShellExecute route here os a working example...


' "How to Call the ShellExecute Windows API Function" http://support.microsoft.com/kb/238245
' The example below will open the command window by runing cmd.exe with the Param /s/k dir
' and will list the directory c:\\ as set by lpszDir, set to "0" or "NULL" and it shows the exe path.
' scott

$include "windows.inc"

openconsole
Print "open Command window"
Execute("cmd","/S/K dir")
Print "Press any key to exit"
do:until inkey$ <> ""
closeconsole
end

sub Execute(lpszFile as string, opt lpszParams as string)

int hwnd,fsShowCmd
string lpszOp

lpszOp = "Open"

'Path or "NULL"
lpszDir = "C:\\"

fsShowCmd = 1

_ShellExecute(hwnd,lpszOp,lpszFile,lpszParams,lpszDir,1)
return
endsub

/*
ParameterÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  Description
---------------------------------------------------------------------------

ÂÃ,  ÂÃ, hwndÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, Identifies the parent window.

ÂÃ,  ÂÃ, lpszOpÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, A string specifying the operation to perform. This
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  string can be "open" or "print".

ÂÃ,  ÂÃ, lpszFileÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, Points to a string specifying the file to open.

ÂÃ,  ÂÃ, lpszParamsÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, Points to a string specifying parameters passed to
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  the application when the lpszFile parameter
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  specifies an executable file. If lpszFile points to
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  a string specifying a document file, this parameter
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  is NULL.

ÂÃ,  ÂÃ, lpszDirÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  Points to a string specifying the default
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  directory.

ÂÃ,  ÂÃ, fsShowCmdÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  Specifies whether the application window is to be
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  shown when the application is opened. This
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  parameter can be one of the following values:

ÂÃ,  ÂÃ,  ÂÃ,  ValueÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  Meaning
ÂÃ,  ÂÃ,  ÂÃ,  ---------------------------------------------------------------------

ÂÃ,  ÂÃ,  ÂÃ,  0ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  Hides the window and passes activation to another
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, window.

ÂÃ,  ÂÃ,  ÂÃ,  1ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  Activates and displays a window. If the window is
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, minimized or maximized, Windows restores it to its
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, original size and position (same as 9).

ÂÃ,  ÂÃ,  ÂÃ,  2ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  Activates a window and displays it as an icon.

ÂÃ,  ÂÃ,  ÂÃ,  3ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  Activates a window and displays it as a maximized
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, window.

ÂÃ,  ÂÃ,  ÂÃ,  4ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  Displays a window in its most recent size and
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, position. The window that is currently active remains
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, active.

ÂÃ,  ÂÃ,  ÂÃ,  5ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  Activates a window and displays it in its current
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, size and position.

ÂÃ,  ÂÃ,  ÂÃ,  6ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  Minimizes the specified window and activates the
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, top-level window in the system's list.

ÂÃ,  ÂÃ,  ÂÃ,  7ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  Displays a window as an icon. The window that is
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, currently active remains active.

ÂÃ,  ÂÃ,  ÂÃ,  8ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  Displays a window in its current state. The window
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, that is currently active remains active.

ÂÃ,  ÂÃ,  ÂÃ,  9ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  Activates and displays a window. If the window is
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, minimized or maximized, Windows restores it to its
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, original size and position (same as 1).

Back to the top

*/

-
I really should learn how to use a spell checker! though im not sure how it will help someone who can not spell?
-
Except where otherwise noted, content Posted By Copex is
licensed under a Creative Commons Attribution 3.0 License

http://creativecommons.org/licenses/by/3.0/

Ionic Wind Support Team

And I will go one step further and show what's wrong with your orignal:

_ShellExecute(win,"Open","CMD.EXE","","C:Windows\System32",1)

ShellExecute is an API function from a DLL, it knows nothing about Emergence BASIC so the first paramter must be a handle to a window, not a WINDOW variable from Emergence.  The WINDOW type is a UDT whose first member is the handle to the window, that member is appropriately named 'hwnd'. 

_ShellExecute(win.hwnd,"Open","CMD.EXE","","C:Windows\System32",1)

Next problem.  In Emergence the single backslash in a string is an escape character, as listed in the users guide under the topic "Language->Constants and Literals" which also shows to get a backslash in a string you need to use \\.  The path you presented is also wrong since it is missing a backslash as well.  So now the line looks like this:

_ShellExecute(win.hwnd,"Open","CMD.EXE","","C:\\Windows\\System32",1)

Have fun,
Paul.
Ionic Wind Support Team

rkstuart

Thanks to both of you for pointing me in the right direction and explaining what was wrong initially.  I knew I needed to pass a handle to the function but mistakenly assumed that I was since I didn't see anything in the docs about retrieving a handle.  That thing about assumptions.  The only thing listed under handle was relating to menus.  Anyway, thanks again.