From: Steven Vere
Subject: Re: LispWorks for Windows question
Date: 
Message-ID: <72psli$6cg@sjx-ixn9.ix.netcom.com>
In
<··················································@library-proxy.airne
s.net> "Marc Battyani" <·············@csi.com> writes: 
>
>
>Marcus Shaw wrote in message ...
>>Hi All,
>>
>>I use LispWorks v 4.0.1 under NT 4 and would like to be able to
>>run an external program from a LispWorks application.
>>
>>Something I could use like this would be great...
>>
>>USER> (run-program "dir > files")
>>
>>(This is just an example - I know about the directory function!)
>>
>>Does LispWorks include any such function?  I had a look at
>>the DDE package to see if I could make LispWorks open a
>>Command Prompt window, run something in it then close it again,
>>but that section of the manual required a deeper knowledge
>>of Windows programming than I have.
>
>
>(fli:define-foreign-function (%win-exec "WinExec") ((lpcmdline :pchar)
>(ucmdshow :ulong))
> :langage :c
> :calling-convention :stdcall
> :result-type :long
> :module "kernel32.dll")
>
>(defun win-exec (command)
>  (fli:with-dynamic-foreign-objects
>   ()
>   (%win-exec (fli:convert-to-dynamic-foreign-string command
>:external-format win32:*multibyte-code-page-ef*) w32::SW_SHOWNORMAL)))
>
>(win-exec "notepad")

   I tried compiling this on Lispworks for Windows under NT and got
some error messages:

"Illegal type specifier :pchar" 

"Illegal type specifier :ulong"

"no package named W32"

By changing :pchar to (:pointer :char) and :ulong to (:unsigned :long),
I was able to get the first two compiler messages to go away.  However,
I am not sure these are a correct replacement, and the problem with W32
being an unknown package remains.

Marc, can you offer any help here?

Steven Vere

From: Marc Battyani
Subject: Re: LispWorks for Windows question
Date: 
Message-ID: <61B4079AB7553DD1.F1881CF509EAA93F.1F70CE941909E1DB@library-proxy.airnews.net>
W32 is the package where I define WIN32 constants and functions

SW_SHOWNORMAL is a constant

(defconstant SW_SHOWNORMAL       1)

you also have

(defconstant SW_MAXIMIZE         3)
(defconstant SW_MINIMIZE         6)

Good luck...

Marc Battyani
From: Steven Vere
Subject: Re: LispWorks for Windows question
Date: 
Message-ID: <72q539$o3@dfw-ixnews4.ix.netcom.com>
In <··········@sjx-ixn9.ix.netcom.com> ····@ix.netcom.com(Steven Vere)
writes: 
>
>In
><··················································@library-proxy.airn

>s.net> "Marc Battyani" <·············@csi.com> writes: 
>>
>>
>>Marcus Shaw wrote in message ...
>>>Hi All,
>>>
>>>I use LispWorks v 4.0.1 under NT 4 and would like to be able to
>>>run an external program from a LispWorks application.
>>>
>>>Something I could use like this would be great...
>>>
>>>USER> (run-program "dir > files")
>>>
>>>(This is just an example - I know about the directory function!)
>>>
>>>Does LispWorks include any such function?  I had a look at
>>>the DDE package to see if I could make LispWorks open a
>>>Command Prompt window, run something in it then close it again,
>>>but that section of the manual required a deeper knowledge
>>>of Windows programming than I have.
>>
>>
>>(fli:define-foreign-function (%win-exec "WinExec") ((lpcmdline
:pchar)
>>(ucmdshow :ulong))
>> :langage :c
>> :calling-convention :stdcall
>> :result-type :long
>> :module "kernel32.dll")
>>
>>(defun win-exec (command)
>>  (fli:with-dynamic-foreign-objects
>>   ()
>>   (%win-exec (fli:convert-to-dynamic-foreign-string command
>>:external-format win32:*multibyte-code-page-ef*)
w32::SW_SHOWNORMAL)))
>>
>>(win-exec "notepad")
>
>   I tried compiling this on Lispworks for Windows under NT and got
>some error messages:
>
>"Illegal type specifier :pchar" 
>
>"Illegal type specifier :ulong"
>
>"no package named W32"
>
>By changing :pchar to (:pointer :char) and :ulong to (:unsigned
:long),
>I was able to get the first two compiler messages to go away. 
However,
>I am not sure these are a correct replacement, and the problem with
W32
>being an unknown package remains.
>
>Marc, can you offer any help here?
>
>Steven Vere

   I have had some e-mail exchanges with Marc Battyani, who filled in
some gaps in the original code to get it to work.  Here is a complete
set of declarations and code which works for me on Lispworks for
Windows under NT:

;------------------------------------------------------------------
(fli:define-c-typedef :uchar  (:unsigned :char))
(fli:define-c-typedef :pchar  (:pointer :uchar))
(defconstant SW_SHOWNORMAL   1)
(defconstant SW_MAXIMIZE     3)
(defconstant SW_MINIMIZE     6)

(fli:define-foreign-function (%win-exec "WinExec") 
   ((lpcmdline :pchar)
    (ucmdshow (:unsigned :long)))
 :langage :c
 :calling-convention :stdcall
 :result-type :long
 :module "kernel32.dll")

(defun win-exec (command)
  (fli:with-dynamic-foreign-objects
   ()
   (%win-exec (fli:convert-to-dynamic-foreign-string command
:external-format win32:*multibyte-code-page-ef*) SW_SHOWNORMAL)))
;------------------------------------------------------------------

After compiling this, (win-exec "notepad") calls up a notepad window.

Replacing SW_SHOWNORMAL with SW_MAXIMIZE or SW_MINIMIZE in the
definition of win-exec controls whether the window appears maximized or
minimized.

Extreme thanks to Marc Battyani for supplying this valuable function
for us.

Steven Vere