From: misomosi Date: Tue, 7 May 2024 00:29:54 +0000 (-0400) Subject: Add Windows pld.h and example X-Git-Url: http://git.misomosispi.com/?a=commitdiff_plain;h=c3d3973ab7e98ed933e5038210d2d137ca43a4af;p=pldh.git Add Windows pld.h and example --- diff --git a/examples/writefile.c b/examples/writefile.c new file mode 100644 index 0000000..130b481 --- /dev/null +++ b/examples/writefile.c @@ -0,0 +1,8 @@ +#include "../pld.h" + +PLD(KERNEL32) +int main(void) { + DWORD dummy; + PFN(WriteFile)(GetStdHandle(STD_OUTPUT_HANDLE), "Hello World!\n", 13, &dummy, NULL); + return 0; +} diff --git a/pld.h b/pld.h new file mode 100644 index 0000000..0d597ba --- /dev/null +++ b/pld.h @@ -0,0 +1,38 @@ +#ifndef COOL_PLD_H +#define COOL_PLD_H + +#ifdef _MSC_VER +#define PLDTYPEOF(x) __typeof__(x) +#else +#define PLDTYPEOF(x) typeof(x) +#endif + +#ifdef _WIN32 +#include +static HMODULE PLD_LoadLibrary_wrapper(LPCSTR lpLibFileName) +{ + HMODULE hModule = GetModuleHandleA(lpLibFileName); + if (hModule != NULL) + hModule = LoadLibraryA(lpLibFileName); + return hModule; +} +static FARPROC PLD_GetProcAddress_wrapper(HMODULE hModule, LPCSTR lpProcName) +{ + FARPROC lpProc = GetProcAddress(hModule, lpProcName); + return lpProc; +} + +#define PLD(name) \ + static HMODULE PLDH(void) { \ + static HMODULE hModule = NULL; \ + if (hModule == NULL) hModule = PLD_LoadLibrary_wrapper(#name); \ + return hModule; \ + } \ + +#define PFN(name) ((PLDTYPEOF(name))PLD_GetProcAddress_wrapper(PLDH(), #name)) + +#else +#error POSIX Unimplemented! +#endif + +#endif // COOL_PLD_H