WWCOMUtil.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /******************************************************************************
  19. *
  20. * NAME
  21. * $Archive: /Commando/Code/wwlib/WWCOMUtil.cpp $
  22. *
  23. * DESCRIPTION
  24. * COM utility functions and macros
  25. *
  26. * PROGRAMMER
  27. * Denzil E. Long, Jr.
  28. * $Author: Denzil_l $
  29. *
  30. * VERSION INFO
  31. * $Revision: 2 $
  32. * $Modtime: 8/02/01 3:00p $
  33. *
  34. ******************************************************************************/
  35. #include "WWCOMUtil.h"
  36. /******************************************************************************
  37. *
  38. * NAME
  39. * Dispatch_GetProperty
  40. *
  41. * DESCRIPTION
  42. *
  43. * INPUTS
  44. * Dispatch - Dispatch interface pointer.
  45. * Property - Name of property to get.
  46. * Value - Property value.
  47. *
  48. * RESULT
  49. *
  50. ******************************************************************************/
  51. STDMETHODIMP Dispatch_GetProperty(IDispatch* object, const OLECHAR* propName,
  52. VARIANT* result)
  53. {
  54. result->vt = VT_EMPTY;
  55. result->lVal = 0;
  56. // Get the dispid for the named property
  57. OLECHAR* member = const_cast<OLECHAR*>(propName);
  58. DISPID dispid;
  59. HRESULT hr = object->GetIDsOfNames(IID_NULL, &member, 1,
  60. LOCALE_SYSTEM_DEFAULT, &dispid);
  61. if (SUCCEEDED(hr))
  62. {
  63. // Get the property
  64. DISPPARAMS params = {NULL, NULL, 0, 0};
  65. UINT argErr = 0;
  66. hr = object->Invoke(dispid, IID_NULL, LOCALE_SYSTEM_DEFAULT,
  67. DISPATCH_PROPERTYGET, &params, result, NULL, &argErr);
  68. }
  69. return hr;
  70. }
  71. /******************************************************************************
  72. *
  73. * NAME
  74. * Dispatch_PutProperty
  75. *
  76. * DESCRIPTION
  77. *
  78. * INPUTS
  79. * Dispatch - Dispatch interface pointer.
  80. * Property - Name of property to put.
  81. * Value - Property value.
  82. *
  83. * RESULT
  84. *
  85. ******************************************************************************/
  86. STDMETHODIMP Dispatch_PutProperty(IDispatch* object, const OLECHAR* propName,
  87. VARIANT* propValue)
  88. {
  89. // Get the dispid for the named property
  90. OLECHAR* member = const_cast<OLECHAR*>(propName);
  91. DISPID dispid;
  92. HRESULT hr = object->GetIDsOfNames(IID_NULL, &member, 1,
  93. LOCALE_SYSTEM_DEFAULT, &dispid);
  94. if (SUCCEEDED(hr))
  95. {
  96. // Get the property
  97. DISPPARAMS params = {NULL, NULL, 0, 0};
  98. params.cArgs = 1;
  99. params.rgvarg = propValue;
  100. VARIANT result;
  101. UINT argErr = 0;
  102. hr = object->Invoke(dispid, IID_NULL, LOCALE_SYSTEM_DEFAULT,
  103. DISPATCH_PROPERTYPUT, &params, &result, NULL, &argErr);
  104. }
  105. return hr;
  106. }
  107. /******************************************************************************
  108. *
  109. * NAME
  110. * Dispatch_InvokeMethod
  111. *
  112. * DESCRIPTION
  113. *
  114. * INPUTS
  115. * Dispatch - Dispatch interface pointer.
  116. * Method - Method name
  117. * Params - Parameters
  118. * Result - On return; result of method call
  119. *
  120. * RESULT
  121. *
  122. ******************************************************************************/
  123. STDMETHODIMP Dispatch_InvokeMethod(IDispatch* object, const OLECHAR* methodName,
  124. DISPPARAMS* params, VARIANT* result)
  125. {
  126. // Get the dispid for the named property
  127. OLECHAR* member = const_cast<OLECHAR*>(methodName);
  128. DISPID dispid;
  129. HRESULT hr = object->GetIDsOfNames(IID_NULL, &member, 1,
  130. LOCALE_SYSTEM_DEFAULT, &dispid);
  131. if (SUCCEEDED(hr))
  132. {
  133. UINT argErr = 0;
  134. hr = object->Invoke(dispid, IID_NULL, LOCALE_SYSTEM_DEFAULT,
  135. DISPATCH_METHOD, params, result, NULL, &argErr);
  136. }
  137. return hr;
  138. }
  139. /******************************************************************************
  140. *
  141. * NAME
  142. * RegisterCOMServer
  143. *
  144. * DESCRIPTION
  145. * Register an in-process COM server DLL.
  146. *
  147. * INPUTS
  148. * DLLName - Name of DLL to register.
  149. *
  150. * RESULT
  151. * Success - True if operation successful.
  152. *
  153. ******************************************************************************/
  154. bool RegisterCOMServer(const char* dllName)
  155. {
  156. bool success = false;
  157. HINSTANCE hInst = LoadLibrary(dllName);
  158. if (hInst != NULL)
  159. {
  160. FARPROC regServerProc = GetProcAddress(hInst, "DllRegisterServer");
  161. if (regServerProc != NULL)
  162. {
  163. HRESULT hr = regServerProc();
  164. success = SUCCEEDED(hr);
  165. }
  166. FreeLibrary(hInst);
  167. }
  168. return success;
  169. }
  170. /******************************************************************************
  171. *
  172. * NAME
  173. * UnregisterCOMServer
  174. *
  175. * DESCRIPTION
  176. * Unregister a in-process COM server DLL.
  177. *
  178. * INPUTS
  179. * DLLName - Name of DLL to unregister.
  180. *
  181. * RESULT
  182. * Success - True if operation successful.
  183. *
  184. ******************************************************************************/
  185. bool UnregisterCOMServer(const char* dllName)
  186. {
  187. bool success = false;
  188. HINSTANCE hInst = LoadLibrary(dllName);
  189. if (hInst != NULL)
  190. {
  191. FARPROC unregServerProc = GetProcAddress(hInst, "DllUnregisterServer");
  192. if (unregServerProc != NULL)
  193. {
  194. HRESULT hr = unregServerProc();
  195. success = SUCCEEDED(hr);
  196. }
  197. FreeLibrary(hInst);
  198. }
  199. return success;
  200. }