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.

169 lines
3.0 KiB

  1. #include "std.h"
  2. PLIBRARY_DESCRIPTOR lhclLoadLibrary(PCWSTR pcszPathName)
  3. {
  4. PLIBRARY_DESCRIPTOR pResult = malloc(
  5. sizeof(LIBRARY_DESCRIPTOR));
  6. if (NULL==pResult)
  7. {
  8. goto NoStructure;
  9. }
  10. pResult->m_hModule = LoadLibraryW(
  11. pcszPathName);
  12. if (NULL==pResult->m_hModule)
  13. {
  14. goto NoLibrary;
  15. }
  16. pResult->m_fpOpen = (PLHC_OPENPROC)GetProcAddress(
  17. pResult->m_hModule,
  18. "lhcOpen");
  19. if (NULL==pResult->m_fpOpen)
  20. {
  21. goto Error;
  22. }
  23. pResult->m_fpClose = (PLHC_CLOSEPROC)GetProcAddress(
  24. pResult->m_hModule,
  25. "lhcClose");
  26. if (NULL==pResult->m_fpClose)
  27. {
  28. goto Error;
  29. }
  30. pResult->m_fpRead = (PLHC_READPROC)GetProcAddress(
  31. pResult->m_hModule,
  32. "lhcRead");
  33. if (NULL==pResult->m_fpRead)
  34. {
  35. goto Error;
  36. }
  37. pResult->m_fpWrite = (PLHC_WRITEPROC)GetProcAddress(
  38. pResult->m_hModule,
  39. "lhcWrite");
  40. if (NULL==pResult->m_fpWrite)
  41. {
  42. goto Error;
  43. }
  44. pResult->m_fpGetLibraryName = (PLHC_GETLIBRARYNAMEPROC)GetProcAddress(
  45. pResult->m_hModule,
  46. "lhcGetLibraryName");
  47. if (NULL==pResult->m_fpGetLibraryName)
  48. {
  49. goto Error;
  50. }
  51. pResult->m_fpUsage = (PLHC_GETLIBRARYNAMEPROC)GetProcAddress(
  52. pResult->m_hModule,
  53. "lhcUsage");
  54. if (NULL==pResult->m_fpUsage)
  55. {
  56. goto Error;
  57. }
  58. return pResult;
  59. Error:
  60. FreeLibrary(
  61. pResult->m_hModule);
  62. NoLibrary:
  63. free(
  64. pResult);
  65. NoStructure:
  66. return FALSE;
  67. }
  68. void lhclFreeLibrary(PLIBRARY_DESCRIPTOR pLibrary)
  69. {
  70. if (pLibrary!=NULL)
  71. {
  72. if (pLibrary->m_hModule!=NULL)
  73. {
  74. FreeLibrary(
  75. pLibrary->m_hModule);
  76. }
  77. free(
  78. pLibrary);
  79. }
  80. }
  81. PLHCOBJECT_DESCRIPTOR lhclOpen(
  82. PLIBRARY_DESCRIPTOR pLibrary,
  83. PCWSTR pcszPortSpec)
  84. {
  85. return pLibrary->m_fpOpen(
  86. pcszPortSpec);
  87. }
  88. BOOL lhclRead(
  89. PLIBRARY_DESCRIPTOR pLibrary,
  90. PLHCOBJECT_DESCRIPTOR pObject,
  91. PVOID pBuffer,
  92. DWORD dwBufferSize,
  93. PDWORD pdwBytesRead)
  94. {
  95. return pLibrary->m_fpRead(
  96. pObject,
  97. pBuffer,
  98. dwBufferSize,
  99. pdwBytesRead);
  100. }
  101. BOOL lhclWrite(
  102. PLIBRARY_DESCRIPTOR pLibrary,
  103. PLHCOBJECT_DESCRIPTOR pObject,
  104. PVOID pBuffer,
  105. DWORD dwBufferSize)
  106. {
  107. return pLibrary->m_fpWrite(
  108. pObject,
  109. pBuffer,
  110. dwBufferSize);
  111. }
  112. BOOL lhclClose(
  113. PLIBRARY_DESCRIPTOR pLibrary,
  114. PLHCOBJECT_DESCRIPTOR pObject)
  115. {
  116. return pLibrary->m_fpClose(
  117. pObject);
  118. }
  119. DWORD lhclGetLibraryName(
  120. PLIBRARY_DESCRIPTOR pLibrary,
  121. PWSTR pszBuffer,
  122. DWORD dwBufferSize)
  123. {
  124. return pLibrary->m_fpGetLibraryName(
  125. pszBuffer,
  126. dwBufferSize);
  127. }
  128. void lhclUsage(
  129. PLIBRARY_DESCRIPTOR pLibrary)
  130. {
  131. pLibrary->m_fpUsage();
  132. }