Two other methods occur to me.
1) You can write a file to disk (a RAM disk for speed) and have the DOS
program read it. It's perfectly legal. It's inelegant, clumsy, awkward and
slow, so in that sense it is compatible with Windows.
2) You can write a DOS TSR or other program which sets aside a known "mail
box" in memory and communicate through that. The two criteria you need to
satisfy are A) allocate some memory and B) know in absolute address terms
where the memory is and announce to the "co-program" where it is. This is a
little more on the shady side.
---------------
Kevin Appert
Senior Research Engineer
Lockheed Martin
Palo Alto Advanced Technology Center
> ----------
> From: SF Talk[SMTP:sftalk_at_forth.com]
> Reply To: SF Talk
> Sent: Monday, June 07, 1999 8:29 AM
> To: SF Talk
> Subject: Re: Running external program?
>
> Date: Sun, 6 Jun 1999 22:05:59 -0500
> From: "Gene LeFave" <gene_at_tekdata.com>
> Subject: Re: Running external program?
>
> The only legal way to send a message to a running DOS program is
> using the clipboard.
>
> Gene
>
> > Date: Mon, 7 Jun 1999 00:23:32 +0100
> > From: "Charles Melice" <mail_at_forthcad.com>
> > Subject: Re: Running external program?
> >
> > Robert,
> >
> > > If this is not too difficult --- for my first program, I would like
> > > to pass some numerical values to an external Windows or DOS program,
> > > execute the external program, then receive the numerical output from
> > > that program back in SwiftForth.
> >
> > to an external Windows
> > =====================> You can pass numeric value to an external Windows
> using the same registered
> > Windows message for the sender and the receiver:
> "...RegisterWindowMessage
> > function defines a new window message that is guaranteed to be unique
> > throughout the system. The returned message value can be used when
> calling
> > the SendMessage or PostMessage function...."
> >
> >
> > In sender and receiver, you register your message:
> >
> > 0 value MY_MSG
> > 1 IMPORT: RegisterWindowMessage ( szMsg -- MY_MSG )
> > ...
> > z" MY_SWIFT_MESSAGE" RegisterWindowMessage to MY_MSG
> >
> >
> >
> > Then, in sender use wParam and/or lParam to record the value you want to
> > send...
> >
> > HWND_BROADCAST MY_MSG wParam lParam SendMessage drop
> >
> > In receiver, you get the value when receiving your MY_MSG:
> >
> > [SWITCH OnMessage dropDefault
> > MY_MSG RUN: ... here you get your number ...
> > MY_MSG MY_NOTIFY_SEND_BACK ... SendMessage
> ....
> > ;
> > WM_COMMAND RUN: ........
> > WM_NOTIFY RUN: .......
> > WM_PAINT RUNS OnPaint
> > SWITCH]
> >
> > > ........back in SwiftForth.
> >
> > In sender, it look the same:
> >
> > [SWITCH OnMessage dropDefault
> > MY_MSG RUN: ... here back in SwiftForth ...
> > ...
> > ...
> > SWITCH]
> >
> >
> > to a DOS program ?
> > ===============> Sorry! I don't know how to send messages to a DOS
> program. (I never need
> > that, its not legal and probably not easy)
> >
> > Charles
> >
> > ----------
> > > De : SF Talk <sftalk_at_forth.com>
> > > A : SF Talk <sftalk_at_forth.com>
> > > Objet : Running external program?
> > > Date : dimanche 6 juin 1999 8:16
> > >
> > > Date: Sat, 05 Jun 1999 23:48:53 -0700
> > > From: Robert Tkoch <robert_at_starcenter.com>
> > > Subject: Running external program?
> > >
> > > Greetings!
> > >
> > > I recently purchased the SwiftForth CD, and have just begun to play
> with
> > > SwiftForth. I am fairly proficient at Forth, but know almost nothing
> > > about Windows 95.
> > >
> > > If this is not too difficult --- for my first program, I would like
> > > to pass some numerical values to an external Windows or DOS program,
> > > execute the external program, then receive the numerical output from
> > > that program back in SwiftForth.
> > >
> > > I skimmed the SwiftForth manual, but did not see how to do this. Can
> > > anyone suggest where to learn this? Thanks.
> > >
> > > Sincerely,
> > >
> > > Robert Tkoch
> > >
> > >
> > >
> >
> >
> >
>
>
>
.
>From ir230_at_sdcc3.ucsd.edu Mon Jun 7 10:38:26 1999
To: sftalk_at_forth.com
Message-Id: <m0000393_at_gerd.forthinc.com>
Date: Mon, 7 Jun 1999 10:38:26 -0700 (PDT)
From: john wavrik <ir230_at_sdcc3.ucsd.edu>
Subject: Re: [sftalk] Running external program?
Robert,
I also find the need of having Forth communicate with
external programs. Here is a method I am using with
SwiftForth at the moment. It may not be exactly what you
want, since I have Forth and the other application
communicate by disk files rather than shared memory.
This method works for an essentially batch type of
communication: I wrote a "print to file" module and use
SwiftForth to generate a script file for the other application.
The other application, in turn, produces an output file in a
form that can either be "included" into SwiftForth, or else
contains data that SwiftForth must read and parse.
You can either have SwiftForth generate the script file
which you manually load into the other application, or you can
automate the process by having SwiftForth execute the other
application using the word $EXEC (inspired by Win32Forth)
---------------------
2 WINPROC: WinExec
: $EXEC ( a -- f ) \ f=0 means success
DUP COUNT + OFF \ null terminate string
1+ SW_SHOWNORMAL WinExec 31 <= ;
$EXEC takes the address of a counted string
(which contains the full path name of the
application you want to run and any command line
paramaters).
Notice that $EXEC must add a zero to the end of
the string -- so the string should be in a buffer
that has room at the end.
----------------------
Example: c" d:\fpc\f.exe fload loadpre" $EXEC
can either be used interpretively or put
in a word -- it loads my F-PC and starts it
running with the file "loadpre"
$EXEC can be used to get the other application running,
read the command file, produce output, and then close.
Since Windows is multi-tasking one could also start
SwiftForth and the application simultaneously -- and have
them exchange information by using files. (This would avoid
using $EXEC to start the application -- but would require
that you can equip the other application to deal with file
exchange.)
[In the old days, I had Forth communicate with an
application on another machine by using serial
communications. This also might be a possibility to explore]
John J Wavrik
jjwavrik_at_ucsd.edu Dept of Math 0112
Univ of Calif - San Diego
La Jolla, CA 92093-0112
\ ==================================================
\ Start of pfile.f
\ ==================================================
\ Attempt at a PFILE command by
\ redirecting EMIT CR and TYPE
0 VALUE PfileID
VARIABLE Printing Printing OFF
VARIABLE Echo Echo ON
VARIABLE '_Oemit
VARIABLE '_Otype
VARIABLE '_Ocr
CREATE CRLF$ 2 C, 13 C, 10 C, 0 C,
CREATE FileBuf 257 ALLOT ALIGN
79 VALUE WrapAt
: FileBuf.Init
FileBuf 257 ERASE ;
: FileCR ( -- )
Echo @ IF '_Ocr @EXECUTE THEN
Printing @
IF FileBuf COUNT PfileID WRITE-FILE DROP
CRLF$ COUNT PfileID WRITE-FILE DROP
FileBuf.Init THEN ;
: FileFlush
FileBuf C@
IF FileCR THEN ;
: FileCheck ( n -- )
Printing @
IF FileBuf C@ + WrapAt >
IF FileFlush THEN
THEN ;
: FileEmit ( char -- )
Echo @ IF DUP '_Oemit @EXECUTE THEN
Printing @
IF 1 FileCheck
FileBuf COUNT + C!
FileBuf DUP C@ 1+ SWAP C!
ELSE DROP THEN ;
: FileType ( addr cnt -- )
Echo @ IF 2DUP '_Otype @EXECUTE THEN
Printing @
IF DUP FileCheck
DUP >R
FileBuf COUNT + SWAP CMOVE
FileBuf DUP C@ R> + SWAP C!
ELSE 2DROP THEN ;
: Pclose ( -- ) \ Close the print file
FileFlush
PfileID CLOSE-FILE abort" error closing pfile" cr
'_Oemit @ 'EMIT !
'_Otype @ 'TYPE !
'_Ocr @ 'CR !
Printing OFF 0 TO PfileID ;
: $Pfile ( addr cnt -- ) \ Open a printfile
PfileID IF PfileID Pclose THEN
R/W CREATE-FILE
ABORT" File not created "
TO PfileID FileBuf.Init
'EMIT @ '_Oemit !
'TYPE @ '_Otype !
'CR @ '_Ocr !
['] FileEmit 'EMIT !
['] FileType 'TYPE !
['] FileCR 'CR ! ;
: Pfile ( | name )
BL WORD COUNT $Pfile ;
: Print \ Print command line
Printing ON INTERPRET Printing OFF Echo ON ;
: QPrint \ Print command line quietly
Echo OFF Printing ON INTERPRET Printing OFF Echo ON ;
\ ==================================================
\ End of pfile.f
\ ==================================================
Usage
Pfile <name> or c" <filename>" $Pfile
this opens the output file
PClose
this closes the input file
Print <line to execute>
used interpretively to print output
from a command line
FileType, FileEmit, FileCR
used like TYPE, EMIT and CR
Printing
variable -- turn ON to direct output to file
turn OFF to direct to terminal
.
>From gene_at_tekdata.com Sun Jun 6 22:05:59 1999
To: sftalk_at_forth.com
Message-Id: <m0000394_at_gerd.forthinc.com>
Date: Mon, 7 Jun 1999 21:41:07 +0100
From: "Charles Melice" <mail_at_forthcad.com>
Subject: Re: [sftalk] Running external program?
Gene,
You say: "The only legal way to send a message to a running DOS program is
using the clipboard."
I know its possible to use the clipboard to store _what_ we want to send,
but how to use the clipboard to send a message ?
Regards,
Charles
----------
De : SF Talk <sftalk_at_forth.com>
A : SF Talk <sftalk_at_forth.com>
Objet : Re: Running external program?
Date : lundi 7 juin 1999 16:29
Date: Sun, 6 Jun 1999 22:05:59 -0500
From: "Gene LeFave" <gene_at_tekdata.com>
Subject: Re: [sftalk] Running external program?
The only legal way to send a message to a running DOS program is
using the clipboard.
Gene
.
>From rvn_at_forth.com Sun Jun 6 12:24:37 1999
To: sftalk_at_forth.com
Message-Id: <m0000395_at_gerd.forthinc.com>
Date: Sun, 6 Jun 1999 12:24:37 -0700
From: " Rick VanNorman" <rvn_at_forth.com>
Subject: Appologies to all!
All,
Sorry for the snafu with the bounced mail. The list manager
program was configured incorrectly -- and is now fixed.
Rick VanNorman
.
>From gene_at_tekdata.com Mon Jun 7 04:54:45 1999
To: sftalk_at_forth.com
Message-Id: <m0000396_at_gerd.forthinc.com>
Date: Mon, 7 Jun 1999 04:54:45 -0500
From: "Gene LeFave" <gene_at_tekdata.com>
Subject: Re: [sftalk] Running external program?
Charles,
I realize now that I shouldn't have written "the only", that was just a
slip of the keyboard. I meant to say "a way that is blessed by
Microsoft"
In the DOS program there is a series of interupt calls Interrupt 2F,
Function 17H, Subfunctions 0..09 , They provide an interface to
WINOLDAP, and provide access to the windows clipboard.
(Reference: PC Interrupts, 1991, Ralf Brown and Jim Kyle)
Basicly you can create your own type of clipboard data and pass it
back and forth. It's not pretty, and I haven't tried it in years. There
was an article in Dr Dobbs some time ago. This was originally for
Win 3.1, I assume it will work on win 95 and NT..
> Date: Mon, 7 Jun 1999 21:41:07 +0100
> From: "Charles Melice" <mail_at_forthcad.com>
> Subject: Re: Running external program?
>
> Gene,
>
> You say: "The only legal way to send a message to a running DOS program is
> using the clipboard."
>
> I know its possible to use the clipboard to store _what_ we want to send,
> but how to use the clipboard to send a message ?
>
> Regards,
> Charles
>
>
> ----------
> De : SF Talk <sftalk_at_forth.com>
> A : SF Talk <sftalk_at_forth.com>
> Objet : Re: Running external program?
> Date : lundi 7 juin 1999 16:29
>
> Date: Sun, 6 Jun 1999 22:05:59 -0500
> From: "Gene LeFave" <gene_at_tekdata.com>
> Subject: Re: Running external program?
>
> The only legal way to send a message to a running DOS program is
> using the clipboard.
>
> Gene
>
>
>
.
>From mail_at_forthcad.com Tue Jun 8 19:15:13 1999
To: sftalk_at_forth.com
Message-Id: <m0000397_at_gerd.forthinc.com>
Date: Tue, 8 Jun 1999 19:15:13 +0100
From: "Charles Melice" <mail_at_forthcad.com>
Subject: Re: [sftalk] Running external program?
Running a DLL-IMPORTED function is easy, Here is another idea, to run a
SwiftForth word from a 'C' DLL.
I don't know how to _NOT_ use 'CallWindowProc' to have less or more
parameters on the stack...
In SwiftForth
-------------
LIBRARY C_DLL
1 IMPORT: SetCallBack ( xt -- 0 )
0 IMPORT: TEST ( -- 0 )
\ Pseudo WindowProc
:noname WPARAM 0 ?DO bell 300 ms LOOP ; 4 CB: RemoteWord
RemoteWord SetCallBack drop
\ 'TEST' execute 'RemoteWord' from the C_DLL.DLL library.
TEST drop
In C_DLL (STDCALL)
------------------
WNDPROC RemoteWord=0;
void SetCallBack(WNDPROC c) // exported
{
RemoteWord=c;
}
LIB void Test() // exported
{
CallWindowProc( RemoteWord, 0, 0, 3, 0 );
}
\ EOF
Charles
----------
> De : SF Talk <sftalk_at_forth.com>
> A : SF Talk <sftalk_at_forth.com>
> Objet : Running external program?
> Date : dimanche 6 juin 1999 8:16
>
> Date: Sat, 05 Jun 1999 23:48:53 -0700
> From: Robert Tkoch <robert_at_starcenter.com>
> Subject: Running external program?
.
>From mail_at_forthcad.com Wed Jun 9 12:29:15 1999
To: sftalk_at_forth.com
Message-Id: <m0000398_at_gerd.forthinc.com>
Date: Wed, 9 Jun 1999 12:29:15 +0100
From: "Charles Melice" <mail_at_forthcad.com>
Subject: Snipped: ENUM{ named, economical and encapsulated.
\ -------------------------------------------------
\ Encapsuled ENUM
\ usage: ENUM{ : x : y : z } drop
\ -------------------------------------------------
[DEFINED] HASHSTR> 0= [IF]
: LROT ( x1 u -- x2 )
2dup lshift >R 32 swap - rshift R> OR ;
: HASHSTR ( addr u -- uh )
tuck over chars + swap \ len addr+len addr
?DO 5 lrot i c@ BL or BL xor BL 1- - xor LOOP
dup 0> ?EXIT invert ;
: HASHSTR> ( <<name>> -- hcode )
bl word count hashstr ;
[THEN]
vocabulary (enum)
: ENUM{ ( <<enumname>> -- body-addr 0 )
also (enum) 0 Create here dup off swap ;
also (enum) definitions
: FindEnum ( addr h -- enum true | false )
>r
BEGIN @+ dup WHILE \ s: a+4 h
r@ = IF \ s: a+4
@ r> drop \ s: enum#
true EXIT \ s: enum# true
THEN
cell+
REPEAT
r> 3drop false ;
: } ( body-addr n -- n )
0 , nip previous IMMEDIATE
DOES>
hashstr> FindEnum 0= abort" not found"
state @ 0= ?EXIT postpone literal ;
: : ( body-addr n <<name>> -- body-addr n+1 )
HASHSTR> >r
here off over r@ FindEnum abort" enum collision"
r> , dup , 1+ ;
previous definitions
\ EOF
\ --test--
\ enum{ num : zero : one : two : three : four : five }
________
Charles Melice
mail_at_forthcad.com
http://www.forthcad.com
.
>From mikek_at_metretek.com Wed Jun 9 11:29:08 1999
To: sftalk_at_forth.com
Message-Id: <m0000399_at_gerd.forthinc.com>
Date: Wed, 9 Jun 1999 11:29:08 -0400
From: Michael Kemper <mikek_at_metretek.com>
Subject: Re: [sftalk] Running external program?
While we're on the topic...does anyone know how to spawn a program that's
not an executable such as a batch file (or any registered windows file
type). I think it might be related to using 'start', but can't figure it
out.
Any help is appreciated,
Mike Kemper
.
Received on Mon Jun 07 1999 - 09:15:45 PDT
Subscribe to our e-mail list service. It's free for all SwiftForth and SwiftX users!
This archive was generated 09-Feb-2012. Archive updated nightly.