Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

162 lines
3.3 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1993.
  5. //
  6. // File: compob32.cxx
  7. //
  8. // Contents: Stub compobj for Chicago
  9. //
  10. // History: 09-Sep-93 DrewB Created
  11. //
  12. //----------------------------------------------------------------------------
  13. #include "pch.cxx"
  14. #pragma hdrstop
  15. #include <malloc.h>
  16. // Bind GUID definitions in
  17. #include <initguid.h>
  18. #include <coguid.h>
  19. typedef void *LPCOCS;
  20. class CMalloc : public IMalloc
  21. {
  22. public:
  23. // *** IUnknown methods ***
  24. STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID FAR* ppvObj);
  25. STDMETHOD_(ULONG,AddRef) (THIS) ;
  26. STDMETHOD_(ULONG,Release) (THIS);
  27. // *** IMalloc methods ***
  28. STDMETHOD_(void FAR*, Alloc) (THIS_ ULONG cb);
  29. STDMETHOD_(void FAR*, Realloc) (THIS_ void FAR* pv, ULONG cb);
  30. STDMETHOD_(void, Free) (THIS_ void FAR* pv);
  31. STDMETHOD_(ULONG, GetSize) (THIS_ void FAR* pv);
  32. STDMETHOD_(int, DidAlloc) (THIS_ void FAR* pv);
  33. STDMETHOD_(void, HeapMinimize) (THIS);
  34. };
  35. STDMETHODIMP CMalloc::QueryInterface(REFIID riid, void **ppv)
  36. {
  37. if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_IMalloc))
  38. {
  39. *ppv = (IMalloc *)this;
  40. CMalloc::AddRef();
  41. return NOERROR;
  42. }
  43. *ppv = NULL;
  44. return ResultFromScode(E_NOINTERFACE);
  45. }
  46. STDMETHODIMP_(ULONG) CMalloc::AddRef(void)
  47. {
  48. return 1;
  49. }
  50. STDMETHODIMP_(ULONG) CMalloc::Release(void)
  51. {
  52. return 0;
  53. }
  54. STDMETHODIMP_(void FAR*) CMalloc::Alloc(THIS_ ULONG cb)
  55. {
  56. return malloc(cb);
  57. }
  58. STDMETHODIMP_(void FAR*) CMalloc::Realloc(THIS_ void FAR* pv, ULONG cb)
  59. {
  60. return realloc(pv, cb);
  61. }
  62. STDMETHODIMP_(void) CMalloc::Free(THIS_ void FAR* pv)
  63. {
  64. free(pv);
  65. }
  66. STDMETHODIMP_(ULONG) CMalloc::GetSize(THIS_ void FAR* pv)
  67. {
  68. return _msize(pv);
  69. }
  70. STDMETHODIMP_(int) CMalloc::DidAlloc(THIS_ void FAR* pv)
  71. {
  72. return TRUE;
  73. }
  74. STDMETHODIMP_(void) CMalloc::HeapMinimize(THIS)
  75. {
  76. }
  77. static CMalloc _cm;
  78. STDAPI CoInitialize(IMalloc *pm)
  79. {
  80. return NOERROR;
  81. }
  82. STDAPI_(void) CoUninitialize(void)
  83. {
  84. }
  85. STDAPI CoGetMalloc(DWORD dwMemContext, LPMALLOC FAR* ppMalloc)
  86. {
  87. *ppMalloc = (IMalloc *)&_cm;
  88. return NOERROR;
  89. }
  90. STDAPI_(BOOL) IsValidPtrIn( const void FAR* pv, UINT cb )
  91. {
  92. return pv == NULL || !IsBadReadPtr(pv, cb);
  93. }
  94. STDAPI_(BOOL) IsValidPtrOut( void FAR* pv, UINT cb )
  95. {
  96. return !IsBadWritePtr(pv, cb);
  97. }
  98. STDAPI_(BOOL) IsValidInterface( void FAR* pv )
  99. {
  100. return !IsBadReadPtr(pv, sizeof(void *)) &&
  101. !IsBadReadPtr(*(void **)pv, sizeof(void *)) &&
  102. !IsBadCodePtr(**(FARPROC **)pv);
  103. }
  104. STDAPI_(BOOL) IsValidIid( REFIID riid )
  105. {
  106. return !IsBadReadPtr(&riid, sizeof(IID));
  107. }
  108. STDAPI_(BOOL) IsEqualGUID(REFGUID rguid1, REFGUID rguid2)
  109. {
  110. return memcmp(&rguid1, &rguid2, sizeof(GUID)) == 0;
  111. }
  112. STDAPI_(void *) SharedMemAlloc(ULONG cNeeded, DWORD dwReserved)
  113. {
  114. return malloc(cNeeded);
  115. }
  116. STDAPI_(void) SharedMemFree(void *pmem, DWORD dwReserved)
  117. {
  118. free(pmem);
  119. }
  120. STDAPI_(DWORD) CoGetCurrentProcess(void)
  121. {
  122. return 1;
  123. }
  124. STDAPI CoMarshalInterface(LPSTREAM pStm, REFIID riid, LPUNKNOWN pUnk,
  125. DWORD dwDestContext, LPVOID pvDestContext,
  126. DWORD mshlflags)
  127. {
  128. return ResultFromScode(E_UNEXPECTED);
  129. }
  130. STDAPI CoUnmarshalInterface(LPSTREAM pStm, REFIID riid, LPVOID FAR* ppv)
  131. {
  132. return ResultFromScode(E_UNEXPECTED);
  133. }