Reputation: 31
I have a Windows executable that load a library and I want to create a Winelib DLL that will overide the Windows DLL. It's been 2 days that I search and try but it won't work ! Please help me !
Basically I create mydll.c and mydll.spec to build the Winelib DLL with the command:
winegcc -m32 -shared -o mydll.dll mydll.c mydll.spec
Now I have mydll.dll.so and I want to override mydll.dll (both are at the same place) What should I do ? I try to rename mydll.dll but I got a Page Fault when the function is called ! I also tried to configure the override with winecfg or set environment variables like WINEDLLPATH. I don't understand how to proceed.
How I load the library in my Windows executable
HINSTANCE DllHandle;
char str[255];
typedef int(__stdcall * tfp)(char * const);
DllHandle = LoadLibrary("mydll.dll");
tfp fp = (tfp)GetProcAddress(DllHandle, "myfunc");
fp(str);
FreeLibrary(DllHandle);
mydll.spec
@ stdcall myfunc(str)
mydll.c
#include <windef.h>
int WINAPI myfunc(char * str)
{
strcpy(str, "myfunc from the Winelib DLL");
return 0;
}
Upvotes: 3
Views: 1743
Reputation: 4317
I was able to get this to work but had to make the following changes.
I was using wine5 on Ubuntu, where is seems the default install is 64bit. I had to rename wine's executable first as it was using the 32bit call by mistake and that meant it would not work with the 64bit dll.
install wine-tools (for winegcc)
apt-get install wine-tools
Fix wine64 (as the exe seems to load wine32 and then error)
cd /usr/lib/wine
mv wine wine32
ln -s wine64 wine
Makefile
all: mydll.dll.so testmydll.exe
mydll.dll.so: mydll.c mydll.spec
winegcc -shared -o mydll.dll mydll.c mydll.spec
testmydll.exe: testmydll.c
winegcc -mno-cygwin -o testmydll testmydll.c
clean:
rm -f *.so
rm -f *.exe
rm -f *~
Also, there is a mistake in your code, which I corrected. The lack of a __stdcall and the name of the DLL.
Upvotes: 0
Reputation: 1
Use WINEDEBUG=+module
to debug DLL loading problems.
I don't believe Wine searches for native .dll.so
files outside of a single folder but the code is in dlls/ntdll/loader.c:load_builtin_dll
if you want to check yourself.
Upvotes: 0