This is the most simple code for defining dll and using dll. You can do to confirm it as below:
# build and test code
make test
Copyright (c) 2016 Koichi OKADA. All rights reserves.
This codes distributed under the MIT license.
This is the most simple code for defining dll and using dll. You can do to confirm it as below:
# build and test code
make test
Copyright (c) 2016 Koichi OKADA. All rights reserves.
This codes distributed under the MIT license.
#include <windef.h> | |
#include <winbase.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
main(int argc, char *argv[]) | |
{ | |
int retcode = EXIT_FAILURE; | |
if (argc != 5) { | |
printf("Usage: %s dll func text caption\n", argv[0]); | |
return retcode; | |
} | |
HMODULE dll = LoadLibrary(argv[1]); | |
printf("%p\n", dll); | |
if (dll) { | |
FARPROC fnc = GetProcAddress(dll, argv[2]); | |
printf("%p\n", fnc); | |
if (fnc) { | |
((int (*)(HWND, LPCTSTR, LPCTSTR, UINT)) fnc)(0, argv[3], argv[4], 0); | |
retcode = EXIT_SUCCESS; | |
} | |
FreeLibrary(dll); | |
} | |
return retcode; | |
} |
#include <windef.h> | |
#include <winuser.h> | |
int msg(HWND hWnd, LPCTSTR lpText, LPCTSTR lpCaption, UINT uType) | |
{ | |
return MessageBox(hWnd, lpText, lpCaption, uType); | |
} |
all: call libmsg.so | |
call: call.c | |
$(CC) $< -o $@ | |
libmsg.so: libmsg.c | |
$(CC) -shared $< -o $@ | |
clean: | |
-$(RM) -v call libmsg.so | |
test: all | |
./call user32.dll MessageBoxA "MessageBoxA()" user32.dll | |
./call libmsg.so msg "msg()" libmsg.so |