#include #include #include #include //#include "resource.h" #include "musenc.h" static HINSTANCE hModule = NULL; typedef MERET (*me_init)(void); typedef MERET (*me_setconf)(MPARAM mode, UPARAM dwPara1, UPARAM dwPara2 ); typedef MERET (*me_getconf)(MPARAM mode, void *para1 ); typedef MERET (*me_detect)(); typedef MERET (*me_procframe)(); typedef MERET (*me_close)(); typedef MERET (*me_end)(); typedef MERET (*me_getver)( unsigned long *vercode, char *verstring ); typedef MERET (*me_haveunit)( unsigned long *unit ); static me_init mpge_init; static me_setconf mpge_setconf; static me_getconf mpge_getconf; static me_detect mpge_detector; static me_procframe mpge_processframe; static me_close mpge_close; static me_end mpge_end; static me_getver mpge_getver; static me_haveunit mpge_haveunit; // DLLの読み込み(最初の1回目のみ)とワークエリアの初期化を行います。 MERET MPGE_initializeWork() { if( hModule == NULL ){ // (DLLが読み込まれていない場合) // カレントディレクトリ、及びsystemディレクトリのGOGO.DLLの読み込み hModule = LoadLibrary("gogo.dll"); if( hModule == NULL ){ // DLLが見つからない場合 #define Key HKEY_CURRENT_USER #define SubKey "Software\\MarineCat\\GOGO_DLL" HKEY hKey; DWORD dwType, dwKeySize; LONG lResult; static char *szName = "INSTPATH"; char szPathName[ _MAX_PATH + 8]; dwKeySize = sizeof( szPathName ); // レジストリ項目の HEY_CURENT_USER\Software\MarineCat\GOGO_DLLキー以下の // INSTPATH (REG_SZ)を取得します。 if( RegOpenKeyEx( Key, SubKey, 0, KEY_ALL_ACCESS, &hKey ) == ERROR_SUCCESS ){ lResult = RegQueryValueEx( hKey, szName, 0, &dwType, (BYTE *)szPathName, &dwKeySize); RegCloseKey(hKey); if( lResult == ERROR_SUCCESS && REG_SZ == dwType ){ // レジストリから取得したパスで再度DLLの読み込みを試みる hModule = LoadLibrary( szPathName ); } } } // DLLが見つからない if( hModule == NULL ){ // MessageBox( "DLLの読み込みを失敗しました。\nDLLをEXEファイルと同じディレクトリへ複写してください\n"); fprintf( stderr,"DLLの読み込みを失敗しました。\nDLLをEXEファイルと同じディレクトリへ複写してください\n"); exit( -1 ); } // エクスポート関数の取得 mpge_init = (me_init )GetProcAddress( hModule, "MPGE_initializeWork" ); mpge_setconf = (me_setconf )GetProcAddress( hModule, "MPGE_setConfigure" ); mpge_getconf = (me_getconf )GetProcAddress( hModule, "MPGE_getConfigure" ); mpge_detector = (me_detect )GetProcAddress( hModule, "MPGE_detectConfigure" ); mpge_processframe = (me_procframe )GetProcAddress( hModule, "MPGE_processFrame" ); mpge_close = (me_close )GetProcAddress( hModule, "MPGE_closeCoder" ); mpge_end = (me_end )GetProcAddress( hModule, "MPGE_endCoder" ); mpge_getver = (me_getver )GetProcAddress( hModule, "MPGE_getVersion" ); mpge_haveunit= (me_haveunit )GetProcAddress( hModule, "MPGE_getUnitStates" ); } // すべての関数が正常か確認する if( mpge_init && mpge_setconf && mpge_getconf && mpge_detector && mpge_processframe && mpge_end && mpge_getver && mpge_haveunit ) return (mpge_init)(); // エラー fprintf( stderr, "DLLの内容を正しく識別することが出来ませんでした\n"); FreeLibrary( hModule ); hModule = NULL; exit( -1 ); return ME_NOERR; } MERET MPGE_setConfigure(MPARAM mode, UPARAM dwPara1, UPARAM dwPara2 ) { return (mpge_setconf)( mode, dwPara1, dwPara2 ); } MERET MPGE_getConfigure(MPARAM mode, void *para1 ) { return (mpge_getconf)( mode, para1 ); } MERET MPGE_detectConfigure() { return (mpge_detector)(); } MERET MPGE_processFrame() { return (mpge_processframe)(); } MERET MPGE_closeCoder() { return (mpge_close)(); } MERET MPGE_endCoder() { MERET val = (mpge_end)(); if( val == ME_NOERR ){ FreeLibrary( hModule ); // DLL開放 hModule = NULL; } return val; } MERET MPGE_getVersion( unsigned long *vercode, char *verstring ) { return (mpge_getver)( vercode, verstring ); } MERET MPGE_getUnitStates( unsigned long *unit) { return (mpge_haveunit)( unit ); }