plugin.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #include "main.h"
  2. #include "../../winamp/gen.h"
  3. #include <strsafe.h>
  4. static INT
  5. Plugin_Init(void);
  6. static void
  7. Plugin_Quit(void);
  8. static void
  9. Plugin_Config(void);
  10. extern "C" winampGeneralPurposePlugin plugin =
  11. {
  12. GPPHDR_VER,
  13. 0,
  14. Plugin_Init,
  15. Plugin_Config,
  16. Plugin_Quit,
  17. };
  18. static DeviceProvider *deviceProvider = NULL;
  19. HINSTANCE
  20. Plugin_GetInstance(void)
  21. {
  22. return plugin.hDllInstance;
  23. }
  24. HWND
  25. Plugin_GetWinampWindow(void)
  26. {
  27. return plugin.hwndParent;
  28. }
  29. static void
  30. Plugin_SetDescription()
  31. {
  32. WCHAR szBuffer[256], szTemplate[256];
  33. if (0 != plugin.description)
  34. AnsiString_Free(plugin.description);
  35. if (NULL != WASABI_API_LNG)
  36. WASABI_API_LNGSTRINGW_BUF(IDS_PLUGIN_NAME, szTemplate, ARRAYSIZE(szTemplate));
  37. else
  38. szTemplate[0] = L'\0';
  39. StringCchPrintf(szBuffer, ARRAYSIZE(szBuffer),
  40. ((L'\0' != szTemplate[0]) ? szTemplate : L"Nullsoft Test Device Provider v%d.%d"),
  41. PLUGIN_VERSION_MAJOR, PLUGIN_VERSION_MINOR);
  42. plugin.description = String_ToAnsi(CP_ACP, 0, szBuffer, -1, NULL, NULL);
  43. }
  44. static INT
  45. Plugin_Init(void)
  46. {
  47. if (FALSE == Wasabi_InitializeFromWinamp(plugin.hDllInstance, plugin.hwndParent))
  48. return 1;
  49. Wasabi_LoadDefaultServices();
  50. Plugin_SetDescription();
  51. if (NULL == deviceProvider)
  52. {
  53. if (FAILED(DeviceProvider::CreateInstance(&deviceProvider)))
  54. {
  55. Wasabi_Release();
  56. return 2;
  57. }
  58. deviceProvider->Register(WASABI_API_DEVICES);
  59. }
  60. return 0;
  61. }
  62. static void
  63. Plugin_Quit(void)
  64. {
  65. if (0 != plugin.description)
  66. {
  67. AnsiString_Free(plugin.description);
  68. plugin.description = 0;
  69. }
  70. if (NULL != deviceProvider)
  71. {
  72. deviceProvider->Unregister(WASABI_API_DEVICES);
  73. deviceProvider->Release();
  74. }
  75. Wasabi_Release();
  76. }
  77. static void
  78. Plugin_Config(void)
  79. {
  80. }
  81. EXTERN_C __declspec(dllexport) winampGeneralPurposePlugin *
  82. winampGetGeneralPurposePlugin()
  83. {
  84. if (0 == plugin.description)
  85. {
  86. Plugin_SetDescription();
  87. }
  88. return &plugin;
  89. }