1
0

forceUrl.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #include "main.h"
  2. #include "./forceUrl.h"
  3. typedef struct __FORCEURLDATA
  4. {
  5. UINT serviceId;
  6. LPWSTR url;
  7. } FORCEURLDATA;
  8. #define FORCEURLPROP L"MLWEBDEV_FORCEURL"
  9. void ForceUrl_Remove()
  10. {
  11. HWND hLibrary = Plugin_GetLibrary();
  12. if (NULL == hLibrary) return;
  13. FORCEURLDATA *data = (FORCEURLDATA*)GetProp(hLibrary, FORCEURLPROP);
  14. RemoveProp(hLibrary, FORCEURLPROP);
  15. if (NULL != data)
  16. {
  17. Plugin_FreeString(data->url);
  18. free(data);
  19. }
  20. }
  21. HRESULT ForceUrl_Set(UINT serviceId, LPCWSTR pszUrl)
  22. {
  23. if (NULL == pszUrl) return E_INVALIDARG;
  24. HWND hLibrary = Plugin_GetLibrary();
  25. if (NULL == hLibrary) return E_FAIL;
  26. FORCEURLDATA *data = (FORCEURLDATA*)GetProp(hLibrary, FORCEURLPROP);
  27. if (NULL != data)
  28. {
  29. Plugin_FreeString(data->url);
  30. if (data->serviceId != serviceId)
  31. {
  32. free(data);
  33. data = NULL;
  34. }
  35. }
  36. if (NULL == data)
  37. {
  38. data = (FORCEURLDATA*)malloc(sizeof(FORCEURLDATA));
  39. if (NULL == data) return E_OUTOFMEMORY;
  40. data->serviceId = serviceId;
  41. }
  42. data->url = Plugin_CopyString(pszUrl);
  43. if (NULL == data->url || FALSE == SetProp(hLibrary, FORCEURLPROP, data))
  44. {
  45. ForceUrl_Remove();
  46. return E_FAIL;
  47. }
  48. return S_OK;
  49. }
  50. HRESULT ForceUrl_Get(UINT serviceId, const wchar_t **ppszUrl)
  51. {
  52. if (NULL == ppszUrl) return E_POINTER;
  53. *ppszUrl = NULL;
  54. HWND hLibrary = Plugin_GetLibrary();
  55. if (NULL == hLibrary) return E_FAIL;
  56. FORCEURLDATA *data = (FORCEURLDATA*)GetProp(hLibrary, FORCEURLPROP);
  57. if (NULL == data || data->serviceId != serviceId)
  58. return E_NOINTERFACE;
  59. *ppszUrl = data->url;
  60. return S_OK;
  61. }