Skip to content

Instantly share code, notes, and snippets.

@romiras
Created January 13, 2016 13:16
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save romiras/0ad870bc3c0987dbfd5c to your computer and use it in GitHub Desktop.
TestDLL.exe - console program for testing DLL dependencies. Usage: testdll.exe libcairo-2.dll
#include <windows.h>
#include <stdio.h>
/*
__declspec(dllexport) FARPROC Test() {
printf("It worked");
}
*/
void what_error(DWORD res) {
wchar_t buf[256];
FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM, NULL, res,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf, 256, NULL);
printf("%s\n", buf);
}
void WinErr(const char *Msg, DWORD ErrorCode)
{
LPVOID lpMsgBuf;
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS |
FORMAT_MESSAGE_MAX_WIDTH_MASK | FORMAT_MESSAGE_ALLOCATE_BUFFER,
NULL, ErrorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf, 0, NULL);
printf("%s. %s\n", Msg, lpMsgBuf);
LocalFree(lpMsgBuf);
}
int main(int argc, char **argv) {
HMODULE m = LoadLibrary(argv[1]);
/*
FARPROC test = GetProcAddress(m, "Test");
test();
*/
if (m != 0) {
BOOL b;
b = FreeLibrary(m);
puts("OK");
}
else {
DWORD res = GetLastError();
printf("Cannot load %s. Code: %d\n", argv[1], res);
/*what_error(res);*/
WinErr("Oops", res);
}
return 0;
}
# Project: TestDLL
# Makefile created by Dev-C++ 5.5.1
CPP = g++.exe
CC = gcc.exe
WINDRES = windres.exe
OBJ = main.o
LINKOBJ = main.o
LIBS = -L"C:/Program Files/Development/Dev-Cpp/MinGW32/lib" -L"C:/Program Files/Development/Dev-Cpp/MinGW32/mingw32/lib" -static-libstdc++ -static-libgcc
INCS = -I"C:/Program Files/Development/Dev-Cpp/MinGW32/include"
CXXINCS = -I"C:/Program Files/Development/Dev-Cpp/MinGW32/include" -I"C:/Program Files/Development/Dev-Cpp/MinGW32/lib/gcc/mingw32/4.7.2/include/c++"
BIN = testdll.exe
CXXFLAGS = $(CXXINCS)
CFLAGS = $(INCS)
RM = rm -f
.PHONY: all all-before all-after clean clean-custom
all: all-before $(BIN) all-after
clean: clean-custom
${RM} $(OBJ) $(BIN)
$(BIN): $(OBJ)
$(CC) $(LINKOBJ) -o $(BIN) $(LIBS)
main.o: main.c
$(CC) -c main.c -o main.o $(CFLAGS)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment