1. A Stupid Question : A DLL Wrapper
If a DLL function accepts a string, how do I write the defining code?
Alex
2. Re: A Stupid Question : A DLL Wrapper
- Posted by Juergen Luethje <j.lue at gmx.de>
Oct 23, 2005
-
Last edited Oct 24, 2005
Alex Chamberlain wrote:
> If a DLL function accepts a string, how do I write the defining code?
It depends, e.g. whether the DLL was written in C or in Euphoria. You
should have a documentation for the concerning DLL, or at least for the
function you are interested in.
Here is an example for wrapping the function "DeleteFileA", which is in
"kernel32.dll" as part of the Windows API. It accepts a string (= the
concerning file name) as parameter.
include dll.e
include machine.e
constant
KERNEL32 = open_dll("kernel32.dll"),
DEL_FILE = define_c_func(KERNEL32, "DeleteFileA", {C_POINTER}, C_LONG),
ERROR = -1
global function del_file (sequence fileName)
atom lpFilename, ret
if DEL_FILE != ERROR then
lpFilename = allocate_string(fileName)
ret = c_func(DEL_FILE, {lpFilename}) - 1
free(lpFilename)
return ret -- -1 on error
end if
return ERROR
end function
-- Demo
sequence file
file = "test.txt"
puts(1, "'" & file & "' ")
if del_file(file) then
puts(1, "not deleted.")
else
puts(1, "successfully deleted.")
end if
Regards,
Juergen
3. Re: A Stupid Question : A DLL Wrapper
- Posted by Matt Lewis <matthewwalkerlewis at gmail.com>
Oct 23, 2005
-
Last edited Oct 24, 2005
Alex Chamberlain wrote:
>
> If a DLL function accepts a string, how do I write the defining code?
>
You have to pass a pointer to the string allocated in memory (plus a zero
at the end of the string, which allocate_string() does for you).
Assuming you had something like this in the dll:
void foo( lpzstring * bar )
You would wrap it like this:
include machine.e
include dll.e
constant
foo_dll = open_dll( "foo.dll" ),
foo = define_c_proc( foo_dll, "foo", {C_POINTER} )
global procedure Foo( sequence bar )
atom bar_ptr
bar_ptr = allocate_string( bar )
c_proc( foo, {bar_ptr})
free( bar_ptr )
end procedure
Matt Lewis
4. Re: A Stupid Question : A DLL Wrapper
Thanks Matt & Juergen
I have actually used another library (ab_dll) to do it for me!
Alex
5. Re: A Stupid Question : A DLL Wrapper
Just posted the results of my questions - a "UCalc Wrapper and Calculator" (for
Windows).
"DLL Wrapper of ucalc32.dll - a very fast and accurate maths expressions
evaluator. Also included is a calculator that uses the program and the original
download zip from ucalc.com, which includes wrappers for C++, VB and Delphi -
still have alot to do."
Thanks alot,
Alex