Path: blob/main/crypto/krb5/src/windows/lib/loadfuncs.c
34907 views
#define WIN32_LEAN_AND_MEAN1#include <windows.h>2#include "loadfuncs.h"34//5// UnloadFuncs:6//7// This function will reset all the function pointers of a function loaded8// by LaodFuncs and will free the DLL instance provided.9//1011void12UnloadFuncs(13FUNC_INFO fi[],14HINSTANCE h15)16{17int n;18if (fi)19for (n = 0; fi[n].func_ptr_var; n++)20*(fi[n].func_ptr_var) = NULL;21if (h) FreeLibrary(h);22}232425//26// LoadFuncs:27//28// This function try to load the functions for a DLL. It returns 0 on failure29// and non-zero on success. The parameters are described below.30//3132int33LoadFuncs(34const char* dll_name,35FUNC_INFO fi[],36HINSTANCE* ph, // [out, optional] - DLL handle37int* pindex, // [out, optional] - index of last func loaded (-1 if none)38int cleanup, // cleanup function pointers and unload on error39int go_on, // continue loading even if some functions cannot be loaded40int silent // do not pop-up a system dialog if DLL cannot be loaded4142)43{44HINSTANCE h;45int i, n, last_i;46int error = 0;47UINT em;4849if (ph) *ph = 0;50if (pindex) *pindex = -1;5152for (n = 0; fi[n].func_ptr_var; n++)53*(fi[n].func_ptr_var) = NULL;5455if (silent)56em = SetErrorMode(SEM_FAILCRITICALERRORS);57h = LoadLibrary(dll_name);58if (silent)59SetErrorMode(em);6061if (!h)62return 0;6364last_i = -1;65for (i = 0; (go_on || !error) && (i < n); i++)66{67void* p = (void*)GetProcAddress(h, fi[i].func_name);68if (!p)69error = 1;70else71{72last_i = i;73*(fi[i].func_ptr_var) = p;74}75}76if (pindex) *pindex = last_i;77if (error && cleanup && !go_on) {78for (i = 0; i < n; i++) {79*(fi[i].func_ptr_var) = NULL;80}81FreeLibrary(h);82return 0;83}84if (ph) *ph = h;85if (error) return 0;86return 1;87}888990