Skip to content

Instantly share code, notes, and snippets.

@whitequark
Created March 23, 2016 01:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whitequark/8ce504c85116707f41ef to your computer and use it in GitHub Desktop.
Save whitequark/8ce504c85116707f41ef to your computer and use it in GitHub Desktop.
*.exe
*.dll
*.lib
#include <windows.h>
#include <stdio.h>
int main() {
HMODULE hFoo = LoadLibrary("foo.dll");
DWORD *dwData = (DWORD *)GetProcAddress(hFoo, "dwData");
fprintf(stderr, "dwData = %p\n", dwData);
fprintf(stderr, "*dwData = %lld\n", *dwData);
return 0;
}
#include <windows.h>
#include <stdio.h>
__declspec(dllimport) DWORD dwData;
int main() {
fprintf(stderr, "&dwData = %p\n", &dwData);
fprintf(stderr, "dwData = %lld\n", dwData);
return 0;
}
.data
.globl dwData
dwData:
.long 1234
$ wine bar.exe
dwData = 000000006AE83000
*dwData = 1234
$ wine baz.exe
&dwData = 000000006AE83000
dwData = 1234
all: bar.exe baz.exe
clean:
rm *.exe *.dll *.lib
.PHONY: all clean
foo.dll foo.lib: foo.s
x86_64-w64-mingw32-gcc -shared $^ -o foo.dll -Wl,--out-implib,foo.lib
bar.exe: bar.c foo.dll
x86_64-w64-mingw32-gcc $(filter %.c,$^) -o $@
baz.exe: baz.c foo.lib
x86_64-w64-mingw32-gcc $(filter %.c,$^) -L. -lfoo -o $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment