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.

117 lines
3.7 KiB

  1. /******************************************************************************
  2. Copyright (C) Microsoft Corporation 1985-1990. All rights reserved.
  3. Title: task.c - support for task creation and blocking
  4. Version: 1.00
  5. Date: 05-Mar-1990
  6. Author: ROBWI
  7. ------------------------------------------------------------------------------
  8. Change log:
  9. DATE REV DESCRIPTION
  10. ----------- ----- -----------------------------------------------------------
  11. 05-MAR-1990 ROBWI First Version - APIs and structures
  12. 18-APR-1990 ROBWI Ported from Resman to mmsystem
  13. 25-JUN-1990 ROBWI Added mmTaskYield
  14. 07-JUL-1991 CJP Modified to work with new stack switcher code
  15. *****************************************************************************/
  16. #include <windows.h>
  17. #include "mmsystem.h"
  18. #include "mmsysi.h"
  19. #include "mmddk.h"
  20. #include "mmtask\mmtask.h"
  21. UINT FAR PASCAL BWinExec(LPSTR lpModuleName, UINT wCmdShow, LPVOID lpParameters);
  22. /***************************************************************************
  23. *
  24. * @doc DDK MMSYSTEM TASK
  25. *
  26. * @api UINT | mmTaskCreate | This function creates a new task.
  27. *
  28. * @parm LPTASKCALLBACK | lpfn | Points to a program supplied
  29. * function and represents the starting address of the new
  30. * task.
  31. *
  32. * @parm HTASK FAR * | lph | Points to the variable that receives the
  33. * task identifier. This may be NULL in some versions. This
  34. * is not an error it simply means that the system could not
  35. * determine the task handle of the newly created task.
  36. *
  37. * @parm DWORD | dwStack | Specifies the size of the stack to be
  38. * provided to the task.
  39. *
  40. * @parm DWORD | dwInst | DWORD of instance data to pass to the task
  41. * routine.
  42. *
  43. * @rdesc Returns zero if the function is successful. Otherwise it
  44. * returns an error value which may be one of the following:
  45. *
  46. * @flag TASKERR_NOTASKSUPPORT | Task support is not available.
  47. * @flag TASKERR_OUTOFMEMORY | Not enough memory to create task.
  48. *
  49. * @comm When a mmsystem task is created, the system will make a far
  50. * call to the program-supplied function whose address is
  51. * specified by the lpfn parameter. This function may include
  52. * local variables and may call other functions as long as
  53. * the stack has sufficient space.
  54. *
  55. * The task terminates when it returns.
  56. *
  57. * @xref mmTaskSignal mmTaskBlock
  58. *
  59. ***************************************************************************/
  60. UINT WINAPI mmTaskCreate(LPTASKCALLBACK lpfn, HTASK FAR * lph, DWORD dwInst)
  61. {
  62. MMTaskStruct TaskStruct;
  63. char szName[20];
  64. UINT wRes;
  65. HTASK hTask;
  66. /*
  67. create another app. so that we can run the stream outside of
  68. the context of the app.
  69. */
  70. if (!LoadString(ghInst, IDS_TASKSTUB, szName, sizeof(szName)))
  71. return TASKERR_NOTASKSUPPORT;
  72. TaskStruct.cb = sizeof(TaskStruct);
  73. TaskStruct.lpfn = lpfn;
  74. TaskStruct.dwInst = dwInst;
  75. TaskStruct.dwStack = 0L;
  76. wRes = BWinExec(szName, SW_SHOWNOACTIVATE, &TaskStruct);
  77. if (wRes > 32)
  78. {
  79. hTask = wRes;
  80. wRes = MMSYSERR_NOERROR;
  81. }
  82. else if (wRes == 0)
  83. {
  84. wRes = TASKERR_OUTOFMEMORY;
  85. hTask = NULL;
  86. }
  87. else
  88. {
  89. wRes = TASKERR_NOTASKSUPPORT;
  90. hTask = NULL;
  91. }
  92. if (lph)
  93. *lph = hTask;
  94. DPRINTF2("mmTaskCreate: hTask = %04X, wErr = %04X\r\n", hTask, wRes);
  95. return wRes;
  96. }