Note that there are some explanatory texts on larger screens.

plurals
  1. POIs IntPtr.Zero equivalent to null?
    primarykey
    data
    text
    <p>I am trying to setup <code>ReadFile</code> to run asynchronously and according to <a href="http://msdn.microsoft.com/en-us/library/aa365467(VS.85).aspx" rel="noreferrer">MSDN</a>, I need to set <code>lpNumberOfBytesRead</code> to <code>null</code>:</p> <blockquote> <p>"Use NULL for this parameter if this is an asynchronous operation to avoid potentially erroneous results."</p> </blockquote> <p>For example, if I have the following:</p> <pre><code> [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)] public static extern bool ReadFile( IntPtr hFile, out byte[] aBuffer, int cbToRead, IntPtr cbThatWereRead, ref OVERLAPPED pOverlapped ); </code></pre> <p>and I call it like this (with the intention of having the 4th parameter being null):</p> <pre><code>Win32API.ReadFile(readHandle, out data_read, Win32API.BUFFER_SIZE, IntPtr.Zero, ref over_lapped); </code></pre> <p>will that be the same as calling it with null? If not, what should I change in the declaration or in the function call itself?</p> <p>I was also curious if I should be using <code>SafeHandle</code> or <code>HandleRef</code> instead of <code>IntPtr</code> for the <code>hFile</code> reference? I know to make sure that I close the handle with <code>CloseHandle(IntPtr)</code> when I'm done with it, just not sure if there is any othe reason to use the other two options over <code>IntPtr</code>. I am also tryingn to avoid using unsafe code.</p> <p>EDIT: As it turns out, I shouldnt be setting the fourth parameter to <code>IntPtr.Zero</code> anyway, because even though I am running asynchronously, it could still return right away. See <a href="http://support.microsoft.com/kb/156932" rel="noreferrer">Asynchronous Disk I/O</a>. Ahh, I love contradicting stories.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload