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.

78 lines
2.3 KiB

  1. TO ADD A NEW WRAPPER
  2. ====================
  3. Usually, just list it in apilist.txt.
  4. The file is presently sorted, but that does not matter.
  5. If the function is BOOL/LastError, failure is false, you're done.
  6. If the function returns an HRESULT or an NTSTATUS, you're done.
  7. If the function returns a Win32 error, like a registry function, add it to
  8. the registry section in winthrow_err.tpl
  9. If the function returns a PVOID, failure is false, you're done.
  10. The most common case that requires additional work is if the function
  11. returns a HANDLE or an integral type, like int, long, ULONG, DWORD, etc.
  12. For these, if the error value is 0, -1, or 0xFFFFFFFF, just add it to
  13. the "appropriate" section.
  14. UNDONE: Sized buffers. We need another set of wrappers for these.
  15. This directory produces "throwing wrappers" over Win32 functions.
  16. The throwing wrappers come in three flavors:
  17. "same signature-or-throw"
  18. HANDLE CreateFileOrThrow(...)
  19. {
  20. HANDLE h = CreateFileW(...);
  21. if (h == INVALID_HANDLE_VALUE)
  22. Throw...;
  23. return h;
  24. }
  25. "same signature-or-throw-unless-count-dots"
  26. HANDLE CreateFileOrThrow(..., DWORD& LastErrorOut, SIZE_T CountOfOkErrors, DWORD OkErrors...)
  27. {
  28. LastErrorOut = NO_ERROR;
  29. HANDLE h = CreateFileW(...);
  30. if (h == INVALID_HANDLE_VALUE)
  31. {
  32. LastErrorOut = GetLastError();
  33. if (LastErrorOut not in OkErrors)
  34. Throw...;
  35. }
  36. return h;
  37. }
  38. "same signagure-or-throw-unless-count-valist"
  39. HANDLE CreateFileOrThrow(..., DWORD& LastErrorOut, SIZE_T CountOfOkErrors, va_list OkErrors)
  40. {
  41. LastErrorOut = NO_ERROR;
  42. HANDLE h = CreateFileW(...);
  43. if (h == INVALID_HANDLE_VALUE)
  44. {
  45. LastErrorOut = GetLastError();
  46. if (LastErrorOut not in OkErrors)
  47. Throw...;
  48. }
  49. return h;
  50. }
  51. The wrappers are generated via the mysterious genthnk tool.
  52. The files are not as clear as I would like, but adding new wrappers has been made as painless as possible,
  53. given the mysterious genthnk tool..
  54. @NL -- newline
  55. [IFunc] -- iterated function, evaluated for every function
  56. [EFunc] -- exception function, replace IFunc
  57. [Code] --
  58. [Template] --
  59. [Macros] -- arbitrary reusable pieces
  60. @Indent --
  61. Any questions, see JayKrell.
  62. See also
  63. base\tools\genthnk
  64. base\mvdm\MeoWThunks\cgen\template.tpl