Commit 9a7e66f8 authored by Damien Fouilleul's avatar Damien Fouilleul

- activex: globally use win32 unicode APIs, hopefully this will fix reported registration problems

parent 96c47fe7
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include <windows.h> #include <windows.h>
#include <shlwapi.h> #include <shlwapi.h>
#include <tchar.h>
#include <guiddef.h> #include <guiddef.h>
using namespace std; using namespace std;
...@@ -80,10 +81,10 @@ STDAPI DllCanUnloadNow(VOID) ...@@ -80,10 +81,10 @@ STDAPI DllCanUnloadNow(VOID)
return (0 == i_class_ref) ? S_OK: S_FALSE; return (0 == i_class_ref) ? S_OK: S_FALSE;
}; };
static inline HKEY keyCreate(HKEY parentKey, LPCSTR keyName) static inline HKEY keyCreate(HKEY parentKey, LPCTSTR keyName)
{ {
HKEY childKey; HKEY childKey;
if( ERROR_SUCCESS == RegCreateKeyExA(parentKey, keyName, 0, NULL, if( ERROR_SUCCESS == RegCreateKeyEx(parentKey, keyName, 0, NULL,
REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &childKey, NULL) ) REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &childKey, NULL) )
{ {
return childKey; return childKey;
...@@ -91,24 +92,24 @@ static inline HKEY keyCreate(HKEY parentKey, LPCSTR keyName) ...@@ -91,24 +92,24 @@ static inline HKEY keyCreate(HKEY parentKey, LPCSTR keyName)
return NULL; return NULL;
}; };
static inline HKEY keySet(HKEY hKey, LPCSTR valueName, const void *s, size_t len) static inline HKEY keySet(HKEY hKey, LPCTSTR valueName, const void *s, size_t len, DWORD dwType = REG_SZ)
{ {
if( NULL != hKey ) if( NULL != hKey )
{ {
RegSetValueExA(hKey, valueName, 0, REG_SZ, RegSetValueEx(hKey, valueName, 0, dwType,
(const BYTE*)s, len); (const BYTE*)s, len);
} }
return hKey; return hKey;
}; };
static inline HKEY keySetDef(HKEY hKey, const void *s, size_t len) static inline HKEY keySetDef(HKEY hKey, const void *s, size_t len, DWORD dwType = REG_SZ)
{ {
return keySet(hKey, NULL, s, len); return keySet(hKey, NULL, s, len, dwType);
}; };
static inline HKEY keySetDef(HKEY hKey, LPCSTR s) static inline HKEY keySetDef(HKEY hKey, LPCTSTR s)
{ {
return keySetDef(hKey, s, strlen(s)+1); return keySetDef(hKey, s, sizeof(TCHAR)*(_tcslen(s)+1), REG_SZ);
}; };
static inline HKEY keyClose(HKEY hKey) static inline HKEY keyClose(HKEY hKey)
...@@ -122,23 +123,21 @@ static inline HKEY keyClose(HKEY hKey) ...@@ -122,23 +123,21 @@ static inline HKEY keyClose(HKEY hKey)
static HRESULT UnregisterProgID(REFCLSID rclsid, unsigned int version) static HRESULT UnregisterProgID(REFCLSID rclsid, unsigned int version)
{ {
LPCSTR psz_CLSID = CStrFromGUID(rclsid); OLECHAR szCLSID[GUID_STRLEN];
if( NULL == psz_CLSID ) StringFromGUID2(rclsid, szCLSID, GUID_STRLEN);
return E_OUTOFMEMORY;
char progId[sizeof(PROGID_STR)+16]; TCHAR progId[sizeof(PROGID_STR)+16];
sprintf(progId, "%s.%u", PROGID_STR, version); _stprintf(progId, TEXT("%s.%u"), TEXT(PROGID_STR), version);
SHDeleteKeyA(HKEY_CLASSES_ROOT, progId); SHDeleteKey(HKEY_CLASSES_ROOT, progId);
HKEY hClsIDKey; HKEY hClsIDKey;
if( ERROR_SUCCESS == RegOpenKeyExA(HKEY_CLASSES_ROOT, "CLSID", 0, KEY_WRITE, &hClsIDKey) ) if( ERROR_SUCCESS == RegOpenKeyEx(HKEY_CLASSES_ROOT, TEXT("CLSID"), 0, KEY_WRITE, &hClsIDKey) )
{ {
SHDeleteKey(hClsIDKey, psz_CLSID); SHDeleteKey(hClsIDKey, szCLSID);
RegCloseKey(hClsIDKey); RegCloseKey(hClsIDKey);
} }
CoTaskMemFree((void *)psz_CLSID);
}; };
STDAPI DllUnregisterServer(VOID) STDAPI DllUnregisterServer(VOID)
...@@ -173,20 +172,19 @@ STDAPI DllUnregisterServer(VOID) ...@@ -173,20 +172,19 @@ STDAPI DllUnregisterServer(VOID)
return S_OK; return S_OK;
}; };
static HRESULT RegisterClassID(HKEY hParent, REFCLSID rclsid, unsigned int version, BOOL isDefault, const char *path, size_t pathLen) static HRESULT RegisterClassID(HKEY hParent, REFCLSID rclsid, unsigned int version, BOOL isDefault, LPCTSTR path, size_t pathLen)
{ {
char progId[sizeof(PROGID_STR)+16]; TCHAR progId[sizeof(PROGID_STR)+16];
sprintf(progId, "%s.%u", PROGID_STR, version); _stprintf(progId, TEXT("%s.%u"), TEXT(PROGID_STR), version);
char description[sizeof(DESCRIPTION)+16]; TCHAR description[sizeof(DESCRIPTION)+16];
sprintf(description, "%s v%u", DESCRIPTION, version); _stprintf(description, TEXT("%s v%u"), TEXT(DESCRIPTION), version);
HKEY hClassKey; HKEY hClassKey;
{ {
LPCSTR psz_CLSID = CStrFromGUID(rclsid); OLECHAR szCLSID[GUID_STRLEN];
if( NULL == psz_CLSID ) StringFromGUID2(rclsid, szCLSID, GUID_STRLEN);
return E_OUTOFMEMORY;
HKEY hProgKey = keyCreate(HKEY_CLASSES_ROOT, progId); HKEY hProgKey = keyCreate(HKEY_CLASSES_ROOT, progId);
if( NULL != hProgKey ) if( NULL != hProgKey )
...@@ -194,9 +192,9 @@ static HRESULT RegisterClassID(HKEY hParent, REFCLSID rclsid, unsigned int versi ...@@ -194,9 +192,9 @@ static HRESULT RegisterClassID(HKEY hParent, REFCLSID rclsid, unsigned int versi
// default key value // default key value
keySetDef(hProgKey, description); keySetDef(hProgKey, description);
keyClose(keySetDef(keyCreate(hProgKey, "CLSID"), keyClose(keySetDef(keyCreate(hProgKey, TEXT("CLSID")),
psz_CLSID, szCLSID,
GUID_STRLEN)); sizeof(szCLSID)));
//hSubKey = keyClose(keyCreate(hBaseKey, "Insertable")); //hSubKey = keyClose(keyCreate(hBaseKey, "Insertable"));
...@@ -204,22 +202,21 @@ static HRESULT RegisterClassID(HKEY hParent, REFCLSID rclsid, unsigned int versi ...@@ -204,22 +202,21 @@ static HRESULT RegisterClassID(HKEY hParent, REFCLSID rclsid, unsigned int versi
} }
if( isDefault ) if( isDefault )
{ {
hProgKey = keyCreate(HKEY_CLASSES_ROOT, PROGID_STR); hProgKey = keyCreate(HKEY_CLASSES_ROOT, TEXT(PROGID_STR));
if( NULL != hProgKey ) if( NULL != hProgKey )
{ {
// default key value // default key value
keySetDef(hProgKey, description); keySetDef(hProgKey, description);
keyClose(keySetDef(keyCreate(hProgKey, "CLSID"), keyClose(keySetDef(keyCreate(hProgKey, TEXT("CLSID")),
psz_CLSID, szCLSID,
GUID_STRLEN)); sizeof(szCLSID)));
keyClose(keySetDef(keyCreate(hProgKey, "CurVer"), keyClose(keySetDef(keyCreate(hProgKey, TEXT("CurVer")),
progId)); progId));
} }
} }
hClassKey = keyCreate(hParent, psz_CLSID); hClassKey = keyCreate(hParent, szCLSID);
CoTaskMemFree((void *)psz_CLSID);
} }
if( NULL != hClassKey ) if( NULL != hClassKey )
{ {
...@@ -227,45 +224,45 @@ static HRESULT RegisterClassID(HKEY hParent, REFCLSID rclsid, unsigned int versi ...@@ -227,45 +224,45 @@ static HRESULT RegisterClassID(HKEY hParent, REFCLSID rclsid, unsigned int versi
keySetDef(hClassKey, description); keySetDef(hClassKey, description);
// Control key value // Control key value
keyClose(keyCreate(hClassKey, "Control")); keyClose(keyCreate(hClassKey, TEXT("Control")));
// Insertable key value // Insertable key value
//keyClose(keyCreate(hClassKey, "Insertable")); //keyClose(keyCreate(hClassKey, TEXT("Insertable")));
// ToolboxBitmap32 key value // ToolboxBitmap32 key value
{ {
char iconPath[pathLen+3]; TCHAR iconPath[pathLen+3];
memcpy(iconPath, path, pathLen); memcpy(iconPath, path, sizeof(TCHAR)*pathLen);
strcpy(iconPath+pathLen, ",1"); _tcscpy(iconPath+pathLen, TEXT(",1"));
keyClose(keySetDef(keyCreate(hClassKey, keyClose(keySetDef(keyCreate(hClassKey,
"ToolboxBitmap32"), TEXT("ToolboxBitmap32")),
iconPath, sizeof(iconPath))); iconPath, sizeof(iconPath)));
} }
#ifdef BUILD_LOCALSERVER #ifdef BUILD_LOCALSERVER
// LocalServer32 key value // LocalServer32 key value
keyClose(keySetDef(keyCreate(hClassKey, keyClose(keySetDef(keyCreate(hClassKey,
"LocalServer32", path, pathLen+1))); TEXT("LocalServer32"), path, sizeof(TCHAR)*(pathLen+1))));
#else #else
// InprocServer32 key value // InprocServer32 key value
{ {
HKEY hSubKey = keySetDef(keyCreate(hClassKey, HKEY hSubKey = keySetDef(keyCreate(hClassKey,
"InprocServer32"), TEXT("InprocServer32")),
path, pathLen+1); path, sizeof(TCHAR)*(pathLen+1));
keySet(hSubKey, keySet(hSubKey,
"ThreadingModel", TEXT("ThreadingModel"),
THREADING_MODEL, sizeof(THREADING_MODEL)); TEXT(THREADING_MODEL), sizeof(TEXT(THREADING_MODEL)));
keyClose(hSubKey); keyClose(hSubKey);
} }
#endif #endif
// MiscStatus key value // MiscStatus key value
keyClose(keySetDef(keyCreate(hClassKey, keyClose(keySetDef(keyCreate(hClassKey,
"MiscStatus\\1"), TEXT("MiscStatus\\1")),
MISC_STATUS, sizeof(MISC_STATUS))); TEXT(MISC_STATUS), sizeof(TEXT(MISC_STATUS))));
// Programmable key value // Programmable key value
keyClose(keyCreate(hClassKey, "Programmable")); keyClose(keyCreate(hClassKey, TEXT("Programmable")));
// ProgID key value // ProgID key value
keyClose(keySetDef(keyCreate(hClassKey, keyClose(keySetDef(keyCreate(hClassKey,
...@@ -274,23 +271,23 @@ static HRESULT RegisterClassID(HKEY hParent, REFCLSID rclsid, unsigned int versi ...@@ -274,23 +271,23 @@ static HRESULT RegisterClassID(HKEY hParent, REFCLSID rclsid, unsigned int versi
// VersionIndependentProgID key value // VersionIndependentProgID key value
keyClose(keySetDef(keyCreate(hClassKey, keyClose(keySetDef(keyCreate(hClassKey,
"VersionIndependentProgID"), TEXT("VersionIndependentProgID")),
PROGID_STR, sizeof(PROGID_STR))); TEXT(PROGID_STR), sizeof(TEXT(PROGID_STR))));
// Version key value // Version key value
keyClose(keySetDef(keyCreate(hClassKey, keyClose(keySetDef(keyCreate(hClassKey,
"Version"), TEXT("Version")),
"1.0")); TEXT("1.0")));
// TypeLib key value // TypeLib key value
LPCSTR psz_LIBID = CStrFromGUID(LIBID_AXVLC); OLECHAR szLIBID[GUID_STRLEN];
if( NULL != psz_LIBID )
{ StringFromGUID2(LIBID_AXVLC, szLIBID, GUID_STRLEN);
keyClose(keySetDef(keyCreate(hClassKey,
"TypeLib"), keyClose(keySetDef(keyCreate(hClassKey,
psz_LIBID, GUID_STRLEN)); TEXT("TypeLib")),
CoTaskMemFree((void *)psz_LIBID); szLIBID, sizeof(szLIBID)));
}
RegCloseKey(hClassKey); RegCloseKey(hClassKey);
} }
return S_OK; return S_OK;
...@@ -300,14 +297,14 @@ STDAPI DllRegisterServer(VOID) ...@@ -300,14 +297,14 @@ STDAPI DllRegisterServer(VOID)
{ {
DllUnregisterServer(); DllUnregisterServer();
char DllPath[MAX_PATH]; TCHAR DllPath[MAX_PATH];
DWORD DllPathLen=GetModuleFileNameA(h_instance, DllPath, sizeof(DllPath)) ; DWORD DllPathLen=GetModuleFileName(h_instance, DllPath, MAX_PATH) ;
if( 0 == DllPathLen ) if( 0 == DllPathLen )
return E_UNEXPECTED; return E_UNEXPECTED;
HKEY hBaseKey; HKEY hBaseKey;
if( ERROR_SUCCESS != RegOpenKeyExA(HKEY_CLASSES_ROOT, "CLSID", 0, KEY_CREATE_SUB_KEY, &hBaseKey) ) if( ERROR_SUCCESS != RegOpenKeyEx(HKEY_CLASSES_ROOT, TEXT("CLSID"), 0, KEY_CREATE_SUB_KEY, &hBaseKey) )
return SELFREG_E_CLASS; return SELFREG_E_CLASS;
RegisterClassID(hBaseKey, CLSID_VLCPlugin, 1, FALSE, DllPath, DllPathLen); RegisterClassID(hBaseKey, CLSID_VLCPlugin, 1, FALSE, DllPath, DllPathLen);
...@@ -334,34 +331,19 @@ STDAPI DllRegisterServer(VOID) ...@@ -334,34 +331,19 @@ STDAPI DllRegisterServer(VOID)
pcr->Release(); pcr->Release();
} }
// register type lib into the registry
ITypeLib *typeLib;
#ifdef BUILD_LOCALSERVER #ifdef BUILD_LOCALSERVER
// replace .exe by .tlb // replace .exe by .tlb
strcpy(DllPath+DllPathLen-4, ".tlb"); _tcscpy(DllPath+DllPathLen-4, TEXT(".tlb"));
#endif #endif
#ifndef OLE2ANSI // register type lib into the registry
size_t typeLibPathLen = MultiByteToWideChar(CP_ACP, 0, DllPath, -1, NULL, 0); ITypeLib *typeLib;
if( typeLibPathLen > 0 )
{ HRESULT result = LoadTypeLibEx(DllPath, REGKIND_REGISTER, &typeLib);
LPOLESTR typeLibPath = (LPOLESTR)CoTaskMemAlloc(typeLibPathLen*sizeof(wchar_t)); if( SUCCEEDED(result) )
MultiByteToWideChar(CP_ACP, 0, DllPath, DllPathLen, typeLibPath, typeLibPathLen);
if( FAILED(LoadTypeLibEx(typeLibPath, REGKIND_REGISTER, &typeLib)) )
#ifndef BUILD_LOCALSERVER
return SELFREG_E_TYPELIB;
typeLib->Release(); typeLib->Release();
#endif
CoTaskMemFree((void *)typeLibPath);
}
#else
if( FAILED(LoadTypeLibEx((LPOLESTR)DllPath, REGKIND_REGISTER, &typeLib)) )
return SELFREG_E_TYPELIB;
typeLib->Release();
#endif
return S_OK; return result;
}; };
#ifdef BUILD_LOCALSERVER #ifdef BUILD_LOCALSERVER
......
...@@ -430,30 +430,43 @@ HRESULT VLCPlugin::getVLC(libvlc_instance_t** pp_libvlc) ...@@ -430,30 +430,43 @@ HRESULT VLCPlugin::getVLC(libvlc_instance_t** pp_libvlc)
int ppsz_argc = 1; int ppsz_argc = 1;
HKEY h_key; HKEY h_key;
DWORD i_type, i_data = MAX_PATH + 1; char p_data[MAX_PATH];
char p_data[MAX_PATH + 1]; if( RegOpenKeyEx( HKEY_LOCAL_MACHINE, TEXT("Software\\VideoLAN\\VLC"),
if( RegOpenKeyEx( HKEY_LOCAL_MACHINE, "Software\\VideoLAN\\VLC",
0, KEY_READ, &h_key ) == ERROR_SUCCESS ) 0, KEY_READ, &h_key ) == ERROR_SUCCESS )
{ {
if( RegQueryValueEx( h_key, "InstallDir", 0, &i_type, DWORD i_type, i_data = MAX_PATH;
(LPBYTE)p_data, &i_data ) == ERROR_SUCCESS ) TCHAR w_data[MAX_PATH];
if( RegQueryValueEx( h_key, TEXT("InstallDir"), 0, &i_type,
(LPBYTE)w_data, &i_data ) == ERROR_SUCCESS )
{ {
if( i_type == REG_SZ ) if( i_type == REG_SZ )
{ {
strcat( p_data, "\\plugins" ); if( WideCharToMultiByte(CP_UTF8, 0, w_data, -1, p_data,
ppsz_argv[ppsz_argc++] = "--plugin-path"; sizeof(p_data)-sizeof("\\plugins")+1, NULL, NULL) )
ppsz_argv[ppsz_argc++] = p_data; {
strcat( p_data, "\\plugins" );
ppsz_argv[ppsz_argc++] = "--plugin-path";
ppsz_argv[ppsz_argc++] = p_data;
}
} }
} }
RegCloseKey( h_key ); RegCloseKey( h_key );
} }
char p_path[MAX_PATH+1]; char p_path[MAX_PATH];
DWORD len = GetModuleFileNameA(DllGetModule(), p_path, sizeof(p_path));
if( len > 0 )
{ {
p_path[len] = '\0'; TCHAR w_path[MAX_PATH];
ppsz_argv[0] = p_path; DWORD len = GetModuleFileName(DllGetModule(), w_path, MAX_PATH);
if( len > 0 )
{
len = WideCharToMultiByte(CP_UTF8, 0, w_path, len, p_path,
sizeof(p_path)-1, NULL, NULL);
if( len > 0 )
{
p_path[len] = '\0';
ppsz_argv[0] = p_path;
}
}
} }
// make sure plugin isn't affected with VLC single instance mode // make sure plugin isn't affected with VLC single instance mode
...@@ -681,7 +694,7 @@ HRESULT VLCPlugin::onActivateInPlace(LPMSG lpMesg, HWND hwndParent, LPCRECT lprc ...@@ -681,7 +694,7 @@ HRESULT VLCPlugin::onActivateInPlace(LPMSG lpMesg, HWND hwndParent, LPCRECT lprc
** properly displayed. ** properly displayed.
*/ */
_inplacewnd = CreateWindow(_p_class->getInPlaceWndClassName(), _inplacewnd = CreateWindow(_p_class->getInPlaceWndClassName(),
"VLC Plugin In-Place Window", TEXT("VLC Plugin In-Place Window"),
WS_CHILD|WS_CLIPCHILDREN|WS_CLIPSIBLINGS, WS_CHILD|WS_CLIPCHILDREN|WS_CLIPSIBLINGS,
lprcPosRect->left, lprcPosRect->left,
lprcPosRect->top, lprcPosRect->top,
......
...@@ -51,7 +51,7 @@ public: ...@@ -51,7 +51,7 @@ public:
REFCLSID getClassID(void) { return (REFCLSID)_classid; }; REFCLSID getClassID(void) { return (REFCLSID)_classid; };
LPCSTR getInPlaceWndClassName(void) const { return TEXT("VLC Plugin In-Place"); }; LPCTSTR getInPlaceWndClassName(void) const { return TEXT("VLC Plugin In-Place"); };
HINSTANCE getHInstance(void) const { return _hinstance; }; HINSTANCE getHInstance(void) const { return _hinstance; };
LPPICTURE getInPlacePict(void) const LPPICTURE getInPlacePict(void) const
{ if( NULL != _inplace_picture) _inplace_picture->AddRef(); return _inplace_picture; }; { if( NULL != _inplace_picture) _inplace_picture->AddRef(); return _inplace_picture; };
......
...@@ -77,28 +77,6 @@ BSTR BSTRFromCStr(UINT codePage, LPCSTR s) ...@@ -77,28 +77,6 @@ BSTR BSTRFromCStr(UINT codePage, LPCSTR s)
return NULL; return NULL;
}; };
char *CStrFromGUID(REFGUID clsid)
{
LPOLESTR oleStr;
if( FAILED(StringFromIID(clsid, &oleStr)) )
return NULL;
#ifdef OLE2ANSI
return (LPCSTR)oleStr;
#else
char *pct_CLSID = NULL;
size_t len = WideCharToMultiByte(CP_ACP, 0, oleStr, -1, NULL, 0, NULL, NULL);
if( len > 0 )
{
pct_CLSID = (char *)CoTaskMemAlloc(len);
WideCharToMultiByte(CP_ACP, 0, oleStr, -1, pct_CLSID, len, NULL, NULL);
}
CoTaskMemFree(oleStr);
return pct_CLSID;
#endif
};
/* /*
** properties ** properties
*/ */
......
...@@ -32,8 +32,6 @@ extern char *CStrFromWSTR(UINT codePage, LPCWSTR wstr, UINT len); ...@@ -32,8 +32,6 @@ extern char *CStrFromWSTR(UINT codePage, LPCWSTR wstr, UINT len);
extern char *CStrFromBSTR(UINT codePage, BSTR bstr); extern char *CStrFromBSTR(UINT codePage, BSTR bstr);
extern BSTR BSTRFromCStr(UINT codePage, LPCSTR s); extern BSTR BSTRFromCStr(UINT codePage, LPCSTR s);
extern char *CStrFromGUID(REFGUID clsid);
// properties // properties
extern HRESULT GetObjectProperty(LPUNKNOWN object, DISPID dispID, VARIANT& v); extern HRESULT GetObjectProperty(LPUNKNOWN object, DISPID dispID, VARIANT& v);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment