Ok, now I have dealt a lot with
winemaker, winebuild, winegcc and all that... and read all the documentation
But for a simple demo/test, all that is taking a sledgehammer to crack a nut (while winemaker doesn't seem to work as expected: for example, ignoring the "--wine32" parameter and more).
Now I just want to understand the most simple workflow possible - by creating a "built-in" DLL function which adds two Integers. Should be
really simple - shouldn't it?
I have written a pretty short Windows program (with Delphi 7) like this:
Code: Select all
myPlusLib:=LoadLibrary('plus.dll');
myPlusFunc:=GetProcAddress(myPlusLib, 'plus');
Writeln('Result of 1+2=', myPlusFunc(1, 2));
FreeLibrary(myPlusLib)
and parallel to this, a Linux library like this
Code: Select all
#include <windef.h>
#include <stdio.h>
int WINAPI plus(int a, int b)
{
printf("Here is plus(%d, %d)\n", a, b);
return a+b;
}
int DllMain(void)
{
printf("Here is DllMain\n");
return 0;
}
int WinMain(void)
{
printf("Here is WinMain\n");
return 0;
}
with
printf just to see what happens.
I compiled this with
winegcc -m32 -o plus.dll.so -shared plus.c
and get two warnings
Code: Select all
/usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: /usr/lib/wine/libwinecrt0.a(dll_entry.o): warning: relocation in read-only section `.text'
/usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: warning: creating DT_TEXTREL in a shared object
and a file
plus.dll.so which I copy to
/usr/lib/wine.
Now when I start
wine TestPlus, I get
Code: Select all
0009:fixme:msg:ChangeWindowMessageFilterEx 0x20040 400 1 (nil)
Here is DllMain
Here is DllMain
DLL initialization failed (0x0000045A)
so my
plus.dll.so seems to be found and used, but
DllMain seems to be called
twice, and then "initialization" fails (whatever there may be initialized).
With
WINEDEBUG="+all", I found something like
Code: Select all
4096.717:0008:0009:trace:module:load_builtin_callback loaded plus.dll-yTZUi0.spec 0x18b220 0x7c2b0000
0009: load_dll( dbg_offset=0, base=7c2b0000, name=0018b248, dbg_size=0, filename=L"C:\\windows\\system32\\plus.dll-yTZUi0.spec" )
0009: load_dll() = 0
4096.717:0008:0009:trace:loaddll:load_so_dll Loaded L"C:\\windows\\system32\\plus.dll-yTZUi0.spec" at 0x7c2b0000: builtin
4096.717:0008:0009:trace:heap:RtlFreeHeap (0x110000,70000062,0x176870): returning TRUE
4096.717:0008:0009:trace:module:load_dll Loaded module L"\\??\\C:\\windows\\system32\\plus.dll" at 0x7c2b0000
4096.718:0008:0009:trace:heap:RtlFreeHeap (0x110000,70000062,0x17b660): returning TRUE
4096.718:0008:0009:trace:module:process_attach (L"plus.dll-yTZUi0.spec",(nil)) - START
4096.718:0008:0009:Call PE DLL (proc=0x7c2b5610,module=0x7c2b0000 L"plus.dll-yTZUi0.spec",reason=PROCESS_ATTACH,res=(nil))
4096.718:0008:0009:Ret PE DLL (proc=0x7c2b5610,module=0x7c2b0000 L"plus.dll-yTZUi0.spec",reason=PROCESS_ATTACH,res=(nil)) retval=0
4096.718:0008:0009:Call PE DLL (proc=0x7c2b5610,module=0x7c2b0000 L"plus.dll-yTZUi0.spec",reason=PROCESS_DETACH,res=(nil))
4096.718:0008:0009:Ret PE DLL (proc=0x7c2b5610,module=0x7c2b0000 L"plus.dll-yTZUi0.spec",reason=PROCESS_DETACH,res=(nil)) retval=0
4096.718:0008:0009:warn:module:process_attach Initialization of L"plus.dll-yTZUi0.spec" failed
4096.718:0008:0009:trace:module:process_attach (L"plus.dll-yTZUi0.spec",(nil)) - END
4096.718:0008:0009:trace:module:LdrUnloadDll (0x7c2b0000)
4096.718:0008:0009:trace:module:LdrUnloadDll (L"plus.dll-yTZUi0.spec") - START
4096.718:0008:0009:trace:module:MODULE_DecRefCount (L"plus.dll-yTZUi0.spec") ldr.LoadCount: 0
4096.718:0008:0009:trace:module:free_modref unloading L"C:\\windows\\system32\\plus.dll-yTZUi0.spec"
which leaves me pretty clueless.
What am I doing wrong, what have I forgotten?
Thanks a lot,
-Matt