Possible to call winlib function from native program ?

Stefan Dösinger stefandoesinger at gmail.com
Thu Aug 30 12:37:48 CDT 2018


Hello Wilma,

You need to compile and link your entire application with winegcc (or
wineg++) and run it through Wine. winegcc will give you a file
app.exe.so, which you can run with "wine app.exe.so". It'll also create
an app.exe shell script that invokes Wine for you.

The reason why you cannot simply dlopen a Wine DLL and call code from it
is that Wine's DLLs depend on having a running wineserver instance to
take care of Windows kernel tasks that do not exist on the Linux side,
e.g. the registry. Furthermore dependencies between Wine DLLs are
resolved via PE exports / imports, so when you dlopen crypt32.dll the
required user32.dll, advapi32.dll and bcrypt.dll libs won't be loaded
and linked.

A winelib-linked program can call link to and call any Linux shared
library. If the Wine-dependent functionality is relatively small and you
do not with to have all of Wine loaded whenever your program is running,
you could consider making the Wine-dependent bits run in an external
process and communicate via pipes, sockets or shared memory with your
main program.

I hope this helps.

Stefan

Am 2018-08-30 um 13:00 schrieb Wilma Feuerstein:
> I'm trying to call a winelib-function from a Linux C/C++ shared-library.
> The reason for it is, that I want to call some wine-dll-functions from C#.
>  
> 
> I wrote a wineg++/winegcc compiled shared-library (libtest.c), which I
> want to call from a gcc/g++ main program (for testing).
> 
> Inside the shared library, I try to call CryptProtectData (in
> Crypt32.lib) and GetVersionEx (Kernel32.lib) - for a test - and just
> printf the results.
> Inside the main application, I dlopen the shared library,
> and dlsym the wrapper-function which calls CryptProtectData/GetVersionEx, 
> then I try to execute that wrapper function.
> 
> But as soon as the execution hits the CryptProtectData/GetVersionEx, I
> get *Segmentation fault (core dumped)* .
> 
> Why ?
> The source-code for calling the CryptProtectData/GetVersionEx function
> works, tested it on Windows.
> Invoking a dlsym-ed function that doesn't call a wine-function works as
> well.
> But invoking a dlsym-ed function that calls a winelib-function does NOT
> work (segmentation fault).
> Do I need to call any undocumented wine init-code ? 
> Or what is the problem ?
> Can I even run libtest.dll.so inside an application that isn't run with
> wine / that isn't compiled with wineg++ ?
> If the latter is the case, is there some hack somewhere to make it work ?
> Basically all such a hack would need to do is loading some libraries,
> and execute some init code, or not ?
> 
> |wineg++-m64 -shared -fPIC -Wall-lrt -ldl -lpthread -lwine -lmsvcrt
> -lcrypt32 -lusp10 -o libtest.so libtest.c g++-m64 app.c -ldl -o app ./app|
> 
>  
> Details/Code here:
> https://stackoverflow.com/questions/52093440/how-to-call-wine-dll-functions-from-c
>  
> 
> 
> 




More information about the wine-devel mailing list