Open dov opened 5 years ago
After I wrote the above, I realized that perhaps the "attempt to call an unknown symbol" error is the call to printf()
. I then added a new function to my dll:
int32_t add_hello(int32_t a, int32_t b);
and called it as follows:
// Try calling into the library.
int32_t (*AddHelloPtr)(int32_t a, int32_t b);
if (get_export("add_hello", &AddHelloPtr) != -1) {
int a=10,b=32;
printf("%d+%d=%d\n", a,b,AddHelloPtr(a,b));
}
else
printf("Failed getting pointer to say_hello()!\n");
and this worked!
But I still wonder how would I load the windows CRT library so that I can call printf (and other io functions)? Or is there a way to redirect the DLL printf()
call to the gcc libc printf()
.
In order to learn how to use the loadlbrary library with the goal of accessing a commercial win32 library from linux, I started off with a simple hello world example.
Here are my files:
include
void say_hello() { printf("Say Hello!\n"); }
include "say-hello.h"
int main(int argc, char*argv[]) { say_hello(); }
i686-w64-mingw32-gcc -o hello-main.obj -c -O2 -mms-bitfields hello-main.c i686-w64-mingw32-gcc -o say-hello.obj -c -fPIC -O2 -mms-bitfields say-hello.c i686-w64-mingw32-gcc -o say-hello.dll -shared say-hello.obj i686-w64-mingw32-gcc -o hello-main.exe hello-main.obj say-hello.dll
wine hello-main.exe 000b:fixme:winediag:start_process Wine Staging 4.0-rc2 is a testing version containing experimental patches. 000b:fixme:winediag:start_process Please mention your exact version when filing bug reports on winehq.org. Say Hello!
ifndef _GNU_SOURCE
define _GNU_SOURCE
endif
include
include
include
include
include
include
include "winnt_types.h"
include "pe_linker.h"
include "ntoskernel.h"
int main(int argc, char argv, char envp) { PIMAGE_DOS_HEADER DosHeader; PIMAGE_NT_HEADERS PeHeader; struct pe_image image = { .entry = NULL, .name = "say-hello.dll", };
}