为什么`[DllImport]`的入口点为RtlSecureZeroMemory`会失败,即使它是有据可查的入口点? [英] Why does `[DllImport]` fail with an entry point of `RtlSecureZeroMemory`, even though it is a well documented entry point?

查看:138
本文介绍了为什么`[DllImport]`的入口点为RtlSecureZeroMemory`会失败,即使它是有据可查的入口点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用下面的代码尝试使用kernel32函数SecureZeroMemory失败,但System.EntryPointNotFoundException失败-即使它已被很好地证明在这里,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);

推荐答案

该函数已记录,但您所包含的链接均未提供该文档.要了解发生了什么,您应该先阅读此处的实际文档:

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

它说:

此函数定义为 RtlSecureZeroMemory 函数(请参阅WinBase.h). RtlSecureZeroMemory 的实现是内联提供的,可以在任何版本的Windows上使用(请参阅WinNT.h.)

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.)

提供的内联"的含义是该函数在头文件中定义,而不由任何系统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`会失败,即使它是有据可查的入口点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆