Re: A Stupid Question : A DLL Wrapper

new topic     » goto parent     » topic index » view thread      » older message » newer message

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

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu