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.

153 lines
2.6 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. return pResult;
  52. Error:
  53. FreeLibrary(
  54. pResult->m_hModule);
  55. NoLibrary:
  56. free(
  57. pResult);
  58. NoStructure:
  59. return FALSE;
  60. }
  61. void lhclFreeLibrary(PLIBRARY_DESCRIPTOR pLibrary)
  62. {
  63. if (pLibrary!=NULL)
  64. {
  65. if (pLibrary->m_hModule!=NULL)
  66. {
  67. FreeLibrary(
  68. pLibrary->m_hModule);
  69. }
  70. free(
  71. pLibrary);
  72. }
  73. }
  74. PLHCOBJECT_DESCRIPTOR lhclOpen(
  75. PLIBRARY_DESCRIPTOR pLibrary,
  76. PCWSTR pcszPortSpec)
  77. {
  78. return pLibrary->m_fpOpen(
  79. pcszPortSpec);
  80. }
  81. BOOL lhclRead(
  82. PLIBRARY_DESCRIPTOR pLibrary,
  83. PLHCOBJECT_DESCRIPTOR pObject,
  84. PVOID pBuffer,
  85. DWORD dwBufferSize,
  86. PDWORD pdwBytesRead)
  87. {
  88. return pLibrary->m_fpRead(
  89. pObject,
  90. pBuffer,
  91. dwBufferSize,
  92. pdwBytesRead);
  93. }
  94. BOOL lhclWrite(
  95. PLIBRARY_DESCRIPTOR pLibrary,
  96. PLHCOBJECT_DESCRIPTOR pObject,
  97. PVOID pBuffer,
  98. DWORD dwBufferSize)
  99. {
  100. return pLibrary->m_fpWrite(
  101. pObject,
  102. pBuffer,
  103. dwBufferSize);
  104. }
  105. BOOL lhclClose(
  106. PLIBRARY_DESCRIPTOR pLibrary,
  107. PLHCOBJECT_DESCRIPTOR pObject)
  108. {
  109. return pLibrary->m_fpClose(
  110. pObject);
  111. }
  112. DWORD lhclGetLibraryName(
  113. PLIBRARY_DESCRIPTOR pLibrary,
  114. PWSTR pszBuffer,
  115. DWORD dwBufferSize)
  116. {
  117. return pLibrary->m_fpGetLibraryName(
  118. pszBuffer,
  119. dwBufferSize);
  120. }