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 )
>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
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
>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