|
⇤ ← Revision 1 as of 2010-05-18 01:08:02
Size: 1035
Comment: create page, add content (Wed Mar 10 ver; changeset 4428)
|
Size: 2594
Comment: update content (old wiki)
|
| Deletions are marked like this. | Additions are marked like this. |
| Line 17: | Line 17: |
| ||'''handle'''||^a pointer to the object handle^|| ||'''name'''||^a pointer to the named function in the shared object^|| |
||'''handle'''||*a valid shared object handle returned by [[SDL_LoadObject]]()*|| ||'''name'''||^a pointer to the named function in the shared object^ ''-or-'' *the null terminated string of the function's name to look up*|| |
| Line 21: | Line 21: |
| <<Color2(green,This has a "void" RV but also a pointer. Should this info be reported in Remarks instead?)>> | <<Color2(green,This has a "void" RV but also a pointer. Should this info be reported in Remarks instead because it's not really a RV?)>> |
| Line 23: | Line 23: |
| Returns a pointer to the object handle (or NULL if there was an error). ??? | *<<BR>>Returns a pointer to the function or NULL if there was an error; call [[SDL_GetError]]() for more information.<<BR>>* |
| Line 27: | Line 27: |
| You can add your code example here | #include "SDL_loadso.h" // Variable declaration void* myHandle = NULL; char* myFunctionName = "myFancyFunction"; void (*myFancyFunction)(int anInt); // Dynamically load mylib.so myHandle = SDL_LoadObject("mylib.so"); // Load the exported function from mylib.so // The exported function has the following prototype // void myFancyFunction(int anInt); myFancyFunction = (void (*)(int))SDL_LoadFunction( myHandle, myFunctionName ); // Call myFancyFunction with a random integer if (myFancyFunction != NULL) { myFancyFunction( 15 ); } else { // Error handling here } |
| Line 33: | Line 54: |
| *<<BR>>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. These functions only work on C function names. Other languages may have name mangling and intrinsic language support that varies from compiler to compiler. 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. 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.<<BR>>* |
|
| Line 34: | Line 63: |
| .[[SDL_LoadObject]] |
DRAFT |
SDL_LoadFunction
Use this function to look up the address of the a named function in the shared object and return it.
Contents
Syntax
void* SDL_LoadFunction(void* handle,
const char* name)
Function Parameters
handle |
*a valid shared object handle returned by SDL_LoadObject()* |
name |
a pointer to the named function in the shared object -or- *the null terminated string of the function's name to look up* |
Return Value
green
*
Returns a pointer to the function or NULL if there was an error; call SDL_GetError() for more information.
*
Code Examples
#include "SDL_loadso.h"
// Variable declaration
void* myHandle = NULL;
char* myFunctionName = "myFancyFunction";
void (*myFancyFunction)(int anInt);
// Dynamically load mylib.so
myHandle = SDL_LoadObject("mylib.so");
// Load the exported function from mylib.so
// The exported function has the following prototype
// void myFancyFunction(int anInt);
myFancyFunction = (void (*)(int))SDL_LoadFunction( myHandle, myFunctionName );
// Call myFancyFunction with a random integer
if (myFancyFunction != NULL) {
myFancyFunction( 15 );
}
else {
// Error handling here
}
Remarks
This address is no longer valid after calling SDL_UnloadObject().
*
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.
These functions only work on C function names. Other languages may have name mangling and intrinsic language support that varies from compiler to compiler.
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.
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.
*
