Source code of Windows XP (NT5)
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.

84 lines
1.9 KiB

  1. /****************************************************************************
  2. *
  3. * ntcomm.c
  4. *
  5. * Copyright (c) 1993 Microsoft Corporation. All Rights Reserved
  6. *
  7. * MCI Device Driver for the Pioneer 4200 Videodisc Player
  8. *
  9. * Comms compatibility routines for Windows NT
  10. *
  11. ***************************************************************************/
  12. #include <windows.h>
  13. INT OpenComm(LPCTSTR lpstr, UINT wqin, UINT wqout)
  14. {
  15. HANDLE hFile;
  16. COMMTIMEOUTS Timeouts;
  17. hFile = CreateFile(lpstr,
  18. GENERIC_READ | GENERIC_WRITE,
  19. 0,
  20. NULL,
  21. OPEN_EXISTING,
  22. FILE_FLAG_WRITE_THROUGH,
  23. 0);
  24. if (hFile == INVALID_HANDLE_VALUE) {
  25. return 0;
  26. }
  27. /*
  28. * Set the timeouts to be like win3.1 (as defined in the SDK)
  29. */
  30. Timeouts.ReadIntervalTimeout = INFINITE;
  31. Timeouts.ReadTotalTimeoutMultiplier = 0;
  32. Timeouts.ReadTotalTimeoutConstant = 0;
  33. Timeouts.WriteTotalTimeoutMultiplier = INFINITE;
  34. Timeouts.WriteTotalTimeoutConstant = INFINITE;
  35. if (!SetCommTimeouts(hFile, &Timeouts)) {
  36. CloseHandle(hFile);
  37. return 0;
  38. } else {
  39. return (INT)hFile;
  40. }
  41. }
  42. INT GetCommError(int hDevice, LPCOMSTAT lpComStat)
  43. {
  44. DWORD dwErrors;
  45. if (ClearCommError((HANDLE)hDevice, &dwErrors, lpComStat)) {
  46. return dwErrors;
  47. } else {
  48. /*
  49. * Concoct something nasty
  50. */
  51. return CE_IOE;
  52. }
  53. }
  54. INT ReadComm(HFILE nCid, LPSTR lpBuf, INT nSize)
  55. {
  56. DWORD cbRead;
  57. if (!ReadFile((HANDLE)nCid, lpBuf, nSize, &cbRead, 0))
  58. return(-(INT)cbRead);
  59. return((INT)cbRead);
  60. }
  61. INT WriteComm(HFILE nCid, LPSTR lpBuf, INT nSize)
  62. {
  63. DWORD cbWritten;
  64. if (!WriteFile((HANDLE)nCid, lpBuf, nSize, &cbWritten, 0))
  65. return(-(INT)cbWritten);
  66. return((INT)cbWritten);
  67. }