[Ecls-list] New User + A Very Simple Win32 GUI example

Brian Algeri bdasp at hotmail.com
Tue Jul 27 12:11:23 UTC 2004


Hi, I am a new ECL user.

I downloaded ECL a couple of days ago and have been playing around with the 
program.

Initial reaction:
Ok, Very nice program!  The documentation and examples are a little sparse, 
but
all of the information is there if you hunt through the mail-list, the 
manuals, and
the source and header files.  I also looked through the x-chat source which 
is a nice
ECL reference.

Some Background:
I started learning Lisp about two months ago after I finished reading 'Ansi 
Common Lisp'.
I have been looking for a lisp implementation which I could easly intergrate 
with C/C++.
ECL seems to do that nicely. I primarally do most of my coding on Windows OS 
machines.

ECL learning apps:
My first orientation applications were a simple Hello world standalone ECL 
application.
Then a simple standalone ECL application which called a external C library - 
DLL
static and object. I then decided to try and embed the interpreter inside a 
Win32 C
application, I created a simple toy application in which the Win32 API 
MessegeBox
function gets its text and caption messages from a Lisp script.

I'll post that code below in case a new user is interested in using ECL from 
a Microsoft
Window application or for future reference.  I UUE encoded the steps in a 
doc to preserve
the format. I used UUD32 to encode the file. The text is also included. I 
would of attached
a zip file but I was unable to access the past mail list attachements and I 
wanted this
to be used as a reference also.

Future projects:
I think my next ECL step-up project is going to be a personal 
contact-information database
used for networking. All done in Common Lisp with the GUI and interface code 
in C using the
Win32 API.

My future project's might be to use ECL as a scripting engine for a text 
based MUD game.
I just finished reading 'MUD Game Programming' where the author uses C, with 
Python as the
scripting engine. I think common lisp would work better. Another might be a 
Roguelike game
using pdcurses or tile graphics using the Allegro game library with lisp 
scripts, A example
of this is the TOME roguelike which uses a LUA scripting engine. Other 
projects might include
other personal database and business apps.

Attachments:
The UUE encoded WinToyProj.doc is included below. Along with the unencoded 
.doc below that
for those who don't know about UUE. Although the formating might be messed 
up.

Again, very nice program, glad I ran acrossed it on my lisp searches. 
Another tool for my
programming arsenal :)



Brian Algeri

_=_
_=_ Part 001 of 001 of file WinToyProj.doc
_=_

begin 666 WinToyProj.doc
M1FEL93H at 5VEN5&]Y4')O:BYD;V,@#0I$97-C.B!!('9E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
M1&5V+T5#3"\-"DQ$3$E"4R`]("UL96-L("UL9VUP("UL9V, at +6QW<V]C:S,R
M("UL;2`M;7=I;F1O=W,-"D5812`](%=I;E1O>2YE>&4-"@T*86QL. at T*"6=C
M8R`M8R!W:6YM<V<N8R`M;R!W:6YM<V<N;PT*"6=C8R`D*$-&3$%'4RD@)"A)
M3D-0051(*2`M=R`M8R!7:6Y4;WDN8R`M;R!7:6Y4;WDN;PT*"6=C8R`M;R`D
M*$5812D@)"A,24)0051(*2!7:6Y4;WDN;R!7:6Y-<V<N;R`D*$Q$3$E"4RD-
M"@ES=')I<"`D*$5812D-"@T*9RLK. at T*"6<K*R`M8R!W:6YM<V<N8R`M;R!W
M:6YM<V<N;PT*"6<K*R`D*$-&3$%'4RD@)"A)3D-0051(*2`M=R`M8R!7:6Y4
M;WDN8R`M;R!7:6Y4;WDN;PT*"6<K*R`M;R`D*$5812D@)"A,24)0051(*2!7
M:6Y4;WDN;R!7:6Y-<V<N;R`D*$Q$3$E"4RD-"@ES=')I<"`D*$5812D-"@T*
M8VQE86XZ#0H)<FT@*BYO#0H)<FT@*BYE>&4-"@T*-2X@($EN('1H92!-<WES
M('-H96QL('1Y<&4@;6%K92!T;R!C;VUP:6QE('5S:6YG(&=C8R!O<B`G;6%K
M92!G*RLG('1O#0H@("`@8V]M<&EL92!U<VEN9R!C*RL-"@T*-BX@(%)U;B!7
M:6Y4;WDN97AE("TM(')E<75I<F5S(&5C;"YD;&PN#0H)(`T*-RX@($9O<B!T
M:&4 at 9G5N(&]F(&ET(&-H86YG92!T:&4@;65S<V%G97,@:6X@;65S<V=E<RYL
M:7-P('1O(&-H86YG92!T:&4-"B`@("!M97-S86=E8F]X('1E>'0@=VET:&]U
M="!H879I;F<@=&\@<F5C;VUP:6QE('1H92!P<F]J96-T("TM(&$@<VEM<&QE
9#0H@("`@<V-R:7!T:6YG(&5N9VEN92X-"@``
`
end



File: WinToyProj.doc
Desc: A very simple example to embed ECL in a C or C++ application
	which uses the Win32 API
	For readability turn wordwrap off.
Rev:  Init -- Brian Algeri -- 7/27/04

Build enviroment:

I am using Mingw 3.3.1 with BinUtils 2.14.90 and MsysDTK 1.0.1 and
Msys 1.0.10 on a WindowsXP machine.  I am using a cvs version of ECL
which I fetched on July-22-04 I used the 'configure -with-cmuformat
--enable-simple-conf' and 'make windows-nsi' option, but I had to
manualy copy libgc.a from the build directory as this file did not
get included in the NSI setup program. A standalone lisp app with
(c:build-program...) would not work without this library.

Some notes on build process:
I am not using the ECL program to generate the c and obj files for
this example. Not needed for this simple project. I did not need to
use the compile-file or c:build-program as I was not using the lisp2c
compiler for this project - not compiling the lisp source to a native
system object file. I created all the files with a text editor and am
using a makefile to build the project. In the past I examined all the
output from c:build-program with numerous setting using :lisp-files and
:ld-flags and :prologue-code and :epilogue-code to see what was outputed
and how everything worked and what went into the generated c file.
Along with looking at the example in the manual and all the code samples
from the mailing list.

This may or may not be optimal as I have only been using ecl for a couple
of days. You can also compile the below lisp file to a .fas file and load
that in the below example instead of the .lisp file or compile the .lisp
file and then load the .fas file within the C program -- both modifications
require small code changes to the below source, not shown.

Here are the project steps:

1. Create a file called Messages.lisp which contains:

;;; the defpackage args need to be capitalized
(defpackage "WIN-TOY-APP"
  (:use "COMMON-LISP")
  (:nicknames "WTA")
  (:export "GET-MSG-TEXT"
	     "GET-MSG-CAPTION"))

(in-package win-toy-app)

(defun get-msg-text ()
  (values "Hello from ECL Lisp"))

(defun get-msg-caption ()
  (format nil "~a" "Lisp App Message")) ;another way to return a str

2. Create a file called WinMsg.c which contains:

#include <windows.h>

int WinMsg(char* msg, char* caption)
{
  MessageBox (0, msg, caption, MB_OK | MB_ICONINFORMATION);
  ExitProcess(0);

  return 0;
}

3. Create a file called WinToy.c which contains:

#include <ecl.h>

extern int WinMsg(char* msg, char* caption);

int main()
{
  cl_object result, result2;

  char* interpreter = "ECL";
  cl_boot(1, &interpreter);

  cl_load(3,
          make_simple_string("Messages.lisp"),
          make_keyword("VERBOSE"),
          Cnil);

  result = cl_funcall(1, c_string_to_object("wta:get-msg-text"));
  result2 = cl_funcall(1, c_string_to_object("wta:get-msg-caption"));

  // The casts are not needed for gcc, only g++
  WinMsg((char*)result->string.self, (char*)result2->string.self);

  return 0;
}

4. Create a makefile which contains:

# modify the include and library paths for your enviroment
# the make program requires true tabs at indentations.
# under the LDLIBS variable -lwsock32 is not needed as the app does not
#   call any winsock functions.  you can remove this library, I included
#   it because this is included by default when you run (c:build-program...)
#   the -mwindows tells the linker to create a Win32 application without
#   the console window. If you leave this flag out the app will still
#   build but the console window will also be displayed -- useful for
#   debugging as printf or cout exprs will output to the console window.
# the makefile can be improved, wrote it fast and simply.

CFLAGS = -g -O2 -fstrict-aliasing -Dmingw32 -O
INCPATH = -I /c/Bin/Dev/ECL/h
LIBPATH = -L /c/Bin/Dev/ECL/
LDLIBS = -lecl -lgmp -lgc -lwsock32 -lm -mwindows
EXE = WinToy.exe

all:
	gcc -c winmsg.c -o winmsg.o
	gcc $(CFLAGS) $(INCPATH) -w -c WinToy.c -o WinToy.o
	gcc -o $(EXE) $(LIBPATH) WinToy.o WinMsg.o $(LDLIBS)
	strip $(EXE)

g++:
	g++ -c winmsg.c -o winmsg.o
	g++ $(CFLAGS) $(INCPATH) -w -c WinToy.c -o WinToy.o
	g++ -o $(EXE) $(LIBPATH) WinToy.o WinMsg.o $(LDLIBS)
	strip $(EXE)

clean:
	rm *.o
	rm *.exe

5.  In the Msys shell type make to compile using gcc or 'make g++' to
    compile using c++

6.  Run WinToy.exe -- requires ecl.dll.

7.  For the fun of it change the messages in messges.lisp to change the
    messagebox text without having to recompile the project -- a simple
    scripting engine.

_________________________________________________________________
Is your PC infected? Get a FREE online computer virus scan from McAfee® 
Security. http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963





More information about the ecl-devel mailing list