Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Accessing DLL's generically

3 views
Skip to first unread message

breshears@tek.com Doug Breshears

unread,
Jan 19, 1995, 5:32:13 PM1/19/95
to
Accessing DLL's generically

Please!! does anybody have any code that would allow a person
to take a list of arguments from the command line ( or interpreter )
and call a routine in a DLL that way without previouslly
knowing anything about the DLL.
Of course the arguments would include the file name and routine name
and the arguments that the routine needs,
but how would the program, once it has a reference to the routine,
call it without previously knowing the types of the arguments
and the return type and having them hard coded in?????

I know of two interpreters that claim to have done this.
Cenvi and WinLisp or some such. ( Just read a post about it )

Kenneth Kasajian

unread,
Jan 28, 1995, 5:28:28 PM1/28/95
to

>Accessing DLL's generically

They simply place the arguments on the stack themselves. If you want to do
this yourself, the best way is to look at the .asm or .cod file generated by
your compiler, say visual C++. Select source/assembler output in the
compiler section. Now look at what the compiler compiles for each
different type of parameter. For example, type in the C function:
foo (iX, iY, iZ);
and then see what the compiler did.

The basic idea is that each parameter is pushed on the stack one by one and
then a call is made to the DLL's procedure addresses (returned by
GetProcAddres).

Functions in DLL's are usually written using the Pascal calling convention,
which means that the parameters are pushed in reverse order as they are when
the C calling convention is used.

The return value of the function is returned in DX:AX.

When the function is to return a floating point value, an additional
argument must be placed on the stack which is a pointer into your stack,
just like an automatic variable local to your stack, when the double value
is to be placed. Then the DLL function will return a pointer to this in
DS:AX.

Good luck

Ron Loewy

unread,
Jan 29, 1995, 2:22:15 PM1/29/95
to
In article <kasajianD...@netcom.com>, Kenneth Kasajian wrote:
>
>
> When the function is to return a floating point value, an additional
> argument must be placed on the stack which is a pointer into your
stack,
> just like an automatic variable local to your stack, when the double
value
> is to be placed. Then the DLL function will return a pointer to
this in
> DS:AX.

This is not always true, it is only true if the DLL was created using
Microsoft's tools, Borland's tools place the return of the floating
point value at the top of the floating point chip stack.

>
> Good luck

Ron.
--
Ron Loewy, Author of HLPDK/PA, PASTERP and Interactive Help | rlo...@panix.com

Troy Arie Cobb

unread,
Jan 29, 1995, 7:09:47 AM1/29/95
to
In article <kasajianD...@netcom.com> kasa...@netcom.com (Kenneth Kasajian) writes:
>From: kasa...@netcom.com (Kenneth Kasajian)
>Subject: Re: Accessing DLL's generically
>Date: Sat, 28 Jan 1995 22:28:28 GMT

>Doug Breshears <doug bres...@tek.com> writes:

>>Accessing DLL's generically

>>Please!! does anybody have any code that would allow a person
>>to take a list of arguments from the command line ( or interpreter )
>>and call a routine in a DLL that way without previouslly
>>knowing anything about the DLL.
>>Of course the arguments would include the file name and routine name
>>and the arguments that the routine needs,
>>but how would the program, once it has a reference to the routine,
>>call it without previously knowing the types of the arguments
>>and the return type and having them hard coded in?????
>>I know of two interpreters that claim to have done this.
>>Cenvi and WinLisp or some such. ( Just read a post about it )

I've done this in a prior application by restricting the types that can be
sent. It is pretty straightforward to compose a call this way - you might
want to restrict types to char *, char, int, long, double, float, and void *.
Also allowing returns of these, as well. This covers about 90% of the cases.

Another method is to restrict dll calls to a particular format, say argc-argv.
This allows the dll writer to do what they will with the data but makes it
pretty straightforward for the user of your program to specify the argument
list (which you compose into an argv argument vector).

Of course, the other method is the one previously responded, jump down to asm
and push/pop your own arguments.

Good luck.

- Troy

0 new messages