2021-07-24 21:11:47 -07:00

51 lines
1.5 KiB
C
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#define MODULE_TEMPLATE2(mod, fname) \
\
\
static HMODULE hMod = NULL; \
static PROCDATA *pList = NULL; \
\
static TCHAR szMod[] = TEXT( #fname ); \
\
void __ ## mod ## dynlink(PROCDATA *p) \
{ \
PROCDATA *head; \
\
if (!hMod) { \
UINT errmode = SetErrorMode(SEM_NOOPENFILEERRORBOX \
| SEM_FAILCRITICALERRORS); \
hMod = LoadLibrary(szMod); \
SetErrorMode(errmode); \
} \
if (hMod) { \
if (p->ord) \
p->fp = GetProcAddress(hMod, (LPCSTR)(p->ord)); \
else \
p->fp = GetProcAddress(hMod, p->name); \
} \
if (p->fp) { \
head = pList; \
pList = p; \
p->next = head; \
} \
} \
\
void __ ## mod ## unlink(void) \
{ \
if (hMod) { \
FreeLibrary(hMod); \
hMod = NULL; \
\
while(pList) { \
PROCDATA *head; \
pList->fp = NULL; \
head = pList->next; \
pList->next = NULL; \
pList = head; \
} \
} \
} \
\
void _Unlink ## mod(void) {__ ## mod ## unlink();}
#define MODULE_TEMPLATE(mod, fname) MODULE_TEMPLATE2(mod, fname)