main.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. #include "main.h"
  2. #include "./navigation.h"
  3. #include "./wasabi.h"
  4. #include "./resource.h"
  5. #include "./external.h"
  6. #include "./serviceHost.h"
  7. #include "./import.h"
  8. #include "../winamp/wa_ipc.h"
  9. #include <initguid.h>
  10. #include <strsafe.h>
  11. static DWORD externalCookie = 0;
  12. static Navigation *navigation = NULL;
  13. // {BF4F80A7-7470-4b08-8A4C-34382C146202}
  14. DEFINE_GUID(WebDevLangUid, 0xbf4f80a7, 0x7470, 0x4b08, 0x8a, 0x4c, 0x34, 0x38, 0x2c, 0x14, 0x62, 0x2);
  15. static int Plugin_Init();
  16. static void Plugin_Quit();
  17. static INT_PTR Plugin_MessageProc(INT msg, INT_PTR param1, INT_PTR param2, INT_PTR param3);
  18. extern "C" winampMediaLibraryPlugin plugin =
  19. {
  20. MLHDR_VER,
  21. "nullsoft(ml_webdev.dll)",
  22. Plugin_Init,
  23. Plugin_Quit,
  24. Plugin_MessageProc,
  25. 0,
  26. 0,
  27. 0,
  28. };
  29. HINSTANCE Plugin_GetInstance(void)
  30. {
  31. return plugin.hDllInstance;
  32. }
  33. HWND Plugin_GetWinamp(void)
  34. {
  35. return plugin.hwndWinampParent;
  36. }
  37. HWND Plugin_GetLibrary(void)
  38. {
  39. return plugin.hwndLibraryParent;
  40. }
  41. HRESULT Plugin_GetExternal(ExternalDispatch **ppExternal)
  42. {
  43. if (NULL == ppExternal) return E_POINTER;
  44. HRESULT hr = ExternalDispatch::CreateInstance(ppExternal);
  45. return hr;
  46. }
  47. static int Plugin_Init()
  48. {
  49. if (!WasabiApi_Initialize(Plugin_GetInstance()))
  50. return 1;
  51. if (NULL == OMBROWSERMNGR ||
  52. NULL == OMSERVICEMNGR ||
  53. NULL == OMUTILITY )
  54. {
  55. return 2;
  56. }
  57. if (NULL != WASABI_API_LNG)
  58. {
  59. static wchar_t szDescription[256];
  60. StringCchPrintf(szDescription, ARRAYSIZE(szDescription),
  61. WASABI_API_LNGSTRINGW(IDS_PLUGIN_NAME),
  62. PLUGIN_VERSION_MAJOR, PLUGIN_VERSION_MINOR);
  63. plugin.description = (char*)szDescription;
  64. }
  65. ExternalDispatch *externalDispatch;
  66. if (SUCCEEDED(ExternalDispatch::CreateInstance(&externalDispatch)))
  67. {
  68. DispatchInfo dispatchInfo;
  69. dispatchInfo.id = 0;
  70. dispatchInfo.name =(LPWSTR)externalDispatch->GetName();
  71. dispatchInfo.dispatch = externalDispatch;
  72. if (0 == SENDWAIPC(Plugin_GetWinamp(), IPC_ADD_DISPATCH_OBJECT, (WPARAM)&dispatchInfo))
  73. externalCookie = dispatchInfo.id;
  74. externalDispatch->Release();
  75. }
  76. if (NULL == navigation)
  77. {
  78. if (FAILED(Navigation::CreateInstance(&navigation)))
  79. {
  80. navigation = NULL;
  81. if (0 != externalCookie)
  82. {
  83. HWND hWinamp = Plugin_GetWinamp();
  84. SENDWAIPC(hWinamp, IPC_REMOVE_DISPATCH_OBJECT, (WPARAM)externalCookie);
  85. externalCookie = 0;
  86. }
  87. return 2;
  88. }
  89. }
  90. return 0;
  91. }
  92. static void Plugin_Quit()
  93. {
  94. if (0 != externalCookie)
  95. {
  96. HWND hWinamp = Plugin_GetWinamp();
  97. SENDWAIPC(hWinamp, IPC_REMOVE_DISPATCH_OBJECT, (WPARAM)externalCookie);
  98. externalCookie = 0;
  99. }
  100. WebDevServiceHost::ReleseCache();
  101. if (NULL != navigation)
  102. {
  103. navigation->Finish();
  104. navigation->Release();
  105. navigation = NULL;
  106. }
  107. ImportService_SaveRecentUrl();
  108. WasabiApi_Release();
  109. }
  110. static INT_PTR Plugin_MessageProc(INT msg, INT_PTR param1, INT_PTR param2, INT_PTR param3)
  111. {
  112. INT_PTR result = 0;
  113. if (NULL != navigation &&
  114. FALSE != navigation->ProcessMessage(msg, param1, param2, param3, &result))
  115. {
  116. return result;
  117. }
  118. return FALSE;
  119. }
  120. HRESULT Plugin_GetNavigation(Navigation **instance)
  121. {
  122. if(NULL == instance) return E_POINTER;
  123. if (NULL == navigation)
  124. {
  125. *instance = NULL;
  126. return E_UNEXPECTED;
  127. }
  128. *instance = navigation;
  129. navigation->AddRef();
  130. return S_OK;
  131. }
  132. EXTERN_C __declspec(dllexport) winampMediaLibraryPlugin *winampGetMediaLibraryPlugin()
  133. {
  134. return &plugin;
  135. }