Skip to content

Commit

Permalink
Expose default callback functions.
Browse files Browse the repository at this point in the history
This was suggested in #33.
  • Loading branch information
fancycode committed Jan 26, 2016
1 parent 2e193f1 commit 905ad75
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
8 changes: 4 additions & 4 deletions MemoryModule.c
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ BuildImportTable(PMEMORYMODULE module)
return result;
}

static HCUSTOMMODULE _LoadLibrary(LPCSTR filename, void *userdata)
HCUSTOMMODULE MemoryDefaultLoadLibrary(LPCSTR filename, void *userdata)
{
HMODULE result;
UNREFERENCED_PARAMETER(userdata);
Expand All @@ -435,21 +435,21 @@ static HCUSTOMMODULE _LoadLibrary(LPCSTR filename, void *userdata)
return (HCUSTOMMODULE) result;
}

static FARPROC _GetProcAddress(HCUSTOMMODULE module, LPCSTR name, void *userdata)
FARPROC MemoryDefaultGetProcAddress(HCUSTOMMODULE module, LPCSTR name, void *userdata)
{
UNREFERENCED_PARAMETER(userdata);
return (FARPROC) GetProcAddress((HMODULE) module, name);
}

static void _FreeLibrary(HCUSTOMMODULE module, void *userdata)
void MemoryDefaultFreeLibrary(HCUSTOMMODULE module, void *userdata)
{
UNREFERENCED_PARAMETER(userdata);
FreeLibrary((HMODULE) module);
}

HMEMORYMODULE MemoryLoadLibrary(const void *data, size_t size)
{
return MemoryLoadLibraryEx(data, size, _LoadLibrary, _GetProcAddress, _FreeLibrary, NULL);
return MemoryLoadLibraryEx(data, size, MemoryDefaultLoadLibrary, MemoryDefaultGetProcAddress, MemoryDefaultFreeLibrary, NULL);
}

HMEMORYMODULE MemoryLoadLibraryEx(const void *data, size_t size,
Expand Down
24 changes: 24 additions & 0 deletions MemoryModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,30 @@ int MemoryLoadString(HMEMORYMODULE, UINT, LPTSTR, int);
*/
int MemoryLoadStringEx(HMEMORYMODULE, UINT, LPTSTR, int, WORD);

/**
* Default implementation of CustomLoadLibraryFunc that calls LoadLibraryA
* internally to load an additional libary.
*
* This is the default as used by MemoryLoadLibrary.
*/
HCUSTOMMODULE MemoryDefaultLoadLibrary(LPCSTR, void *);

/**
* Default implementation of CustomGetProcAddressFunc that calls GetProcAddress
* internally to get the address of an exported function.
*
* This is the default as used by MemoryLoadLibrary.
*/
FARPROC MemoryDefaultGetProcAddress(HCUSTOMMODULE, LPCSTR, void *);

/**
* Default implementation of CustomFreeLibraryFunc that calls FreeLibrary
* internally to release an additional libary.
*
* This is the default as used by MemoryLoadLibrary.
*/
void MemoryDefaultFreeLibrary(HCUSTOMMODULE, void *);

#ifdef __cplusplus
}
#endif
Expand Down

0 comments on commit 905ad75

Please sign in to comment.