PageRenderTime 51ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/ThirdPartyLibs/MemoryModule/MemoryModule.h

https://github.com/Esenthel/EsenthelEngine
C Header | 168 lines | 40 code | 25 blank | 103 comment | 0 complexity | 9dd5d0a3a35dacfd552065516499a00c MD5 | raw file
Possible License(s): Apache-2.0, LGPL-3.0, LGPL-2.0, BSD-3-Clause, CC0-1.0, 0BSD, MIT, GPL-2.0
  1. /*
  2. * Memory DLL loading code
  3. * Version 0.0.4
  4. *
  5. * Copyright (c) 2004-2015 by Joachim Bauch / mail@joachim-bauch.de
  6. * http://www.joachim-bauch.de
  7. *
  8. * The contents of this file are subject to the Mozilla Public License Version
  9. * 2.0 (the "License"); you may not use this file except in compliance with
  10. * the License. You may obtain a copy of the License at
  11. * http://www.mozilla.org/MPL/
  12. *
  13. * Software distributed under the License is distributed on an "AS IS" basis,
  14. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  15. * for the specific language governing rights and limitations under the
  16. * License.
  17. *
  18. * The Original Code is MemoryModule.h
  19. *
  20. * The Initial Developer of the Original Code is Joachim Bauch.
  21. *
  22. * Portions created by Joachim Bauch are Copyright (C) 2004-2015
  23. * Joachim Bauch. All Rights Reserved.
  24. *
  25. */
  26. #ifndef __MEMORY_MODULE_HEADER
  27. #define __MEMORY_MODULE_HEADER
  28. #include <windows.h>
  29. typedef void *HMEMORYMODULE;
  30. typedef void *HMEMORYRSRC;
  31. typedef void *HCUSTOMMODULE;
  32. #ifdef __cplusplus
  33. extern "C" {
  34. #endif
  35. typedef LPVOID (*CustomAllocFunc)(LPVOID, SIZE_T, DWORD, DWORD, void*);
  36. typedef BOOL (*CustomFreeFunc)(LPVOID, SIZE_T, DWORD, void*);
  37. typedef HCUSTOMMODULE (*CustomLoadLibraryFunc)(LPCSTR, void *);
  38. typedef FARPROC (*CustomGetProcAddressFunc)(HCUSTOMMODULE, LPCSTR, void *);
  39. typedef void (*CustomFreeLibraryFunc)(HCUSTOMMODULE, void *);
  40. /**
  41. * Load EXE/DLL from memory location with the given size.
  42. *
  43. * All dependencies are resolved using default LoadLibrary/GetProcAddress
  44. * calls through the Windows API.
  45. */
  46. HMEMORYMODULE MemoryLoadLibrary(const void *, size_t);
  47. /**
  48. * Load EXE/DLL from memory location with the given size using custom dependency
  49. * resolvers.
  50. *
  51. * Dependencies will be resolved using passed callback methods.
  52. */
  53. HMEMORYMODULE MemoryLoadLibraryEx(const void *, size_t,
  54. CustomAllocFunc,
  55. CustomFreeFunc,
  56. CustomLoadLibraryFunc,
  57. CustomGetProcAddressFunc,
  58. CustomFreeLibraryFunc,
  59. void *);
  60. /**
  61. * Get address of exported method. Supports loading both by name and by
  62. * ordinal value.
  63. */
  64. FARPROC MemoryGetProcAddress(HMEMORYMODULE, LPCSTR);
  65. /**
  66. * Free previously loaded EXE/DLL.
  67. */
  68. void MemoryFreeLibrary(HMEMORYMODULE);
  69. /**
  70. * Execute entry point (EXE only). The entry point can only be executed
  71. * if the EXE has been loaded to the correct base address or it could
  72. * be relocated (i.e. relocation information have not been stripped by
  73. * the linker).
  74. *
  75. * Important: calling this function will not return, i.e. once the loaded
  76. * EXE finished running, the process will terminate.
  77. *
  78. * Returns a negative value if the entry point could not be executed.
  79. */
  80. int MemoryCallEntryPoint(HMEMORYMODULE);
  81. /**
  82. * Find the location of a resource with the specified type and name.
  83. */
  84. HMEMORYRSRC MemoryFindResource(HMEMORYMODULE, LPCTSTR, LPCTSTR);
  85. /**
  86. * Find the location of a resource with the specified type, name and language.
  87. */
  88. HMEMORYRSRC MemoryFindResourceEx(HMEMORYMODULE, LPCTSTR, LPCTSTR, WORD);
  89. /**
  90. * Get the size of the resource in bytes.
  91. */
  92. DWORD MemorySizeofResource(HMEMORYMODULE, HMEMORYRSRC);
  93. /**
  94. * Get a pointer to the contents of the resource.
  95. */
  96. LPVOID MemoryLoadResource(HMEMORYMODULE, HMEMORYRSRC);
  97. /**
  98. * Load a string resource.
  99. */
  100. int MemoryLoadString(HMEMORYMODULE, UINT, LPTSTR, int);
  101. /**
  102. * Load a string resource with a given language.
  103. */
  104. int MemoryLoadStringEx(HMEMORYMODULE, UINT, LPTSTR, int, WORD);
  105. /**
  106. * Default implementation of CustomAllocFunc that calls VirtualAlloc
  107. * internally to allocate memory for a library
  108. *
  109. * This is the default as used by MemoryLoadLibrary.
  110. */
  111. LPVOID MemoryDefaultAlloc(LPVOID, SIZE_T, DWORD, DWORD, void *);
  112. /**
  113. * Default implementation of CustomFreeFunc that calls VirtualFree
  114. * internally to free the memory used by a library
  115. *
  116. * This is the default as used by MemoryLoadLibrary.
  117. */
  118. BOOL MemoryDefaultFree(LPVOID, SIZE_T, DWORD, void *);
  119. /**
  120. * Default implementation of CustomLoadLibraryFunc that calls LoadLibraryA
  121. * internally to load an additional libary.
  122. *
  123. * This is the default as used by MemoryLoadLibrary.
  124. */
  125. HCUSTOMMODULE MemoryDefaultLoadLibrary(LPCSTR, void *);
  126. /**
  127. * Default implementation of CustomGetProcAddressFunc that calls GetProcAddress
  128. * internally to get the address of an exported function.
  129. *
  130. * This is the default as used by MemoryLoadLibrary.
  131. */
  132. FARPROC MemoryDefaultGetProcAddress(HCUSTOMMODULE, LPCSTR, void *);
  133. /**
  134. * Default implementation of CustomFreeLibraryFunc that calls FreeLibrary
  135. * internally to release an additional libary.
  136. *
  137. * This is the default as used by MemoryLoadLibrary.
  138. */
  139. void MemoryDefaultFreeLibrary(HCUSTOMMODULE, void *);
  140. #ifdef __cplusplus
  141. }
  142. #endif
  143. #endif // __MEMORY_MODULE_HEADER