diff --git a/doc/WinFsp-Tutorial.asciidoc b/doc/WinFsp-Tutorial.asciidoc
index b6f4b791..48f3bc68 100644
--- a/doc/WinFsp-Tutorial.asciidoc
+++ b/doc/WinFsp-Tutorial.asciidoc
@@ -71,60 +71,12 @@ First add the WinFsp DLL as a delay loaded DLL. Open the project properties and
- Linker > Input > Delay Loaded Dll's: `winfsp-$(PlatformTarget).dll`
-Then add the function `WinFspLoad` to passthrough.c. This function consults the registry to find the WinFsp installation directory, loads the WinFsp DLL and then makes all delay loaded imports available.
-
-.`*WinFspLoad*`
-[source,c]
-----
-static NTSTATUS WinFspLoad(VOID)
-{
-#if defined(_WIN64)
-#define FSP_DLLNAME "winfsp-x64.dll"
-#else
-#define FSP_DLLNAME "winfsp-x86.dll"
-#endif
-#define FSP_DLLPATH "bin\\" FSP_DLLNAME
-
- WCHAR PathBuf[MAX_PATH];
- DWORD Size;
- HKEY RegKey;
- LONG Result;
- HMODULE Module;
-
- Module = LoadLibraryW(L"" FSP_DLLNAME);
- if (0 == Module)
- {
- Result = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"Software\\WinFsp",
- 0, KEY_READ | KEY_WOW64_32KEY, &RegKey);
- if (ERROR_SUCCESS == Result)
- {
- Size = sizeof PathBuf - sizeof L"" FSP_DLLPATH + sizeof(WCHAR);
- Result = RegGetValueW(RegKey, 0, L"InstallDir",
- RRF_RT_REG_SZ, 0, PathBuf, &Size);
- RegCloseKey(RegKey);
- }
- if (ERROR_SUCCESS != Result)
- return STATUS_OBJECT_NAME_NOT_FOUND;
-
- RtlCopyMemory(PathBuf + (Size / sizeof(WCHAR) - 1), L"" FSP_DLLPATH, sizeof L"" FSP_DLLPATH);
- Module = LoadLibraryW(PathBuf);
- if (0 == Module)
- return STATUS_DLL_NOT_FOUND;
- }
-
- return STATUS_SUCCESS;
-
-#undef FSP_DLLNAME
-#undef FSP_DLLPATH
-}
-----
-
-Also add the following lines in the beginning of `wmain`:
+Then add the following lines in the beginning of `wmain`:
.`*wmain excerpt*`
[source,c]
----
- if (!NT_SUCCESS(WinFspLoad()))
+ if (!NT_SUCCESS(FspLoad()))
return ERROR_DELAY_LOAD_FAILED;
----
diff --git a/inc/winfsp/winfsp.h b/inc/winfsp/winfsp.h
index ea7f3b42..f0c5c934 100644
--- a/inc/winfsp/winfsp.h
+++ b/inc/winfsp/winfsp.h
@@ -1626,6 +1626,52 @@ FSP_API NTSTATUS FspCallNamedPipeSecurely(PWSTR PipeName,
PULONG PBytesTransferred, ULONG Timeout,
PSID Sid);
+/*
+ * Delay load
+ */
+static inline
+NTSTATUS FspLoad(VOID)
+{
+#if defined(_WIN64)
+#define FSP_DLLNAME "winfsp-x64.dll"
+#else
+#define FSP_DLLNAME "winfsp-x86.dll"
+#endif
+#define FSP_DLLPATH "bin\\" FSP_DLLNAME
+
+ WCHAR PathBuf[MAX_PATH];
+ DWORD Size;
+ HKEY RegKey;
+ LONG Result;
+ HMODULE Module;
+
+ Module = LoadLibraryW(L"" FSP_DLLNAME);
+ if (0 == Module)
+ {
+ Result = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"Software\\WinFsp",
+ 0, KEY_READ | KEY_WOW64_32KEY, &RegKey);
+ if (ERROR_SUCCESS == Result)
+ {
+ Size = sizeof PathBuf - sizeof L"" FSP_DLLPATH + sizeof(WCHAR);
+ Result = RegGetValueW(RegKey, 0, L"InstallDir",
+ RRF_RT_REG_SZ, 0, PathBuf, &Size);
+ RegCloseKey(RegKey);
+ }
+ if (ERROR_SUCCESS != Result)
+ return STATUS_OBJECT_NAME_NOT_FOUND;
+
+ RtlCopyMemory(PathBuf + (Size / sizeof(WCHAR) - 1), L"" FSP_DLLPATH, sizeof L"" FSP_DLLPATH);
+ Module = LoadLibraryW(PathBuf);
+ if (0 == Module)
+ return STATUS_DLL_NOT_FOUND;
+ }
+
+ return STATUS_SUCCESS;
+
+#undef FSP_DLLNAME
+#undef FSP_DLLPATH
+}
+
#ifdef __cplusplus
}
#endif
diff --git a/tst/passthrough-fuse/passthrough-fuse.vcxproj b/tst/passthrough-fuse/passthrough-fuse.vcxproj
index a11bfae4..1d0c6a5e 100644
--- a/tst/passthrough-fuse/passthrough-fuse.vcxproj
+++ b/tst/passthrough-fuse/passthrough-fuse.vcxproj
@@ -101,7 +101,7 @@
Disabled
WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
true
- $(MSBuildProgramFiles32)\WinFsp\inc\fuse
+ $(MSBuildProgramFiles32)\WinFsp\inc\fuse;$(MSBuildProgramFiles32)\WinFsp\inc
MultiThreaded
4996
@@ -120,7 +120,7 @@
Disabled
_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
true
- $(MSBuildProgramFiles32)\WinFsp\inc\fuse
+ $(MSBuildProgramFiles32)\WinFsp\inc\fuse;$(MSBuildProgramFiles32)\WinFsp\inc
MultiThreaded
4996
@@ -141,7 +141,7 @@
true
WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
true
- $(MSBuildProgramFiles32)\WinFsp\inc\fuse
+ $(MSBuildProgramFiles32)\WinFsp\inc\fuse;$(MSBuildProgramFiles32)\WinFsp\inc
MultiThreaded
4996
@@ -164,7 +164,7 @@
true
NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
true
- $(MSBuildProgramFiles32)\WinFsp\inc\fuse
+ $(MSBuildProgramFiles32)\WinFsp\inc\fuse;$(MSBuildProgramFiles32)\WinFsp\inc
MultiThreaded
4996
diff --git a/tst/passthrough-fuse/winposix.c b/tst/passthrough-fuse/winposix.c
index 92bacefb..bcf708ef 100644
--- a/tst/passthrough-fuse/winposix.c
+++ b/tst/passthrough-fuse/winposix.c
@@ -24,7 +24,7 @@
* file names and security.
*/
-#include
+#include
#include
#include
#include "winposix.h"
@@ -523,44 +523,7 @@ static int maperror(int winerrno)
}
}
-static NTSTATUS WinFspLoad(VOID)
+long WinFspLoad(void)
{
-#if defined(_WIN64)
-#define FSP_DLLNAME "winfsp-x64.dll"
-#else
-#define FSP_DLLNAME "winfsp-x86.dll"
-#endif
-#define FSP_DLLPATH "bin\\" FSP_DLLNAME
-
- WCHAR PathBuf[MAX_PATH];
- DWORD Size;
- HKEY RegKey;
- LONG Result;
- HMODULE Module;
-
- Module = LoadLibraryW(L"" FSP_DLLNAME);
- if (0 == Module)
- {
- Result = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"Software\\WinFsp",
- 0, KEY_READ | KEY_WOW64_32KEY, &RegKey);
- if (ERROR_SUCCESS == Result)
- {
- Size = sizeof PathBuf - sizeof L"" FSP_DLLPATH + sizeof(WCHAR);
- Result = RegGetValueW(RegKey, 0, L"InstallDir",
- RRF_RT_REG_SZ, 0, PathBuf, &Size);
- RegCloseKey(RegKey);
- }
- if (ERROR_SUCCESS != Result)
- return STATUS_OBJECT_NAME_NOT_FOUND;
-
- RtlCopyMemory(PathBuf + (Size / sizeof(WCHAR) - 1), L"" FSP_DLLPATH, sizeof L"" FSP_DLLPATH);
- Module = LoadLibraryW(PathBuf);
- if (0 == Module)
- return STATUS_DLL_NOT_FOUND;
- }
-
- return STATUS_SUCCESS;
-
-#undef FSP_DLLNAME
-#undef FSP_DLLPATH
+ return FspLoad();
}
diff --git a/tst/passthrough/passthrough.c b/tst/passthrough/passthrough.c
index bb59d834..72a29bc7 100644
--- a/tst/passthrough/passthrough.c
+++ b/tst/passthrough/passthrough.c
@@ -916,51 +916,9 @@ static NTSTATUS SvcStop(FSP_SERVICE *Service)
return STATUS_SUCCESS;
}
-static NTSTATUS WinFspLoad(VOID)
-{
-#if defined(_WIN64)
-#define FSP_DLLNAME "winfsp-x64.dll"
-#else
-#define FSP_DLLNAME "winfsp-x86.dll"
-#endif
-#define FSP_DLLPATH "bin\\" FSP_DLLNAME
-
- WCHAR PathBuf[MAX_PATH];
- DWORD Size;
- HKEY RegKey;
- LONG Result;
- HMODULE Module;
-
- Module = LoadLibraryW(L"" FSP_DLLNAME);
- if (0 == Module)
- {
- Result = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"Software\\WinFsp",
- 0, KEY_READ | KEY_WOW64_32KEY, &RegKey);
- if (ERROR_SUCCESS == Result)
- {
- Size = sizeof PathBuf - sizeof L"" FSP_DLLPATH + sizeof(WCHAR);
- Result = RegGetValueW(RegKey, 0, L"InstallDir",
- RRF_RT_REG_SZ, 0, PathBuf, &Size);
- RegCloseKey(RegKey);
- }
- if (ERROR_SUCCESS != Result)
- return STATUS_OBJECT_NAME_NOT_FOUND;
-
- RtlCopyMemory(PathBuf + (Size / sizeof(WCHAR) - 1), L"" FSP_DLLPATH, sizeof L"" FSP_DLLPATH);
- Module = LoadLibraryW(PathBuf);
- if (0 == Module)
- return STATUS_DLL_NOT_FOUND;
- }
-
- return STATUS_SUCCESS;
-
-#undef FSP_DLLNAME
-#undef FSP_DLLPATH
-}
-
int wmain(int argc, wchar_t **argv)
{
- if (!NT_SUCCESS(WinFspLoad()))
+ if (!NT_SUCCESS(FspLoad()))
return ERROR_DELAY_LOAD_FAILED;
return FspServiceRun(L"" PROGNAME, SvcStart, SvcStop, 0);