mirror of
https://github.com/winfsp/winfsp.git
synced 2025-04-22 16:33:02 -05:00
src: dotnet: check dll version during assembly load
This commit is contained in:
parent
5d8384a508
commit
197ce7c30a
@ -175,6 +175,8 @@ FSP_API NTSTATUS FspVersion(PUINT32 PVersion)
|
|||||||
* Two threads competing to read the version will read
|
* Two threads competing to read the version will read
|
||||||
* the same value from the Version resource.
|
* the same value from the Version resource.
|
||||||
*/
|
*/
|
||||||
|
*PVersion = 0;
|
||||||
|
|
||||||
extern HINSTANCE DllInstance;
|
extern HINSTANCE DllInstance;
|
||||||
WCHAR ModuleFileName[MAX_PATH];
|
WCHAR ModuleFileName[MAX_PATH];
|
||||||
PVOID VersionInfo;
|
PVOID VersionInfo;
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Reflection;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Security;
|
using System.Security;
|
||||||
using System.Security.AccessControl;
|
using System.Security.AccessControl;
|
||||||
@ -850,6 +851,17 @@ namespace Fsp.Interop
|
|||||||
FspWin32FromNtStatus = GetEntryPoint<Proto.FspWin32FromNtStatus>(Module);
|
FspWin32FromNtStatus = GetEntryPoint<Proto.FspWin32FromNtStatus>(Module);
|
||||||
FspDebugLogSetHandle = GetEntryPoint<Proto.FspDebugLogSetHandle>(Module);
|
FspDebugLogSetHandle = GetEntryPoint<Proto.FspDebugLogSetHandle>(Module);
|
||||||
}
|
}
|
||||||
|
private static void CheckVersion()
|
||||||
|
{
|
||||||
|
FileVersionInfo Info;
|
||||||
|
UInt32 Version = 0, VersionMajor, VersionMinor;
|
||||||
|
Info = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location);
|
||||||
|
FspVersion(out Version); VersionMajor = Version >> 16; VersionMinor = Version & 0xFFFF;
|
||||||
|
if (Info.FileMajorPart != VersionMajor || Info.FileMinorPart > VersionMinor)
|
||||||
|
throw new TypeLoadException(String.Format(
|
||||||
|
"incorrect dll version (need {0}.{1}, have {2}.{3})",
|
||||||
|
Info.FileMajorPart, Info.FileMinorPart, VersionMajor, VersionMinor));
|
||||||
|
}
|
||||||
static Api()
|
static Api()
|
||||||
{
|
{
|
||||||
#if false //DEBUG
|
#if false //DEBUG
|
||||||
@ -857,6 +869,7 @@ namespace Fsp.Interop
|
|||||||
Debugger.Break();
|
Debugger.Break();
|
||||||
#endif
|
#endif
|
||||||
LoadProto(LoadDll());
|
LoadProto(LoadDll());
|
||||||
|
CheckVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
[DllImport("kernel32.dll", CallingConvention = CallingConvention.StdCall, SetLastError = true)]
|
[DllImport("kernel32.dll", CallingConvention = CallingConvention.StdCall, SetLastError = true)]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user