问题描述
使用下面的代码尝试使用kernel32函数SecureZeroMemory
失败,但System.EntryPointNotFoundException
失败-即使它已被很好地证明在这里,在PInvoke上,在在这里,SO上.在目标.NET Framework 4.7.2上运行完全正常的Windows 10 Pro.
Attempting to use the kernel32 function SecureZeroMemory
, using the code below, fails, with System.EntryPointNotFoundException
- even though it is well documented here, on PInvoke, and here, on SO. Running completely normal Windows 10 Pro, on target .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/zh-CN/library/windows/desktop/aa366877(v = vs.85).aspx
This function is documented, but neither of the links that you include are the documentation. To understand what is going on, you should start by reading the actual documentation which is here: https://msdn.microsoft.com/en-us/library/windows/desktop/aa366877(v=vs.85).aspx
它说:
提供的内联"的含义是该函数在头文件中定义,而不由任何系统DLL导出.这意味着无法通过p/invoke调用它.
What is meant by "provided inline" is that the function is defined in the header files and not exported by any system DLL. Which means that it cannot be called by p/invoke.
这篇关于为什么`[DllImport]`的入口点为RtlSecureZeroMemory`会失败,即使它是有据可查的入口点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!