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

Brian Algeri bdasp at hotmail.com
Tue Jul 27 12:57:43 UTC 2004


Text of the example doc:

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.

_________________________________________________________________
Overwhelmed by debt? Find out how to ‘Dig Yourself Out of Debt’ from MSN 
Money. http://special.msn.com/money/0407debt.armx





More information about the ecl-devel mailing list