Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can find a more complete answer about the difference between <code>SafeHandle</code> and <code>IntPtr</code> here: <a href="https://stackoverflow.com/questions/526661/intptr-safehandle-and-handleref-explained">IntPtr, SafeHandle and HandleRef - Explained</a></p> <p>However, to summarize, <code>IntPtr</code> should be used where the argument is actually a <em>machine-size pointer</em> - <code>SafeHandle</code> should be used where the argument is actually a Win32 handle. These types are not generally interchangeable; the size of <code>IntPtr</code> will vary on different architectures (32 bits on x86 and 64 bits on x64 and amd64). NOTE: Under the covers I believe <code>SafeHandle</code> uses an <code>IntPtr</code> as well).</p> <p>Also, unlike <code>IntPtr</code>, <code>SafeHandle</code> actually performs disposal of resources when a type is garbage collected. This ensures that system resources are not leaked when your program is running (although you should <code>Dispose()</code> of <code>SafeHandle</code> instances early when possible). Note that <code>SafeHandle</code> is actually abstract because there many different kinds of handles which require different approaches for proper disposal and handling.</p> <p>In your specific case, you need to look at the documentation for the DLL you are calling. If it is a Win32 DLL, there may already be a SafeHandle type for it. If it's a third-party DLL, then you can roll your own SafeHandle implementation - assuming that in addition to <code>Initialize()</code> there is some version of <code>Release()</code> (or equivalent).</p> <p>Some additional interesting tidbits about IntPtr vs SafeHandle can be found at:</p> <p><a href="http://msdn.microsoft.com/en-us/library/ms182294(v=vs.80).aspx" rel="nofollow noreferrer">Use SafeHandle to encapsulate native resources</a></p> <p><a href="http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.safehandle.aspx" rel="nofollow noreferrer">SafeHandle Class Reference</a></p> <p><a href="http://msdn.microsoft.com/en-us/library/fh21e17c.aspx" rel="nofollow noreferrer">SafeHandles and Critical Finalization</a></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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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