diff --git a/src/Makefile.am b/src/Makefile.am index cda6a01..71df1b4 100755 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -358,7 +358,8 @@ if BUILD_WIN32 libmediastreamer_base_la_LIBADD+= -lole32 \ -loleaut32\ -lwinmm \ - -luuid + -luuid \ + -lshlwapi endif if BUILD_WIN32_WCE diff --git a/src/audiofilters/winsnd3.c b/src/audiofilters/winsnd3.c index 3c00618..9ba7811 100644 --- a/src/audiofilters/winsnd3.c +++ b/src/audiofilters/winsnd3.c @@ -18,15 +18,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #define UNICODE +#define _UNICODE #include "mediastreamer2/mssndcard.h" #include "mediastreamer2/msfilter.h" #include "mediastreamer2/msticker.h" #include -#ifdef _MSC_VER #include -#endif #include #if defined(_WIN32_WCE) diff --git a/src/base/msfactory.c b/src/base/msfactory.c index f1b270d..68e5d0f 100644 --- a/src/base/msfactory.c +++ b/src/base/msfactory.c @@ -34,25 +34,27 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "basedescs.h" #if !defined(_WIN32_WCE) -#include +# include #endif #ifndef WIN32 -#include +# include #else -#ifndef PACKAGE_PLUGINS_DIR -#if defined(WIN32) || defined(_WIN32_WCE) -#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) -#define PACKAGE_PLUGINS_DIR "lib\\mediastreamer\\plugins\\" -#else -#define PACKAGE_PLUGINS_DIR "." -#endif -#else -#define PACKAGE_PLUGINS_DIR "." -#endif -#endif +# include +# include +# ifndef PACKAGE_PLUGINS_DIR +# if defined(WIN32) || defined(_WIN32_WCE) +# if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) +# define PACKAGE_PLUGINS_DIR "lib\\mediastreamer\\plugins\\" +# else +# define PACKAGE_PLUGINS_DIR "." +# endif +# else +# define PACKAGE_PLUGINS_DIR "." +# endif +# endif #endif #ifdef HAVE_DLOPEN -#include +# include #endif #ifdef __APPLE__ @@ -429,35 +431,60 @@ int ms_factory_load_plugins(MSFactory *factory, const char *dir){ #if defined(WIN32) && !defined(_WIN32_WCE) WIN32_FIND_DATA FileData; HANDLE hSearch; - char szDirPath[1024]; -#ifdef UNICODE wchar_t wszDirPath[1024]; -#endif + wchar_t wszPluginFile[1024]; + char szDirPath[1024]; char szPluginFile[1024]; BOOL fFinished = FALSE; const char *tmp=getenv("DEBUG"); BOOL debug=(tmp!=NULL && atoi(tmp)==1); - snprintf(szDirPath, sizeof(szDirPath), "%s", dir); + wchar_t *wszExePath; /* eg. C:\Program Files\Linphone\bin, but we'll find out! */ + wchar_t *wszRelativePluginPath = L"..\\lib\\mediastreamer\\plugins"; + wchar_t *wszFullPluginPath; + + wszExePath = (wchar_t *)malloc(MAX_PATH); + ZeroMemory(wszExePath, sizeof(wszExePath)); + + GetModuleFileNameW(NULL, wszExePath, MAX_PATH); // Get full path name for the running exe, argv[0] is unreliable for this + PathRemoveFileSpecW(wszExePath); // From , Strip file name part + // wprintf(L"%ls\n", wszExePath); + + wszFullPluginPath = (wchar_t *)malloc(MAX_PATH); + ZeroMemory(wszFullPluginPath, sizeof(wszFullPluginPath)); - // Start searching for .dll files in the current directory. + wcsncat(wszFullPluginPath, wszExePath, wcslen(wszExePath)); + wcsncat(wszFullPluginPath, L"\\", 1); + wcsncat(wszFullPluginPath, wszRelativePluginPath, wcslen(wszRelativePluginPath)); + + // wprintf(L"wszFullPluginPath = %ls\n", wszFullPluginPath); + + // Start searching for .dll files in wszFullPluginPath. #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) - snprintf(szDirPath, sizeof(szDirPath), "%s\\*.dll", dir); + _snwprintf(wszDirPath, sizeof(wszDirPath), L"%ls\\*.dll", wszFullPluginPath); + // wprintf(L"wszDirPath = %ls\n", wszDirPath); #else - snprintf(szDirPath, sizeof(szDirPath), "%s\\libms*.dll", dir); + _snwprintf(wszDirPath, sizeof(wszDirPath), L"%ls\\libms*.dll", wszFullPluginPath); #endif + + #ifdef UNICODE - mbstowcs(wszDirPath, szDirPath, sizeof(wszDirPath)); hSearch = FindFirstFileExW(wszDirPath, FindExInfoStandard, &FileData, FindExSearchNameMatch, NULL, 0); #else + wcstombs(szDirPath, wszDirPath, sizeof(szDirPath)); hSearch = FindFirstFileExA(szDirPath, FindExInfoStandard, &FileData, FindExSearchNameMatch, NULL, 0); #endif if (hSearch == INVALID_HANDLE_VALUE) { - ms_message("no plugin (*.dll) found in [%s] [%d].", szDirPath, (int)GetLastError()); + // wprintf(L"no plugin (*.dll) found in [%ls] [%d].\n", wszDirPath, (int)GetLastError()); + ms_message("no plugin (*.dll) found in [%ls] [%d].", wszDirPath, (int)GetLastError()); return 0; } - snprintf(szDirPath, sizeof(szDirPath), "%s", dir); + + // // Go further with dir + // _snprintf(szDirPath, sizeof(szDirPath), "%s", dir); + // mbstowcs(wszDirPath, szDirPath, sizeof(wszDirPath)); + // printf("szDirPath = %s\n", szDirPath); while (!fFinished) { @@ -467,46 +494,49 @@ int ms_factory_load_plugins(MSFactory *factory, const char *dir){ #endif HINSTANCE os_handle; #ifdef UNICODE - wchar_t wszPluginFile[2048]; - char filename[512]; - wcstombs(filename, FileData.cFileName, sizeof(filename)); - snprintf(szPluginFile, sizeof(szPluginFile), "%s\\%s", szDirPath, filename); - mbstowcs(wszPluginFile, szPluginFile, sizeof(wszPluginFile)); + _snwprintf(wszPluginFile, sizeof(wszPluginFile), L"%ls\\%ls", wszFullPluginPath, FileData.cFileName); + // wprintf(L"wszPluginFile = %ls, FileData.cFileName = \n", wszPluginFile, FileData.cFileName); #else - snprintf(szPluginFile, sizeof(szPluginFile), "%s\\%s", szDirPath, FileData.cFileName); + char szFullPluginPath[1024]; + wcstombs(szFullPluginPath, wszFullPluginPath, sizeof(szFullPluginPath)); + _snprintf(szPluginFile, sizeof(szPluginFile), "%s\\%s", szFullPluginPath, FileData.cFileName); #endif #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) if (!debug) em = SetErrorMode (SEM_FAILCRITICALERRORS); #ifdef UNICODE os_handle = LoadLibraryExW(wszPluginFile, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); + if (os_handle==NULL) + { + // wprintf(L"Fail to load plugin %ls with altered search path: error %i\n",wszPluginFile,(int)GetLastError()); + ms_message("Fail to load plugin %ls with altered search path: error %i",wszPluginFile,(int)GetLastError()); + os_handle = LoadLibraryExW(wszPluginFile, NULL, 0); + } #else os_handle = LoadLibraryExA(szPluginFile, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); -#endif if (os_handle==NULL) { ms_message("Fail to load plugin %s with altered search path: error %i",szPluginFile,(int)GetLastError()); -#ifdef UNICODE - os_handle = LoadLibraryExW(wszPluginFile, NULL, 0); -#else os_handle = LoadLibraryExA(szPluginFile, NULL, 0); -#endif } +#endif if (!debug) SetErrorMode (em); #else os_handle = LoadPackagedLibrary(wszPluginFile, 0); #endif - if (os_handle==NULL) - ms_error("Fail to load plugin %s: error %i", szPluginFile, (int)GetLastError()); - else{ + if (os_handle == NULL) { + ms_error("Fail to load plugin %ls: error %i", wszPluginFile, (int)GetLastError()); + } else { init_func_t initroutine; char szPluginName[256]; char szMethodName[256]; char *minus; #ifdef UNICODE - snprintf(szPluginName, sizeof(szPluginName), "%s", filename); + wchar_t wszPluginName[256]; + _snwprintf(wszPluginName, sizeof(szPluginName), L"%ls", FileData.cFileName); + wcstombs(szPluginName, wszPluginName, sizeof(szPluginName)); #else - snprintf(szPluginName, sizeof(szPluginName), "%s", FileData.cFileName); + _snprintf(szPluginName, sizeof(szPluginName), "%s", FileData.cFileName); #endif /*on mingw, dll names might be libsomething-3.dll. We must skip the -X.dll stuff*/ minus=strchr(szPluginName,'-'); @@ -514,16 +544,15 @@ int ms_factory_load_plugins(MSFactory *factory, const char *dir){ else szPluginName[strlen(szPluginName)-4]='\0'; /*remove .dll*/ snprintf(szMethodName, sizeof(szMethodName), "%s_init", szPluginName); initroutine = (init_func_t) GetProcAddress (os_handle, szMethodName); - if (initroutine!=NULL){ - initroutine(factory); - ms_message("Plugin loaded (%s)", szPluginFile); - // Add this new loaded plugin to the list (useful for FreeLibrary at the end) - factory->ms_plugins_loaded_list=ms_list_append(factory->ms_plugins_loaded_list,os_handle); - num++; - }else{ - ms_warning("Could not locate init routine of plugin %s. Should be %s", - szPluginFile, szMethodName); - } + if (initroutine!=NULL){ + initroutine(factory); + ms_message("Plugin loaded (%s)", szPluginFile); + // Add this new loaded plugin to the list (useful for FreeLibrary at the end) + factory->ms_plugins_loaded_list=ms_list_append(factory->ms_plugins_loaded_list,os_handle); + num++; + }else{ + ms_warning("Could not locate init routine of plugin %s. Should be %s", szPluginFile, szMethodName); + } } if (!FindNextFile(hSearch, &FileData)) { if (GetLastError() == ERROR_NO_MORE_FILES){ @@ -539,6 +568,9 @@ int ms_factory_load_plugins(MSFactory *factory, const char *dir){ /* Close the search handle. */ FindClose(hSearch); + free(wszExePath); + free(wszFullPluginPath); + #elif defined(HAVE_DLOPEN) char plugin_name[64]; DIR *ds;