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.

45 lines
1.0 KiB

  1. /*****************************************************************************
  2. *
  3. * ftpwith.cpp - "With" procedures
  4. *
  5. *****************************************************************************/
  6. #include "priv.h"
  7. /*****************************************************************************
  8. *
  9. * With_Hglob
  10. *
  11. * Allocate a moveable HGLOBAL of the requested size, lock it, then call
  12. * the callback. On return, unlock it and get out.
  13. *
  14. * Returns the allocated HGLOBAL, or 0.
  15. *
  16. *****************************************************************************/
  17. HGLOBAL With_Hglob(UINT cb, HGLOBWITHPROC pfn, LPVOID pvRef)
  18. {
  19. HGLOBAL hglob = GlobalAlloc(GHND, cb);
  20. if (hglob)
  21. {
  22. LPVOID pv = GlobalLock(hglob);
  23. if (pv)
  24. {
  25. BOOL fRc = pfn(pv, pvRef);
  26. GlobalUnlock(hglob);
  27. if (!fRc)
  28. {
  29. GlobalFree(hglob);
  30. hglob = 0;
  31. }
  32. }
  33. else
  34. {
  35. GlobalFree(hglob);
  36. hglob = 0;
  37. }
  38. }
  39. return hglob;
  40. }