src/loadso/windows/SDL_sysloadso.c
author Sam Lantinga
Wed, 18 Jan 2017 12:19:57 -0800
changeset 10821 b0b8395f5cf9
parent 10737 3406a0f8b041
child 11811 5d94cb6b24d3
permissions -rw-r--r--
Removed unused variable
slouken@1361
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@10737
     3
  Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
slouken@1361
     4
slouken@5535
     5
  This software is provided 'as-is', without any express or implied
slouken@5535
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     7
  arising from the use of this software.
slouken@1361
     8
slouken@5535
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
    10
  including commercial applications, and to alter it and redistribute it
slouken@5535
    11
  freely, subject to the following restrictions:
slouken@1361
    12
slouken@5535
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@5535
    14
     claim that you wrote the original software. If you use this software
slouken@5535
    15
     in a product, an acknowledgment in the product documentation would be
slouken@5535
    16
     appreciated but is not required.
slouken@5535
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@5535
    18
     misrepresented as being the original software.
slouken@5535
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@1361
    20
*/
icculus@8093
    21
#include "../../SDL_internal.h"
slouken@1361
    22
slouken@5062
    23
#ifdef SDL_LOADSO_WINDOWS
slouken@1635
    24
slouken@1361
    25
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
slouken@1361
    26
/* System dependent library loading routines                           */
slouken@1361
    27
slouken@5090
    28
#include "../../core/windows/SDL_windows.h"
slouken@1361
    29
slouken@1361
    30
#include "SDL_loadso.h"
slouken@1361
    31
slouken@1895
    32
void *
slouken@1895
    33
SDL_LoadObject(const char *sofile)
slouken@1361
    34
{
slouken@5090
    35
    LPTSTR tstr = WIN_UTF8ToString(sofile);
dludwig@8382
    36
#ifdef __WINRT__
dludwig@8382
    37
    /* WinRT only publically supports LoadPackagedLibrary() for loading .dll
dludwig@8382
    38
       files.  LoadLibrary() is a private API, and not available for apps
dludwig@8382
    39
       (that can be published to MS' Windows Store.)
dludwig@8382
    40
    */
dludwig@8382
    41
    void *handle = (void *) LoadPackagedLibrary(tstr, 0);
dludwig@8382
    42
#else
slouken@5090
    43
    void *handle = (void *) LoadLibrary(tstr);
dludwig@8382
    44
#endif
slouken@5090
    45
    SDL_free(tstr);
slouken@1361
    46
slouken@1895
    47
    /* Generate an error message if all loads failed */
slouken@1895
    48
    if (handle == NULL) {
slouken@5090
    49
        char errbuf[512];
slouken@5090
    50
        SDL_strlcpy(errbuf, "Failed loading ", SDL_arraysize(errbuf));
slouken@5090
    51
        SDL_strlcat(errbuf, sofile, SDL_arraysize(errbuf));
slouken@5090
    52
        WIN_SetError(errbuf);
slouken@1895
    53
    }
slouken@5090
    54
    return handle;
slouken@1361
    55
}
slouken@1361
    56
slouken@1895
    57
void *
slouken@1895
    58
SDL_LoadFunction(void *handle, const char *name)
slouken@1361
    59
{
slouken@5090
    60
    void *symbol = (void *) GetProcAddress((HMODULE) handle, name);
slouken@1895
    61
    if (symbol == NULL) {
slouken@5090
    62
        char errbuf[512];
slouken@5090
    63
        SDL_strlcpy(errbuf, "Failed loading ", SDL_arraysize(errbuf));
slouken@5090
    64
        SDL_strlcat(errbuf, name, SDL_arraysize(errbuf));
slouken@5090
    65
        WIN_SetError(errbuf);
slouken@1895
    66
    }
slouken@5090
    67
    return symbol;
slouken@1361
    68
}
slouken@1361
    69
slouken@1895
    70
void
slouken@1895
    71
SDL_UnloadObject(void *handle)
slouken@1361
    72
{
slouken@1895
    73
    if (handle != NULL) {
slouken@1895
    74
        FreeLibrary((HMODULE) handle);
slouken@1895
    75
    }
slouken@1361
    76
}
slouken@1361
    77
slouken@5062
    78
#endif /* SDL_LOADSO_WINDOWS */
slouken@2773
    79
slouken@1895
    80
/* vi: set ts=4 sw=4 expandtab: */