Skip to content

Instantly share code, notes, and snippets.

@kou1okada
Last active February 17, 2016 14:56
Show Gist options
  • Save kou1okada/87b2d964f669ecb79e78 to your computer and use it in GitHub Desktop.
Save kou1okada/87b2d964f669ecb79e78 to your computer and use it in GitHub Desktop.
Example of the dll by the cygwin
#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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment