Why does `[DllImport]` fail with an entry point of `RtlSecureZeroMemory`, even though it is a well documented entry point?
up vote
0
down vote
favorite
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);
c# windows dll pinvoke kernel32
add a comment |
up vote
0
down vote
favorite
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);
c# windows dll pinvoke kernel32
what kind of .net app are you writing?
– Daniel A. White
Nov 9 at 19:54
WPF app, so windows only
– John
Nov 9 at 20:14
It is not possible, since RtlSecureZeroMemory is not a function exported by a system DLL. It is rather a function inlined in winnt.h Essentially, when including winnt.h in a C/C++ project, the code of this function is becoming part of the code being complied. Now, obviously, you can't inline a C header file with C code in C#... :-(
– elgonzo
Nov 9 at 20:26
So these people who've documented it must've just guessed. Would the best way to__declspec(dllexport)
a wrapper to it in a C++ DLL?
– John
Nov 9 at 20:28
Yeah, you could do that.
– elgonzo
Nov 9 at 20:36
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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);
c# windows dll pinvoke kernel32
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);
c# windows dll pinvoke kernel32
c# windows dll pinvoke kernel32
edited Nov 9 at 19:54
Daniel A. White
147k35290371
147k35290371
asked Nov 9 at 19:53
John
122211
122211
what kind of .net app are you writing?
– Daniel A. White
Nov 9 at 19:54
WPF app, so windows only
– John
Nov 9 at 20:14
It is not possible, since RtlSecureZeroMemory is not a function exported by a system DLL. It is rather a function inlined in winnt.h Essentially, when including winnt.h in a C/C++ project, the code of this function is becoming part of the code being complied. Now, obviously, you can't inline a C header file with C code in C#... :-(
– elgonzo
Nov 9 at 20:26
So these people who've documented it must've just guessed. Would the best way to__declspec(dllexport)
a wrapper to it in a C++ DLL?
– John
Nov 9 at 20:28
Yeah, you could do that.
– elgonzo
Nov 9 at 20:36
add a comment |
what kind of .net app are you writing?
– Daniel A. White
Nov 9 at 19:54
WPF app, so windows only
– John
Nov 9 at 20:14
It is not possible, since RtlSecureZeroMemory is not a function exported by a system DLL. It is rather a function inlined in winnt.h Essentially, when including winnt.h in a C/C++ project, the code of this function is becoming part of the code being complied. Now, obviously, you can't inline a C header file with C code in C#... :-(
– elgonzo
Nov 9 at 20:26
So these people who've documented it must've just guessed. Would the best way to__declspec(dllexport)
a wrapper to it in a C++ DLL?
– John
Nov 9 at 20:28
Yeah, you could do that.
– elgonzo
Nov 9 at 20:36
what kind of .net app are you writing?
– Daniel A. White
Nov 9 at 19:54
what kind of .net app are you writing?
– Daniel A. White
Nov 9 at 19:54
WPF app, so windows only
– John
Nov 9 at 20:14
WPF app, so windows only
– John
Nov 9 at 20:14
It is not possible, since RtlSecureZeroMemory is not a function exported by a system DLL. It is rather a function inlined in winnt.h Essentially, when including winnt.h in a C/C++ project, the code of this function is becoming part of the code being complied. Now, obviously, you can't inline a C header file with C code in C#... :-(
– elgonzo
Nov 9 at 20:26
It is not possible, since RtlSecureZeroMemory is not a function exported by a system DLL. It is rather a function inlined in winnt.h Essentially, when including winnt.h in a C/C++ project, the code of this function is becoming part of the code being complied. Now, obviously, you can't inline a C header file with C code in C#... :-(
– elgonzo
Nov 9 at 20:26
So these people who've documented it must've just guessed. Would the best way to
__declspec(dllexport)
a wrapper to it in a C++ DLL?– John
Nov 9 at 20:28
So these people who've documented it must've just guessed. Would the best way to
__declspec(dllexport)
a wrapper to it in a C++ DLL?– John
Nov 9 at 20:28
Yeah, you could do that.
– elgonzo
Nov 9 at 20:36
Yeah, you could do that.
– elgonzo
Nov 9 at 20:36
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
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
It says:
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.)
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.
Thanks! I'll try and write a C++ wrapper around it to make it work. :)
– John
Nov 9 at 21:16
Why, all it does is zeroise the memory, making sure that the code cannot be optimised out. Surely that can be done in pure C#. Use calls toMarshal.Copy
to force zero bytes into unmanaged memory. Why are you even doing this in the first place?
– David Heffernan
Nov 9 at 21:18
This project I'm doing is primarily for experience, so I could just use Array.Clear(), but I was curious about using [DllImport] so gave it a shot
– John
Nov 9 at 21:21
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
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
It says:
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.)
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.
Thanks! I'll try and write a C++ wrapper around it to make it work. :)
– John
Nov 9 at 21:16
Why, all it does is zeroise the memory, making sure that the code cannot be optimised out. Surely that can be done in pure C#. Use calls toMarshal.Copy
to force zero bytes into unmanaged memory. Why are you even doing this in the first place?
– David Heffernan
Nov 9 at 21:18
This project I'm doing is primarily for experience, so I could just use Array.Clear(), but I was curious about using [DllImport] so gave it a shot
– John
Nov 9 at 21:21
add a comment |
up vote
1
down vote
accepted
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
It says:
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.)
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.
Thanks! I'll try and write a C++ wrapper around it to make it work. :)
– John
Nov 9 at 21:16
Why, all it does is zeroise the memory, making sure that the code cannot be optimised out. Surely that can be done in pure C#. Use calls toMarshal.Copy
to force zero bytes into unmanaged memory. Why are you even doing this in the first place?
– David Heffernan
Nov 9 at 21:18
This project I'm doing is primarily for experience, so I could just use Array.Clear(), but I was curious about using [DllImport] so gave it a shot
– John
Nov 9 at 21:21
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
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
It says:
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.)
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.
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
It says:
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.)
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.
answered Nov 9 at 20:58
David Heffernan
512k338061201
512k338061201
Thanks! I'll try and write a C++ wrapper around it to make it work. :)
– John
Nov 9 at 21:16
Why, all it does is zeroise the memory, making sure that the code cannot be optimised out. Surely that can be done in pure C#. Use calls toMarshal.Copy
to force zero bytes into unmanaged memory. Why are you even doing this in the first place?
– David Heffernan
Nov 9 at 21:18
This project I'm doing is primarily for experience, so I could just use Array.Clear(), but I was curious about using [DllImport] so gave it a shot
– John
Nov 9 at 21:21
add a comment |
Thanks! I'll try and write a C++ wrapper around it to make it work. :)
– John
Nov 9 at 21:16
Why, all it does is zeroise the memory, making sure that the code cannot be optimised out. Surely that can be done in pure C#. Use calls toMarshal.Copy
to force zero bytes into unmanaged memory. Why are you even doing this in the first place?
– David Heffernan
Nov 9 at 21:18
This project I'm doing is primarily for experience, so I could just use Array.Clear(), but I was curious about using [DllImport] so gave it a shot
– John
Nov 9 at 21:21
Thanks! I'll try and write a C++ wrapper around it to make it work. :)
– John
Nov 9 at 21:16
Thanks! I'll try and write a C++ wrapper around it to make it work. :)
– John
Nov 9 at 21:16
Why, all it does is zeroise the memory, making sure that the code cannot be optimised out. Surely that can be done in pure C#. Use calls to
Marshal.Copy
to force zero bytes into unmanaged memory. Why are you even doing this in the first place?– David Heffernan
Nov 9 at 21:18
Why, all it does is zeroise the memory, making sure that the code cannot be optimised out. Surely that can be done in pure C#. Use calls to
Marshal.Copy
to force zero bytes into unmanaged memory. Why are you even doing this in the first place?– David Heffernan
Nov 9 at 21:18
This project I'm doing is primarily for experience, so I could just use Array.Clear(), but I was curious about using [DllImport] so gave it a shot
– John
Nov 9 at 21:21
This project I'm doing is primarily for experience, so I could just use Array.Clear(), but I was curious about using [DllImport] so gave it a shot
– John
Nov 9 at 21:21
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53232456%2fwhy-does-dllimport-fail-with-an-entry-point-of-rtlsecurezeromemory-even-t%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
what kind of .net app are you writing?
– Daniel A. White
Nov 9 at 19:54
WPF app, so windows only
– John
Nov 9 at 20:14
It is not possible, since RtlSecureZeroMemory is not a function exported by a system DLL. It is rather a function inlined in winnt.h Essentially, when including winnt.h in a C/C++ project, the code of this function is becoming part of the code being complied. Now, obviously, you can't inline a C header file with C code in C#... :-(
– elgonzo
Nov 9 at 20:26
So these people who've documented it must've just guessed. Would the best way to
__declspec(dllexport)
a wrapper to it in a C++ DLL?– John
Nov 9 at 20:28
Yeah, you could do that.
– elgonzo
Nov 9 at 20:36