Changes since v1:
- repeated the example from the commit message in the .h file
- mentioned that the function is not thread-safe.
- added Jonathan's Reviewed-by: footer
Johannes Schindelin (1):
Win32: simplify loading of DLL functions
compat/win32/lazyload.h | 57 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 57 insertions(+)
create mode 100644 compat/win32/lazyload.h
base-commit: 28996cec80690d2322359d3650a57e8de6e01eb6
Published-As: https://github.com/dscho/git/releases/tag/lazyload-v2
Fetch-It-Via: git fetch https://github.com/dscho/git lazyload-v2
Interdiff vs v1:
diff --git a/compat/win32/lazyload.h b/compat/win32/lazyload.h
index 91c10dad2fb..9e631c8593f 100644
--- a/compat/win32/lazyload.h
+++ b/compat/win32/lazyload.h
@@ -1,7 +1,19 @@
#ifndef LAZYLOAD_H
#define LAZYLOAD_H
-/* simplify loading of DLL functions */
+/*
+ * A pair of macros to simplify loading of DLL functions. Example:
+ *
+ * DECLARE_PROC_ADDR(kernel32.dll, BOOL, CreateHardLinkW,
+ * LPCWSTR, LPCWSTR, LPSECURITY_ATTRIBUTES);
+ *
+ * if (!INIT_PROC_ADDR(CreateHardLinkW))
+ * return error("Could not find CreateHardLinkW() function";
+ *
+ * if (!CreateHardLinkW(source, target, NULL))
+ * return error("could not create hardlink from %S to %S",
+ * source, target);
+ */
struct proc_addr {
const char *const dll;
@@ -20,6 +32,7 @@ struct proc_addr {
* Loads a function from a DLL (once-only).
* Returns non-NULL function pointer on success.
* Returns NULL + errno == ENOSYS on failure.
+ * This function is not thread-safe.
*/
#define INIT_PROC_ADDR(function) \
(function = get_proc_addr(&proc_addr_##function))