summaryrefslogtreecommitdiffstats
path: root/private/crt32/exec/loaddll.c
blob: a6f41b7e2ce7118f2c927926708bc66539ad6846 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/***
*loaddll.c - load or free a Dynamic Link Library
*
*	Copyright (c) 1991, Microsoft Corporation. All rights reserved.
*
*Purpose:
*	defines _loaddll() and _unloaddll() - load and unload DLL
*
*Revision History:
*	08-21-91  BWM	Wrote module.
*
*******************************************************************************/

#include <cruntime.h>
#include <oscalls.h>
#include <assert.h>
#include <stdlib.h>
#include <process.h>

#if !defined(_WIN32_)
#error ERROR - ONLY WIN32 TARGET SUPPORTED!
#endif

/***
*int _loaddll(filename) - Load a dll
*
*Purpose:
*	Load a DLL into memory
*
*Entry:
*	char *filename - file to load
*
*Exit:
*	returns a unique DLL (module) handle if succeeds
*	returns 0 if fails
*
*Exceptions:
*
*******************************************************************************/

int _CALLTYPE1 _loaddll(char * szName)
{
    return ((int)LoadLibrary(szName));
}

/***
*int _unloaddll(handle) - Unload a dll
*
*Purpose:
*	Unloads a DLL. The resources of the DLL will be freed if no other
*	processes are using it.
*
*Entry:
*	int handle - handle from _loaddll
*
*Exit:
*	returns 0 if succeeds
*	returns DOS error if fails
*
*Exceptions:
*
*******************************************************************************/

int _CALLTYPE1 _unloaddll(int hMod)
{
    if (!FreeLibrary((HANDLE)hMod)) {
	return ((int)GetLastError());
    }
    return (0);
}