OSDN Git Service

Collect distributable package files in user specified directory.
[mingw/mingw-get.git] / src / apihook.c
1 /*
2  * apihook.c
3  *
4  * $Id$
5  *
6  * Written by Keith Marshall <keithmarshall@users.sourceforge.net>
7  * Copyright (C) 2013, MinGW.org Project
8  *
9  *
10  * Implementation of a utility function to check for availabiliity of
11  * a specified API function within a specified DLL.
12  *
13  *
14  * This is free software.  Permission is granted to copy, modify and
15  * redistribute this software, under the provisions of the GNU General
16  * Public License, Version 3, (or, at your option, any later version),
17  * as published by the Free Software Foundation; see the file COPYING
18  * for licensing details.
19  *
20  * Note, in particular, that this software is provided "as is", in the
21  * hope that it may prove useful, but WITHOUT WARRANTY OF ANY KIND; not
22  * even an implied WARRANTY OF MERCHANTABILITY, nor of FITNESS FOR ANY
23  * PARTICULAR PURPOSE.  Under no circumstances will the author, or the
24  * MinGW Project, accept liability for any damages, however caused,
25  * arising from the use of this software.
26  *
27  */
28 #define  WIN32_LEAN_AND_MEAN
29
30 #include <windows.h>
31
32 int have_api( const char *entry, const char *dll )
33 {
34   /* Initially assuming that the specified API is "unsupported",
35    * attempt to get a handle for the nominated provider DLL.
36    */
37   HMODULE provider;
38   enum { API_UNSUPPORTED = 0, API_SUPPORTED } status = API_UNSUPPORTED;
39   if( (provider = LoadLibrary( dll == NULL ? "msvcrt.dll" : dll )) != NULL )
40   {
41     /* When we have a valid DLL handle, look up the entry point
42      * address, within it, for the specified API function...
43      */
44     if( GetProcAddress( provider, entry ) != NULL )
45       /*
46        * ...and, provided this returns a valid entry address,
47        * mark the API as "supported".
48        */
49       status = API_SUPPORTED;
50
51     /* Release the handle we acquired above, for the provider DLL,
52      * so that we maintain a balanced reference count.
53      */
54     FreeLibrary( provider );
55   }
56   /* Finally, return the support state for the API, as determined.
57    */
58   return (int)(status);
59 }
60
61 /* $RCSfile$: end of file */