1
0

dispatchTable.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #ifndef NULLSOFT_ORB_PLUGIN_DISPATCHTABLE_HEADER
  2. #define NULLSOFT_ORB_PLUGIN_DISPATCHTABLE_HEADER
  3. #if defined(_MSC_VER) && (_MSC_VER >= 1020)
  4. #pragma once
  5. #endif
  6. #define DISPTABLE_INCLUDE() public:\
  7. STDMETHOD (GetIDsOfNames)(REFIID riid, OLECHAR FAR* FAR* rgszNames, unsigned int cNames, LCID lcid, DISPID FAR* rgdispid);\
  8. STDMETHOD (GetTypeInfo)(unsigned int itinfo, LCID lcid, ITypeInfo FAR* FAR* pptinfo);\
  9. STDMETHOD (GetTypeInfoCount)(unsigned int FAR * pctinfo);\
  10. STDMETHOD (Invoke)(DISPID dispid, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS FAR *pdispparams, VARIANT FAR *pvarResult, EXCEPINFO FAR * pexecinfo, unsigned int FAR *puArgErr);\
  11. private:\
  12. typedef struct __DISPATCHENTRY DISPATCHENTRY;\
  13. const static DISPATCHENTRY szDispatchTable[];
  14. #define DISPTABLE_BEGIN()\
  15. typedef HRESULT (DISPTABLE_CLASS::*DISPATCHHANDLER)(WORD /*wFlags*/, DISPPARAMS FAR* /*pdispparams*/, VARIANT FAR* /*pvarResult*/, UINT FAR* /*puArgErr*/);\
  16. typedef struct __DISPATCHENTRY {\
  17. UINT id;\
  18. LPCWSTR name;\
  19. DISPATCHHANDLER handler;\
  20. } DISPATCHENTRY;\
  21. const DISPTABLE_CLASS::DISPATCHENTRY DISPTABLE_CLASS::szDispatchTable[] = {
  22. #define DISPTABLE_END\
  23. };\
  24. HRESULT DISPTABLE_CLASS::GetIDsOfNames(REFIID riid, OLECHAR FAR* FAR* rgszNames, unsigned int cNames, LCID lcid, DISPID FAR* rgdispid) {\
  25. UINT unknowns = 0;\
  26. for (unsigned int i = 0; i != cNames; i++) {\
  27. rgdispid[i] = DISPID_UNKNOWN;\
  28. for (INT j =0; j < ARRAYSIZE(szDispatchTable); j++) {\
  29. if (CSTR_EQUAL == CompareString(CSTR_INVARIANT, 0, rgszNames[i], -1, szDispatchTable[j].name, -1)) {\
  30. rgdispid[i] = szDispatchTable[j].id; break; }\
  31. }\
  32. if (DISPID_UNKNOWN == rgdispid[i]) { unknowns++; }\
  33. }\
  34. return (0 != unknowns) ? DISP_E_UNKNOWNNAME : S_OK;\
  35. }\
  36. HRESULT DISPTABLE_CLASS::GetTypeInfo(unsigned int itinfo, LCID lcid, ITypeInfo FAR* FAR* pptinfo) { return E_NOTIMPL; }\
  37. HRESULT DISPTABLE_CLASS::GetTypeInfoCount(unsigned int FAR * pctinfo) { return E_NOTIMPL; }\
  38. HRESULT DISPTABLE_CLASS::Invoke(DISPID dispId, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS FAR *pdispparams, VARIANT FAR *pvarResult, EXCEPINFO FAR * pexecinfo, unsigned int FAR *puArgErr) {\
  39. for (INT i = 0; i < ARRAYSIZE(szDispatchTable); i++) {\
  40. if (dispId == szDispatchTable[i].id) { return (this->*szDispatchTable[i].handler)(wFlags, pdispparams, pvarResult, puArgErr); }\
  41. }\
  42. return DISP_E_MEMBERNOTFOUND;\
  43. }
  44. #define DISPENTRY_ADD(__id, __name, __handler)\
  45. { DISPTABLE_CLASS::__id, __name, &DISPTABLE_CLASS::__handler },
  46. #define DISPHANDLER_REGISTER(__handler)\
  47. HRESULT __handler(WORD wFlags, DISPPARAMS FAR *pdispparams, VARIANT FAR *pvarResult, unsigned int FAR *puArgErr);
  48. #endif //NULLSOFT_ORB_PLUGIN_DISPATCHTABLE_HEADER