5typedef MERROR_RETVAL (*mplug_proc_t)(
void* data,
size_t data_sz );
10typedef HMODULE mplug_mod_t;
11# define MPLUG_EXPORT extern __declspec( dllexport )
13typedef void* mplug_mod_t;
18 const char* plugin_path, mplug_mod_t* p_mod_exe );
21 mplug_mod_t mod_exe,
const char* proc_name,
void* data,
size_t data_sz );
23void mplug_free( mplug_mod_t mod_exe );
27#if defined( RETROFLAT_OS_UNIX )
32 const char* plugin_basename, mplug_mod_t* p_mod_exe
35 char plugin_path[MAUG_PATH_SZ_MAX + 1] = { 0 };
36#ifdef RETROFLAT_OS_WIN
39 wchar_t plugin_path_w[MAUG_PATH_SZ_MAX + 1] = { 0 };
43 memset( plugin_path,
'\0', MAUG_PATH_SZ_MAX + 1 );
45#if defined( RETROFLAT_OS_UNIX )
46 maug_snprintf( plugin_path, MAUG_PATH_SZ_MAX,
"%s.so", plugin_basename );
47 *p_mod_exe = dlopen( plugin_path, RTLD_LAZY );
48#elif defined( RETROFLAT_OS_WIN )
50 plugin_path, MAUG_PATH_SZ_MAX,
"%s.dll", plugin_basename );
51 for( i = 0 ; MAUG_PATH_SZ_MAX > i ; i++ ) {
52 if(
'/' == plugin_path[i] ) {
53 plugin_path[i] =
'\\';
57 if( 0 == MultiByteToWideChar(
58 CP_ACP, MB_PRECOMPOSED, plugin_path, -1,
59 plugin_path_w, MAUG_PATH_SZ_MAX
62 "unable to convert wide path for module: %s", plugin_path );
67 *p_mod_exe = (mplug_mod_t)LoadLibraryW( plugin_path_w );
69 *p_mod_exe = (mplug_mod_t)LoadLibrary( plugin_path );
75 if( NULL != plugin_path_w ) {
76 free( plugin_path_w );
80# pragma message( "warning: dlopen undefined!" )
83 if( (mplug_mod_t)NULL == *p_mod_exe ) {
84 error_printf(
"unable to load module: %s", plugin_path );
92 mplug_mod_t mod_exe,
const char* proc_name,
void* data,
size_t data_sz
95 mplug_proc_t plugin_proc = (mplug_proc_t)NULL;
96#ifdef RETROFLAT_OS_WIN
97 char proc_name_ex[MAUG_PATH_SZ_MAX + 1] = { 0 };
99 wchar_t proc_name_ex_w[MAUG_PATH_SZ_MAX + 1] = { 0 };
103#ifdef RETROFLAT_OS_UNIX
104 plugin_proc = dlsym( mod_exe, proc_name );
105#elif defined( RETROFLAT_OS_WIN )
106 memset( proc_name_ex,
'\0', MAUG_PATH_SZ_MAX + 1 );
109 maug_snprintf( proc_name_ex, MAUG_PATH_SZ_MAX,
"%s_", proc_name );
111# if defined( MAUG_WCHAR ) && defined( RETROFLAT_API_WINCE )
112 if( 0 == MultiByteToWideChar(
113 CP_ACP, MB_PRECOMPOSED, proc_name_ex, -1, proc_name_ex_w,
116 error_printf(
"could not create wide proc name!" );
117 retval = MERROR_FILE;
121 plugin_proc = (mplug_proc_t)GetProcAddressW( mod_exe, proc_name_ex_w );
123 plugin_proc = (mplug_proc_t)GetProcAddress( mod_exe, proc_name_ex );
126# pragma message( "dlsym undefined!" )
129 if( (mplug_proc_t)NULL == plugin_proc ) {
130 error_printf(
"unable to load proc: %s", proc_name );
131 retval = MERROR_FILE;
135 retval = plugin_proc( data, data_sz );
141void mplug_free( mplug_mod_t mod_exe ) {
142#ifdef RETROFLAT_OS_UNIX
144#elif defined( RETROFLAT_OS_WIN )
145 FreeLibrary( mod_exe );
147# pragma message( "dlclose undefined!" )
int MERROR_RETVAL
Return type indicating function returns a value from this list.
Definition merror.h:19