<html><head></head><body><div style="font-family: Verdana;font-size: 12.0px;"><div>Thanks for the answer. </div>

<div>Unforunately, that's exactly what I hoped I wouldn't hear. </div>

<div>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. </div>

<div>I counted 83 different API calls, with an average of 5 arguments, some byref, some pointers to whatever, <br/>
and structs comprising 40 or more fields. </div>

<div>I'll have to think about whether it might be easer ripping the respective code out of wine. </div>

<div>
<div>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.  </div>

<div>
<pre>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. 
</pre>
</div>

<div>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. </div>
</div>

<div> 
<div name="quote" style="margin:10px 5px 5px 10px; padding: 10px 0 10px 10px; border-left:2px solid #C3D9E5; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">
<div style="margin:0 0 10px 0;"><b>Gesendet:</b> Donnerstag, 30. August 2018 um 19:37 Uhr<br/>
<b>Von:</b> "Stefan Dösinger" <stefandoesinger@gmail.com><br/>
<b>An:</b> "Wilma Feuerstein" <officedev@gmx.ch>, wine-devel@winehq.org<br/>
<b>Betreff:</b> Re: Possible to call winlib function from native program ?</div>

<div name="quoted-content">Hello Wilma,<br/>
<br/>
You need to compile and link your entire application with winegcc (or<br/>
wineg++) and run it through Wine. winegcc will give you a file<br/>
app.exe.so, which you can run with "wine app.exe.so". It'll also create<br/>
an app.exe shell script that invokes Wine for you.<br/>
<br/>
The reason why you cannot simply dlopen a Wine DLL and call code from it<br/>
is that Wine's DLLs depend on having a running wineserver instance to<br/>
take care of Windows kernel tasks that do not exist on the Linux side,<br/>
e.g. the registry. Furthermore dependencies between Wine DLLs are<br/>
resolved via PE exports / imports, so when you dlopen crypt32.dll the<br/>
required user32.dll, advapi32.dll and bcrypt.dll libs won't be loaded<br/>
and linked.<br/>
<br/>
A winelib-linked program can call link to and call any Linux shared<br/>
library. If the Wine-dependent functionality is relatively small and you<br/>
do not with to have all of Wine loaded whenever your program is running,<br/>
you could consider making the Wine-dependent bits run in an external<br/>
process and communicate via pipes, sockets or shared memory with your<br/>
main program.<br/>
<br/>
I hope this helps.<br/>
<br/>
Stefan<br/>
<br/>
Am 2018-08-30 um 13:00 schrieb Wilma Feuerstein:<br/>
> I'm trying to call a winelib-function from a Linux C/C++ shared-library.<br/>
> The reason for it is, that I want to call some wine-dll-functions from C#.<br/>
>  <br/>
><br/>
> I wrote a wineg++/winegcc compiled shared-library (libtest.c), which I<br/>
> want to call from a gcc/g++ main program (for testing).<br/>
><br/>
> Inside the shared library, I try to call CryptProtectData (in<br/>
> Crypt32.lib) and GetVersionEx (Kernel32.lib) - for a test - and just<br/>
> printf the results.<br/>
> Inside the main application, I dlopen the shared library,<br/>
> and dlsym the wrapper-function which calls CryptProtectData/GetVersionEx, <br/>
> then I try to execute that wrapper function.<br/>
><br/>
> But as soon as the execution hits the CryptProtectData/GetVersionEx, I<br/>
> get *Segmentation fault (core dumped)* .<br/>
><br/>
> Why ?<br/>
> The source-code for calling the CryptProtectData/GetVersionEx function<br/>
> works, tested it on Windows.<br/>
> Invoking a dlsym-ed function that doesn't call a wine-function works as<br/>
> well.<br/>
> But invoking a dlsym-ed function that calls a winelib-function does NOT<br/>
> work (segmentation fault).<br/>
> Do I need to call any undocumented wine init-code ? <br/>
> Or what is the problem ?<br/>
> Can I even run libtest.dll.so inside an application that isn't run with<br/>
> wine / that isn't compiled with wineg++ ?<br/>
> If the latter is the case, is there some hack somewhere to make it work ?<br/>
> Basically all such a hack would need to do is loading some libraries,<br/>
> and execute some init code, or not ?<br/>
><br/>
> |wineg++-m64 -shared -fPIC -Wall-lrt -ldl -lpthread -lwine -lmsvcrt<br/>
> -lcrypt32 -lusp10 -o libtest.so libtest.c g++-m64 app.c -ldl -o app ./app|<br/>
><br/>
>  <br/>
> Details/Code here:<br/>
> <a href="https://stackoverflow.com/questions/52093440/how-to-call-wine-dll-functions-from-c" target="_blank">https://stackoverflow.com/questions/52093440/how-to-call-wine-dll-functions-from-c</a><br/>
>  <br/>
><br/>
><br/>
><br/>
 </div>
</div>
</div></div></body></html>