Reactos
1/***
2*loaddll.c - load or free a Dynamic Link Library
3*
4* Copyright (c) Microsoft Corporation. All rights reserved.
5*
6*Purpose:
7* defines _loaddll() and _unloaddll() - load and unload DLL
8*
9*******************************************************************************/
10
11#include <corecrt_internal.h>
12#include <errno.h>
13#include <stdlib.h>
14
15#define _CRT_ENABLE_OBSOLETE_LOADLIBRARY_FUNCTIONS
16
17#include <process.h>
18
19/***
20*int _loaddll(filename) - Load a dll
21*
22*Purpose:
23* Load a DLL into memory
24*
25*Entry:
26* char *filename - file to load
27*
28*Exit:
29* returns a unique DLL (module) handle if succeeds
30* returns 0 if fails
31*
32*Exceptions:
33*
34*******************************************************************************/
35
36extern "C" intptr_t __cdecl _loaddll(char* szName)
37{
38 return reinterpret_cast<intptr_t>(__acrt_LoadLibraryExA(szName, nullptr, 0));
39}
40
41/***
42*int _unloaddll(handle) - Unload a dll
43*
44*Purpose:
45* Unloads a DLL. The resources of the DLL will be freed if no other
46* processes are using it.
47*
48*Entry:
49* int handle - handle from _loaddll
50*
51*Exit:
52* returns 0 if succeeds
53* returns DOS error if fails
54*
55*Exceptions:
56*
57*******************************************************************************/
58
59extern "C" int __cdecl _unloaddll(intptr_t hMod)
60{
61 if (!FreeLibrary(reinterpret_cast<HMODULE>(hMod))) {
62 return ((int)GetLastError());
63 }
64 return (0);
65}