Re: Wrapping DLLs in Euphoria (was: [OT] Swap RGB)

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

<Some snippage/>

> Some functions need special constants. Their names are mentioned in the
> documentation, but normally not their value. You'll find the value of
> most constant in the header files of your C compiler (or in some User
> contributions in the Eu archieves, I think).
> 

I often find these values by using Google and looking for two sorts of sites:
1/ VB sites, because they don't use the standard C headers, so the code posted
there needs to define these constants explicitly, which is what we want to see;
2/ www.eiffel.com, and specially the documentation of WEL (roughly equvalent to
win32lib, but part of the standard Windows distribution).

> Of many Windows API functions there are 2 versions: One with an "A" at
> the end (e.g. "DeleteFileA", see below), and another one with a "W" at
> the end. "A" denotes the ANSI version, "W" denotes the Unicode version.
> If you want your program to be able to run on the old Windows 9x
> systems, then it should only wrap the "A" versions.
> 

One of the scarce Eu programs I use is dsearch.exw, in the demo\win32 folder.
Give it the name of a WinAPI routine, and it does a fairly decent job at finding
it in existing system dll's, and reporting the Ex, A or W decoration even if you
didn't supply it. You may find it useful to edit it and add winspool.drv to its
dll list.
Otherwise, if you look at MSDN pages, the "requirements" section at the bottom
of the page will give you a .lib name, the extension of which you only need to
change to .dll.

> 
> ad b)
> You'll need in Euphoria:
> - open_dll()
> - define_c_func()
> - define_c_proc()
> - define_c_var()
> 
> 
> ad c)
> You'll need in Euphoria:
> - c_func()
> - c_proc()
> 
> ... and often also:
> - allocate()
> - allocate_string()
> - peek()
> - poke()
> - free()
> 

Beware: if you use win32lib, it also have its own set of routines,
registerw32Function(), w32Func() and friends. I noticed that using both
registerw32Function() and define_c_func() on the same exported routine results in
c_func() calls failing. If define_c_func() is done first, everything is fine
iirc. I usually avoid mixing the two types of registration.

> The Eu documentation of all these routines is good or very good IMHO.
> A simple example follows:
> }}}
<eucode>
> include dll.e
> include machine.e
> include misc.e                                    -- for constant WIN32
> 
> atom Kernel32
> integer DeleteFile
> 
> if platform() = WIN32 then
>    Kernel32   = open_dll("kernel32.dll")
>    DeleteFile = define_c_func(Kernel32, "DeleteFileA", {C_POINTER}, C_LONG)
> end if
> 
> global function delete_file (sequence fileName)
>    atom lpszFileName, ret
> 
>    if DeleteFile = -1 then
>       return -1                                   -- error
>    end if
> 
>    lpszFileName = allocate_string(fileName)
>    ret = c_func(DeleteFile, {lpszFileName}) - 1
>    free(lpszFileName)
>    return ret                                     -- -1 on error
> end function
> 
> 
> -- Demo
> sequence fileName
> 
> fileName = "trash.txt"
> 
> if delete_file(fileName) = -1 then
>    printf(1, "Can't delete file '%s'.", {fileName})
> else
>    printf(1, "File %s' deleted.", {fileName})
> end if
> if getc(0) then end if
> </eucode>
{{{

> 
> > Moreover, where can I get a description of the other routines in user32.dll?
> 
> On the MSDN website, there are lists where the API functions are sorted
> alphabetically, or grouped by category. ATM I don't know about a list
> where they are grouped by DLL. But as a rough estimate, I think that
> functions that are in the same category often may be in the same DLL,
> too.
> 

If you use win32.hlp from the archive - it is really starting to age -, you'll
notice a "Group" link in the upper bar. This links to a table of related exported
names, pretty useful. For a given routine, the Quickinfo link will tell you,
among other things, in which .lib (read .dll) it is.

Sometimes I also use scanbin.exe (easily available on the net) to explore a dll
and its dependencies. Old but useful.

CChris

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

Search



Quick Links

User menu

Not signed in.

Misc Menu