SDL_LoadFunction function

SDL_LoadFunction -- Returns the address of a function in a loaded shared object.

Syntax

void* SDL_LoadFunction(void* handle, const char* name);

Description

Given a valid shared object handle returned by SDL_LoadObject, this function looks up the address of the named function in the shared object and returns it. This address is no longer valid after calling SDL_UnloadObject.

Note 1: These functions only work on C function names. Other languages may have name mangling and intrinsic language support that varies from compiler to compiler.

Note 2: Make sure you declare your function pointers with the same calling convention as the actual library function. Your code will crash mysteriously if you do not do this.

Note 3: Avoid namespace collisions. If you load a symbol from the library, it is not defined whether or not it goes into the global symbol namespace for the application. If it does and it conflicts with symbols in your code or other shared libraries, you will not get the results you expect.

Parameters

handle [in]

name [in]

Return value

NULL

The pointer to the function

See also

SDL_LoadObject, SDL_UnloadObject

Example

   1 #include "SDL_loadso.h"
   2 
   3 // Variable declaration
   4 void* myHandle = NULL;
   5 char* myFunctionName = "myFancyFunction";
   6 void (*myFancyFunction)(int anInt);
   7 
   8 // Dynamically load mylib.so
   9 myHandle = SDL_LoadObject("mylib.so");
  10 
  11 // Load the exported function from mylib.so
  12 // The exported function has the following prototype
  13 // void myFancyFunction(int anInt);
  14 myFancyFunction = (void (*)(int))SDL_LoadFunction( myHandle, myFunctionName );
  15 
  16 // Call myFancyFunction with a random integer
  17 if (myFancyFunction != NULL) {
  18     myFancyFunction( 15 );
  19 }
  20 else {
  21    // Error handling here
  22 }

Requirements

Header

SDL.h

Version

1.2.13

Shared object

libSDL.so

DLL

SDL.dll


CategorySDLGeneral

SDL_LoadFunction (last edited 2008-08-14 20:37:04 by NeoNeurone)