src/loadso/os2/SDL_loadso.c
author Sam Lantinga
Mon, 06 Feb 2006 08:28:51 +0000
changeset 1330 450721ad5436
parent 1312 c9b51268668f
child 1358 c71e05b4dc2e
permissions -rw-r--r--
It's now possible to build SDL without any C runtime at all on Windows,
using Visual C++ 2005
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2006 Sam Lantinga
     4 
     5     This library is free software; you can redistribute it and/or
     6     modify it under the terms of the GNU Lesser General Public
     7     License as published by the Free Software Foundation; either
     8     version 2.1 of the License, or (at your option) any later version.
     9 
    10     This library is distributed in the hope that it will be useful,
    11     but WITHOUT ANY WARRANTY; without even the implied warranty of
    12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    13     Lesser General Public License for more details.
    14 
    15     You should have received a copy of the GNU Lesser General Public
    16     License along with this library; if not, write to the Free Software
    17     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    18 
    19     Sam Lantinga
    20     slouken@libsdl.org
    21 */
    22 
    23 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
    24 /* System dependent library loading routines                           */
    25 
    26 #if !SDL_INTERNAL_BUILDING_LOADSO
    27 #error Do not compile directly...compile src/SDL_loadso.c instead!
    28 #endif
    29 
    30 #if !defined(__OS2__)
    31 #error Compiling for the wrong platform?
    32 #endif
    33 
    34 #include <stdio.h>
    35 #define INCL_DOSERRORS
    36 #define INCL_DOSMODULEMGR
    37 #include <os2.h>
    38 
    39 #include "SDL_types.h"
    40 #include "SDL_error.h"
    41 #include "SDL_loadso.h"
    42 
    43 void *SDL_LoadObject(const char *sofile)
    44 {
    45     HMODULE handle = NULL;
    46     char buf[512];
    47     APIRET ulrc = DosLoadModule(buf, sizeof (buf), (char *) sofile, &handle);
    48 
    49     /* Generate an error message if all loads failed */
    50     if ((ulrc != NO_ERROR) || (handle == NULL))
    51         SDL_SetError("Failed loading %s: %s", sofile, buf);
    52 
    53     return((void *) handle);
    54 }
    55 
    56 void *SDL_LoadFunction(void *handle, const char *name)
    57 {
    58     const char *loaderror = "Unknown error";
    59     void *symbol = NULL;
    60     APIRET ulrc = DosQueryProcAddr((HMODULE)handle, 0, (char *)name, &symbol);
    61     if (ulrc == ERROR_INVALID_HANDLE)
    62         loaderror = "Invalid module handle";
    63     else if (ulrc == ERROR_INVALID_NAME)
    64         loaderror = "Symbol not found";
    65 
    66     if (symbol == NULL)
    67         SDL_SetError("Failed loading %s: %s", name, loaderror);
    68 
    69     return(symbol);
    70 }
    71 
    72 void SDL_UnloadObject(void *handle)
    73 {
    74     if ( handle != NULL )
    75         DosFreeModule((HMODULE) handle);
    76 }
    77