Leaked source code of windows server 2003
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.

73 lines
1.8 KiB

  1. // srvcutil.cpp
  2. #include "precomp.h"
  3. /* B S T R _ T O _ L P T S T R */
  4. /*-------------------------------------------------------------------------
  5. %%Function: BSTR_to_LPTSTR
  6. -------------------------------------------------------------------------*/
  7. HRESULT BSTR_to_LPTSTR(LPTSTR *ppsz, BSTR bstr)
  8. {
  9. #ifndef UNICODE
  10. // compute the length of the required BSTR
  11. int cch = WideCharToMultiByte(CP_ACP, 0, (LPWSTR)bstr, -1, NULL, 0, NULL, NULL);
  12. if (cch <= 0)
  13. {
  14. ERROR_OUT(("WideCharToMultiByte failed"));
  15. return E_FAIL;
  16. }
  17. // cch is the number of BYTES required, including the null terminator
  18. *ppsz = (LPTSTR) new char[cch];
  19. if (*ppsz == NULL)
  20. {
  21. ERROR_OUT(("WideCharToMultiByte out of memory"));
  22. return E_OUTOFMEMORY;
  23. }
  24. WideCharToMultiByte(CP_ACP, 0, (LPWSTR)bstr, -1, *ppsz, cch, NULL, NULL);
  25. return S_OK;
  26. #else
  27. return E_NOTIMPL;
  28. #endif // UNICODE
  29. }
  30. /////////////////////////////////////////////////////////////////////////////
  31. // Connection Point Helpers
  32. HRESULT NmAdvise(IUnknown* pUnkCP, IUnknown* pUnk, const IID& iid, LPDWORD pdw)
  33. {
  34. IConnectionPointContainer *pCPC;
  35. IConnectionPoint *pCP;
  36. HRESULT hRes = pUnkCP->QueryInterface(IID_IConnectionPointContainer, (void**)&pCPC);
  37. if (SUCCEEDED(hRes))
  38. {
  39. hRes = pCPC->FindConnectionPoint(iid, &pCP);
  40. pCPC->Release();
  41. }
  42. if (SUCCEEDED(hRes))
  43. {
  44. hRes = pCP->Advise(pUnk, pdw);
  45. pCP->Release();
  46. }
  47. return hRes;
  48. }
  49. HRESULT NmUnadvise(IUnknown* pUnkCP, const IID& iid, DWORD dw)
  50. {
  51. IConnectionPointContainer *pCPC;
  52. IConnectionPoint *pCP;
  53. HRESULT hRes = pUnkCP->QueryInterface(IID_IConnectionPointContainer, (void**)&pCPC);
  54. if (SUCCEEDED(hRes))
  55. {
  56. hRes = pCPC->FindConnectionPoint(iid, &pCP);
  57. pCPC->Release();
  58. }
  59. if (SUCCEEDED(hRes))
  60. {
  61. hRes = pCP->Unadvise(dw);
  62. pCP->Release();
  63. }
  64. return hRes;
  65. }