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.

104 lines
2.0 KiB

  1. /************************************************************************
  2. regtool.cpp
  3. -- general registry configuration function
  4. History: Date Author Comment
  5. 8/14/00 Casper Wrote it.
  6. *************************************************************************/
  7. #include "stdafx.h"
  8. #include <tchar.h>
  9. #include <string.h>
  10. #include <stdio.h>
  11. #include <msports.h>
  12. #include "moxacfg.h"
  13. #include "mxdebug.h"
  14. ULONG MxGetVenDevId(LPTSTR data)
  15. {
  16. ULONG n1=0, n2 = 0;
  17. TCHAR tmp[5];
  18. if (_tcsncmp(data, TEXT("PCI\\"), 4) != 0)
  19. return (n1);
  20. data += 4;
  21. while (*data) {
  22. if (_tcsncmp(data, TEXT("VEN_") ,4) == 0) {
  23. data += 4;
  24. lstrcpyn(tmp, data, 5);
  25. if(_stscanf(tmp, TEXT("%4X"), &n1)!=1){
  26. n1 = 0;
  27. }
  28. n1 <<= 16;
  29. data += 5;
  30. if (_tcsncmp(data, TEXT("DEV_"),4) == 0) {
  31. data += 4;
  32. lstrcpyn(tmp, data, 5);
  33. if(_stscanf(tmp, TEXT("%4X"), &n2)!=1){
  34. n2 = 0;
  35. }
  36. n1 += n2;
  37. }
  38. return (n1);
  39. }
  40. data++;
  41. }
  42. return (n1);
  43. }
  44. int GetFreePort(void)
  45. {
  46. DWORD maxport;
  47. LPBYTE combuf;
  48. HCOMDB hcomdb;
  49. int port, i;
  50. port = 0;
  51. if(ComDBOpen(&hcomdb) != ERROR_SUCCESS){
  52. Mx_Debug_Out(TEXT("ComDBOpen fail\n"));
  53. return port;
  54. }
  55. ComDBGetCurrentPortUsage (hcomdb,
  56. NULL, 0, CDB_REPORT_BYTES, &maxport);
  57. combuf = new BYTE[maxport];
  58. if(combuf)
  59. {
  60. // init buffer
  61. ZeroMemory(combuf, maxport);
  62. ComDBGetCurrentPortUsage (hcomdb,
  63. combuf, maxport, CDB_REPORT_BYTES, &maxport);
  64. if(maxport > MAXPORTS)
  65. maxport = MAXPORTS;
  66. for(i=0; i<(int)maxport; i++){
  67. if(combuf[i]==0){
  68. port = i+1;
  69. break;
  70. }else
  71. continue;
  72. }
  73. delete[] combuf;
  74. }
  75. BOOL bret;
  76. if(port!=0)
  77. ComDBClaimPort (hcomdb, port, TRUE, &bret);
  78. ComDBClose(hcomdb);
  79. return port;
  80. }