How to use a windows dll in linux

Troy Rollo wine at troy.rollo.name
Thu Aug 31 18:32:28 CDT 2006


On Friday 01 September 2006 03:52, Jeremy White wrote:
> Dan Kegel wrote:
> > On 8/30/06, Mark Smith <mesmith.18885136 at bloglines.com> wrote:

> >> I have a windows dll and header files. I want to make a library that I
> >> can link to and use on linux. What are the steps required to do this?
> >
> > Sorry, you can't.   Not at the moment, anyway.  That's on the to-do list.
>
> It's not that black and white, is it?
>
> I believe you can, and it actually works reasonably well.  BUT there's
> a big catch - you have to make your program into a Winelib application.

Actually there's probably an easier way - a scheme I've been considering is 
one involving a crt0.o designed to load Wine (essentially making the native 
executable an equivalent of wine-pthread with other stuff), then start a 
Winelib program whose entry point calls back into a second entry point in the 
original executable. This scheme ought to work without any modifications to 
the core of Wine. We also wouldn't need to be reserving any memory areas, so 
the trimmed down operating system entry point of the Wine executable might be 
something like this:

int __wine_startup( int argc, char **argv, char **envp)
{
    char error[1024];
    char winelib_argv[3];
    char wine_entry_addr[sizeof(void *) * 2 + 1];

    __wine_argc = argc;
    __wine_argv = argv;
    __wine_envp = envp;

    wine_pthread_set_functions( &pthread_functions, 
sizeof(pthread_functions) );

    sprintf(wine_entry_addr, "%p", __wine_entry);
    winelib_argv[0] = "execallback.exe.so";
    winelib_argv[1] 0;

    wine_init( 2, winelib_argv, error, sizeof(error) );
    fprintf( stderr, "wine: failed to initialize: %s\n", error );
    exit(1);
}

A routine "__wine_exe_entry_point" would be exported by the executable. The 
startup code for "excallback.exe.so" would call that routine as substantially 
all of its initialisation code, so that the executable calls 
wine_dll_register providing its own details.

I suspect the "difficulty" associated with having a Linux executable that 
calls Windows DLLs using Wine has been due the assumption that "main()" in 
the executable would be executed before Wine - by throwing out this 
assumption the problem may be a whole lot easier to solve.

-- 
Troy Rollo - wine at troy.rollo.name



More information about the wine-devel mailing list