Thanks for the answer. 
Unforunately, that's exactly what I hoped I wouldn't hear. 
I can't load a windows/wine-dll from C#, and neither can I load a dll that I have to start with a server process. 
I counted 83 different API calls, with an average of 5 arguments, some byref, some pointers to whatever, 
and structs comprising 40 or more fields. 
I'll have to think about whether it might be easer ripping the respective code out of wine. 
Writing a socket server for ~100 APIs with byref-arguments, with C and Windows-size datatypes on one side, and C# on Linux on the other, where the C# code runs inside a web-server, seems like a daunting task that might be more complex than writing a basic web server.  
Is it not somehow possible to load the wine-server process inside the libtest.dll.so-constructor ? 
#define LINUX_ATTACH_DLL __attribute__((constructor)) 
whether that server process would be started inside the same process or outside wouldn't matter much. 
If I had to manually dlopen the dependencies between crypt32.dll, user32.dll, advapi32.dll and bcrypt.dll - and whatever - in the right order, that's something I could live with. 
 
Gesendet: Donnerstag, 30. August 2018 um 19:37 Uhr
Von: "Stefan Dösinger" <stefandoesinger@gmail.com>
An: "Wilma Feuerstein" <officedev@gmx.ch>, wine-devel@winehq.org
Betreff: Re: Possible to call winlib function from native program ?
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
>  
>
>
>