RE: Win9x/2k/NT calling DLLs

From: Kelly Murray <MurrayKelly_at_ACMSystems.com>
Date: Fri, 10 Nov 2000 15:38:05 -0800

Thanks for the tips. I was able to write some simple
C interfaces as "extensions" to STk which called the DLL entry points
that were statically linked to the STk system.

How many people are using STk ??
The mailing list sure is quiet.

kelly


-----Original Message-----
From: Ian Wild [mailto:ian_at_cfmu.eurocontrol.be]
Sent: Thursday, November 09, 2000 1:31 AM
To: 'stk_at_kaolin.unice.fr'
Subject: Re: Win9x/2k/NT calling DLLs


Kelly Murray wrote:
>
> Hello,
> I'm looking for a scripting language to run some automated tests,
> and STk looks just like what I want. Except I need to link to some
> external DLLs and invoke some routines in them. I didn't see any
> documentation on how to do this, and the FFI docs say the C interface
> doesn't work under Windows.

I once had to do something horribly similar, or similarly horrible,
interfacing random Win3.1 and Win95 DLLs to an interpreter. The basic
strategy I took is as follows:

-o- The high-level code (Scheme, in your case) takes responsibility
for creating a single string containing the bytes needed as parameters.
I had to add various primitives, like GetAddress, IntToBytes, ...,
to make this work. It also helps if you can get the GC to
look the other way for a while.

-o- The C code takes the string created above, the DLL name, and
the entry point name. Do the necessary LoadLibrary() and/or
GetProcAddress() nonsense. Now we come to the tricky bit.

-o- Wrap the single string parameter in a struct containing an
array of unsigned char

-o- switch (setjmp()) {case 0:

-o- Call the DLL entry point with this struct as its only parameter.
This takes care of getting an arbitrary number of parameters onto
the call stack. Squirrel away the return value. Now we come to the
VERY tricky bit.

-o- We don't know for sure how many bytes are left on the stack
when the DLL returns, but we DO know that we rememebered to call
setjmp() just before the DLL. Now we do a longjmp(1)

-o- case 1: Whew! The stack has magically cleaned itself up!

-o- Return to Scheme.


If anyone wants the code, I can probably dig it out, but I haven't
had anything to compile it with for several years now, so it might
be a bit dusty.


imw
Received on Sat Nov 11 2000 - 00:38:14 CET

This archive was generated by hypermail 2.3.0 : Mon Jul 21 2014 - 19:38:59 CEST