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
1












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









share|improve this question























  • 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














up vote
0
down vote

favorite
1












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









share|improve this question























  • 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












up vote
0
down vote

favorite
1









up vote
0
down vote

favorite
1






1





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









share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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
















  • 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












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.






share|improve this answer




















  • 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











  • 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










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















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

























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.






share|improve this answer




















  • 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











  • 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














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.






share|improve this answer




















  • 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











  • 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












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.






share|improve this answer












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.







share|improve this answer












share|improve this answer



share|improve this answer










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
















  • 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











  • 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

















 

draft saved


draft discarded















































 


draft saved


draft discarded














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





















































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







Popular posts from this blog

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo