例如,在旧的 .NET Framework 2.0 源代码(Windows 窗体,Visual Studio 2005 - Whidbey)中,GetClientRect函数是使用HandleRef定义的:
[DllImport(ExternDll.User32, ExactSpelling=true, CharSet=CharSet.Auto)]
public static extern bool GetClientRect(HandleRef hWnd, [In, Out] ref NativeMethods.RECT rect);
在新的 Windows API 代码包(来自 Microsoft,2009/2010)中,使用IntPtr定义了相同的函数:
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool GetClientRect(IntPtr hwnd, ref CoreNativeMethods.RECT rect);
实际上,在任何 Windows API 代码包源文件中都没有使用HandleRef,而在旧的 .NET Framework 源文件中的本机方法签名中大量使用了它。