platform/windows.c
changeset 936 3b4b6c107a59
parent 930 45ad625f03bc
child 937 3039f8fb665b
equal deleted inserted replaced
934:d0d72a7c49a7 936:3b4b6c107a59
   254     __PHYSFS_smallFree(cpstr);
   254     __PHYSFS_smallFree(cpstr);
   255     return(retval);
   255     return(retval);
   256 } /* fallbackCreateFileW */
   256 } /* fallbackCreateFileW */
   257 
   257 
   258 
   258 
   259 /* A blatant abuse of pointer casting... */
   259 #if (PHYSFS_MINIMUM_GCC_VERSION(3,3))
   260 static int symLookup(HMODULE dll, void **addr, const char *sym)
   260     typedef FARPROC __attribute__((__may_alias__)) PHYSFS_FARPROC;
   261 {
   261 #else
   262     return( (*addr = GetProcAddress(dll, sym)) != NULL );
   262     typedef FARPROC PHYSFS_FARPROC;
       
   263 #endif
       
   264 
       
   265 
       
   266 static void symLookup(HMODULE dll, PHYSFS_FARPROC *addr, const char *sym,
       
   267                       int reallyLook, PHYSFS_FARPROC fallback)
       
   268 {
       
   269     PHYSFS_FARPROC proc;
       
   270     proc = (PHYSFS_FARPROC) ((reallyLook) ? GetProcAddress(dll, sym) : NULL);
       
   271     if (proc == NULL)
       
   272         proc = fallback;  /* may also be NULL. */
       
   273     *addr = proc;
   263 } /* symLookup */
   274 } /* symLookup */
   264 
   275 
   265 
   276 
   266 static int findApiSymbols(void)
   277 static int findApiSymbols(void)
   267 {
   278 {
   268     HMODULE dll = NULL;
   279     HMODULE dll = NULL;
   269 
   280 
   270     #define LOOKUP_NOFALLBACK(x, reallyLook) { \
   281     #define LOOKUP_NOFALLBACK(x, reallyLook) \
   271         if (reallyLook) \
   282         symLookup(dll, (PHYSFS_FARPROC *) &p##x, #x, reallyLook, NULL)
   272             symLookup(dll, (void **) &p##x, #x); \
   283 
   273         else \
   284     #define LOOKUP(x, reallyLook) \
   274             p##x = NULL; \
   285         symLookup(dll, (PHYSFS_FARPROC *) &p##x, #x, \
   275     }
   286                   reallyLook, (PHYSFS_FARPROC) fallback##x)
   276 
       
   277     #define LOOKUP(x, reallyLook) { \
       
   278         if ((!reallyLook) || (!symLookup(dll, (void **) &p##x, #x))) \
       
   279             p##x = fallback##x; \
       
   280     }
       
   281 
   287 
   282     /* Apparently Win9x HAS the Unicode entry points, they just don't WORK. */
   288     /* Apparently Win9x HAS the Unicode entry points, they just don't WORK. */
   283     /*  ...so don't look them up unless we're on NT+. (see osHasUnicode.) */
   289     /*  ...so don't look them up unless we're on NT+. (see osHasUnicode.) */
   284 
   290 
   285     dll = libUserEnv = LoadLibraryA("userenv.dll");
   291     dll = libUserEnv = LoadLibraryA("userenv.dll");