dlsym函数问题
dlsym函数是void型,但是我用它提取的函数是short型的,例:
short SingleTagIdentify=dlsym(handle,"SingleTagIdentify");
这种写法是错误的,所以请问这个需要怎么转换啊?请各位高手指点!
[解决办法]
首先,你要知道dlsym的函数原型,这样才能保证类型匹配:
void* dlsym( void* handle, const char* name );
Examples:
Use dlsym() to find a function pointer and a pointer to a global variable in a shared library:
typedef int (*foofunc)( int );
void* handle;
int* some_global_int;
foofunc brain;
/* Open a shared library. */
handle = dlopen( "/usr/nto/x86/lib/libfoo.so.1", RTLD_NOW );
/* Find the address of a function and a global integer. */
brain = (foofunc)dlsym( handle, "takeover_world" );
some_global_int = (int* )dlsym( handle, "my_global_int" );
/* Invoke the function and print the int. */
x = (*brain)( 5 );
printf( "that global is %d\n", *some_global_int );Check to see if a function is defined, and call it if it is:
typedef int (*funcptr)( void );
funcptr funk = NULL;
funk = (funcptr)dlsym( RTLD_DEFAULT, "get_funky" );
if( funk != NULL ) {
(*funk)();
}
[解决办法]