BookmarksCOM.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /** (c) Nullsoft, Inc. C O N F I D E N T I A L
  2. ** Filename:
  3. ** Project:
  4. ** Description:
  5. ** Author: Ben Allison [email protected]
  6. ** Created:
  7. **/
  8. #include "main.h"
  9. #include "BookmarksCOM.h"
  10. #include "../nu/AutoChar.h"
  11. #include "../nu/AutoWide.h"
  12. #include "api.h"
  13. enum
  14. {
  15. DISP_BOOKMARK_ADD = 777,
  16. DISP_BOOKMARK_GETXML,
  17. };
  18. #define CHECK_ID(str, id)\
  19. if (CSTR_EQUAL == CompareStringW(lcid, NORM_IGNORECASE, rgszNames[i], -1, L##str, -1))\
  20. { rgdispid[i] = id; continue; }
  21. HRESULT BookmarksCOM::GetIDsOfNames(REFIID riid, OLECHAR FAR* FAR* rgszNames, unsigned int cNames, LCID lcid, DISPID FAR* rgdispid)
  22. {
  23. bool unknowns = false;
  24. for (unsigned int i = 0;i != cNames;i++)
  25. {
  26. CHECK_ID("Add", DISP_BOOKMARK_ADD)
  27. CHECK_ID("GetXML", DISP_BOOKMARK_GETXML)
  28. rgdispid[i] = DISPID_UNKNOWN;
  29. unknowns = true;
  30. }
  31. if (unknowns)
  32. return DISP_E_UNKNOWNNAME;
  33. else
  34. return S_OK;
  35. }
  36. HRESULT BookmarksCOM::GetTypeInfo(unsigned int itinfo, LCID lcid, ITypeInfo FAR* FAR* pptinfo)
  37. {
  38. return E_NOTIMPL;
  39. }
  40. HRESULT BookmarksCOM::GetTypeInfoCount(unsigned int FAR * pctinfo)
  41. {
  42. return E_NOTIMPL;
  43. }
  44. void Bookmark_WriteAsXML(const wchar_t *filename, int max);
  45. HRESULT BookmarksCOM::Invoke(DISPID dispid, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS FAR *pdispparams, VARIANT FAR *pvarResult, EXCEPINFO FAR * pexecinfo, unsigned int FAR *puArgErr)
  46. {
  47. switch (dispid)
  48. {
  49. case DISP_BOOKMARK_ADD:
  50. switch (pdispparams->cArgs)
  51. {
  52. case 1:
  53. {
  54. Bookmark_additem(pdispparams->rgvarg[0].bstrVal,
  55. pdispparams->rgvarg[0].bstrVal);
  56. return S_OK;
  57. }
  58. case 2:
  59. {
  60. Bookmark_additem(pdispparams->rgvarg[1].bstrVal,
  61. pdispparams->rgvarg[0].bstrVal);
  62. return S_OK;
  63. }
  64. }
  65. break;
  66. case DISP_BOOKMARK_GETXML:
  67. {
  68. int max=0;
  69. if (pdispparams->cArgs == 1)
  70. {
  71. max = _wtoi(pdispparams->rgvarg[0].bstrVal);
  72. }
  73. wchar_t tempPath[MAX_PATH] = {0};
  74. GetTempPathW(MAX_PATH, tempPath);
  75. wchar_t tempFile[MAX_PATH] = {0};
  76. GetTempFileNameW(tempPath, L"bmx.b4s", 0, tempFile);
  77. Bookmark_WriteAsXML(tempFile, max);
  78. HANDLE plFile = CreateFileW(tempFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0);
  79. size_t flen = SetFilePointer(plFile, 0, NULL, FILE_END);
  80. SetFilePointer(plFile, 0, NULL, FILE_BEGIN);
  81. SAFEARRAY *bufferArray=SafeArrayCreateVector(VT_UI1, 0, (ULONG)flen);
  82. void *data = 0;
  83. SafeArrayAccessData(bufferArray, &data);
  84. DWORD bytesRead = 0;
  85. ReadFile(plFile, data, (DWORD)flen, &bytesRead, 0);
  86. SafeArrayUnaccessData(bufferArray);
  87. CloseHandle(plFile);
  88. VariantInit(pvarResult);
  89. V_VT(pvarResult) = VT_ARRAY|VT_UI1;
  90. V_ARRAY(pvarResult) = bufferArray;
  91. DeleteFileW(tempFile);
  92. }
  93. return S_OK;
  94. }
  95. return DISP_E_MEMBERNOTFOUND;
  96. }
  97. STDMETHODIMP BookmarksCOM::QueryInterface(REFIID riid, PVOID *ppvObject)
  98. {
  99. if (!ppvObject)
  100. return E_POINTER;
  101. else if (IsEqualIID(riid, IID_IDispatch))
  102. *ppvObject = (IDispatch *)this;
  103. else if (IsEqualIID(riid, IID_IUnknown))
  104. *ppvObject = this;
  105. else
  106. {
  107. *ppvObject = NULL;
  108. return E_NOINTERFACE;
  109. }
  110. AddRef();
  111. return S_OK;
  112. }
  113. ULONG BookmarksCOM::AddRef(void)
  114. {
  115. return 0;
  116. }
  117. ULONG BookmarksCOM::Release(void)
  118. {
  119. return 0;
  120. }