1
0

DataStoreCOM.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #include "DataStoreCOM.h"
  2. enum
  3. {
  4. DISP_DATASTORE_STORE,
  5. DISP_DATASTORE_RETRIEVE,
  6. DISP_DATASTORE_GENERATE_GUID,
  7. };
  8. #define CHECK_ID(str, id)\
  9. if (CSTR_EQUAL == CompareStringW(lcid, NORM_IGNORECASE, rgszNames[i], -1, L##str, -1))\
  10. { rgdispid[i] = id; continue; }
  11. HRESULT DataStoreCOM::GetIDsOfNames(REFIID riid, OLECHAR FAR* FAR* rgszNames, unsigned int cNames, LCID lcid, DISPID FAR* rgdispid)
  12. {
  13. bool unknowns = false;
  14. for (unsigned int i = 0;i != cNames;i++)
  15. {
  16. CHECK_ID("Store", DISP_DATASTORE_STORE);
  17. CHECK_ID("Retrieve", DISP_DATASTORE_RETRIEVE);
  18. CHECK_ID("GenerateGUID", DISP_DATASTORE_GENERATE_GUID);
  19. rgdispid[i] = DISPID_UNKNOWN;
  20. unknowns = true;
  21. }
  22. if (unknowns)
  23. return DISP_E_UNKNOWNNAME;
  24. else
  25. return S_OK;
  26. }
  27. HRESULT DataStoreCOM::GetTypeInfo(unsigned int itinfo, LCID lcid, ITypeInfo FAR* FAR* pptinfo)
  28. {
  29. return E_NOTIMPL;
  30. }
  31. HRESULT DataStoreCOM::GetTypeInfoCount(unsigned int FAR * pctinfo)
  32. {
  33. return E_NOTIMPL;
  34. }
  35. HRESULT DataStoreCOM::Invoke(DISPID dispid, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS FAR *pdispparams, VARIANT FAR *pvarResult, EXCEPINFO FAR * pexecinfo, unsigned int FAR *puArgErr)
  36. {
  37. switch (dispid)
  38. {
  39. case DISP_DATASTORE_GENERATE_GUID:
  40. {
  41. GUID guid;
  42. UuidCreate(&guid);
  43. wchar_t *guid_string;
  44. UuidToStringW(&guid, (unsigned short **)&guid_string);
  45. BSTR tag = SysAllocString(guid_string);
  46. RpcStringFreeW((unsigned short **)&guid_string);
  47. VariantInit(pvarResult);
  48. V_VT(pvarResult) = VT_BSTR;
  49. V_BSTR(pvarResult) = tag;
  50. return S_OK;
  51. }
  52. case DISP_DATASTORE_STORE:
  53. if (pdispparams->cArgs == 2)
  54. {
  55. GUID guid;
  56. UuidFromStringW((unsigned short *)pdispparams->rgvarg[1].bstrVal, &guid);
  57. SAFEARRAY *bufferArray=pdispparams->rgvarg[0].parray;
  58. SAFEARRAY *store;
  59. HRESULT hr = SafeArrayCopy(bufferArray, &store);
  60. dataStore[guid]=store;
  61. return hr;
  62. }
  63. else
  64. return DISP_E_BADPARAMCOUNT;
  65. case DISP_DATASTORE_RETRIEVE:
  66. if (pdispparams->cArgs == 1)
  67. {
  68. GUID guid;
  69. UuidFromStringW((unsigned short *)pdispparams->rgvarg[0].bstrVal, &guid);
  70. SAFEARRAY *store = dataStore[guid];
  71. if (store)
  72. {
  73. SAFEARRAY *bufferArray;
  74. SafeArrayCopy(store, &bufferArray);
  75. VariantInit(pvarResult);
  76. V_VT(pvarResult) = VT_ARRAY|VT_UI1;
  77. V_ARRAY(pvarResult) = bufferArray;
  78. return S_OK;
  79. }
  80. else
  81. return E_FAIL;
  82. }
  83. else
  84. return DISP_E_BADPARAMCOUNT;
  85. }
  86. return DISP_E_MEMBERNOTFOUND;
  87. }
  88. STDMETHODIMP DataStoreCOM::QueryInterface(REFIID riid, PVOID *ppvObject)
  89. {
  90. if (!ppvObject)
  91. return E_POINTER;
  92. else if (IsEqualIID(riid, IID_IDispatch))
  93. *ppvObject = (IDispatch *)this;
  94. else if (IsEqualIID(riid, IID_IUnknown))
  95. *ppvObject = this;
  96. else
  97. {
  98. *ppvObject = NULL;
  99. return E_NOINTERFACE;
  100. }
  101. AddRef();
  102. return S_OK;
  103. }
  104. ULONG DataStoreCOM::AddRef(void)
  105. {
  106. return 0;
  107. }
  108. ULONG DataStoreCOM::Release(void)
  109. {
  110. return 0;
  111. }