为什么 `[DllImport]` 以 `RtlSecureZeroMemory` 的入口点失败,即使它是一个有据可查的入口点?
Why does `[DllImport]` fail with an entry point of `RtlSecureZeroMemory`, even though it is a well documented entry point?
尝试使用 kernel32 函数 SecureZeroMemory
,使用下面的代码失败,System.EntryPointNotFoundException
- 即使它有很好的文档记录 here, on PInvoke, and 。 运行 完全正常 Windows 10 Pro,在目标 .NET Framework 4.7.2 上。
/// <summary>
/// A kernel32 function that destroys all values in a block of memory
/// </summary>
/// <param name="destination">The pointer to the start of the block to be zeroed</param>
/// <param name="length">The number of bytes to zero</param>
/// <returns></returns>
[DllImport("kernel32.dll", CharSet = CharSet.Auto, EntryPoint = "RtlSecureZeroMemory")]
public static extern void SecureZeroMemory(IntPtr destination, IntPtr length);
此功能已记录在案,但您包含的两个链接都不是文档。要了解发生了什么,您应该首先阅读此处的实际文档:https://msdn.microsoft.com/en-us/library/windows/desktop/aa366877(v=vs.85).aspx
它说:
This function is defined as the RtlSecureZeroMemory function (see WinBase.h). The implementation of RtlSecureZeroMemory is provided inline and can be used on any version of Windows (see WinNT.h.)
"provided inline"的意思是函数定义在头文件中,不被任何系统DLL导出。这意味着它不能被 p/invoke.
调用
尝试使用 kernel32 函数 SecureZeroMemory
,使用下面的代码失败,System.EntryPointNotFoundException
- 即使它有很好的文档记录 here, on PInvoke, and
/// <summary>
/// A kernel32 function that destroys all values in a block of memory
/// </summary>
/// <param name="destination">The pointer to the start of the block to be zeroed</param>
/// <param name="length">The number of bytes to zero</param>
/// <returns></returns>
[DllImport("kernel32.dll", CharSet = CharSet.Auto, EntryPoint = "RtlSecureZeroMemory")]
public static extern void SecureZeroMemory(IntPtr destination, IntPtr length);
此功能已记录在案,但您包含的两个链接都不是文档。要了解发生了什么,您应该首先阅读此处的实际文档:https://msdn.microsoft.com/en-us/library/windows/desktop/aa366877(v=vs.85).aspx
它说:
This function is defined as the RtlSecureZeroMemory function (see WinBase.h). The implementation of RtlSecureZeroMemory is provided inline and can be used on any version of Windows (see WinNT.h.)
"provided inline"的意思是函数定义在头文件中,不被任何系统DLL导出。这意味着它不能被 p/invoke.
调用