|
Cet article a fait l'objet d'une traduction manuelle. Déplacez votre pointeur sur les phrases de l'article pour voir la version originale de ce texte.
|
Traduction
Source
|
GCHandle, structure
Assembly : mscorlib (dans mscorlib.dll)
Le type GCHandle expose les membres suivants.
| Nom | Description | |
|---|---|---|
![]() ![]() | IsAllocated | |
![]() ![]() | Target |
| Nom | Description | |
|---|---|---|
![]() ![]() | AddrOfPinnedObject | |
![]() ![]() ![]() | Alloc(Object) | |
![]() ![]() ![]() | Alloc(Object, GCHandleType) | |
![]() ![]() | Equals | Dans XNA Framework, ce membre est substitué par Equals(Object). |
![]() ![]() | Finalize | |
![]() ![]() | Free | |
![]() ![]() | FromIntPtr | |
![]() ![]() | GetHashCode | Dans XNA Framework, ce membre est substitué par GetHashCode(). |
![]() ![]() | GetType | |
![]() ![]() | MemberwiseClone | |
![]() ![]() | ToIntPtr | |
![]() ![]() | ToString | Dans XNA Framework 3.0, ce membre est hérité de Object.ToString(). |
| Nom | Description | |
|---|---|---|
![]() ![]() | Equality | |
![]() ![]() ![]() | Explicit(GCHandle to IntPtr) | |
![]() ![]() ![]() | Explicit(IntPtr to GCHandle) | |
![]() ![]() | Inequality |
using System; using System.IO; using System.Threading; using System.Windows.Forms; using System.Runtime.InteropServices; using System.Security.Permissions; public delegate bool CallBack(int handle, IntPtr param); public class LibWrap { // passing managed object as LPARAM // BOOL EnumWindows(WNDENUMPROC lpEnumFunc, LPARAM lParam); [DllImport("user32.dll")] public static extern bool EnumWindows(CallBack cb, IntPtr param); } public class App { public static void Main() { Run(); } [SecurityPermission(SecurityAction.Demand, UnmanagedCode=true)] public static void Run() { TextWriter tw = System.Console.Out; GCHandle gch = GCHandle.Alloc(tw); CallBack cewp = new CallBack(CaptureEnumWindowsProc); // platform invoke will prevent delegate to be garbage collected // before call ends LibWrap.EnumWindows(cewp, GCHandle.ToIntPtr(gch)); gch.Free(); } private static bool CaptureEnumWindowsProc(int handle, IntPtr param) { GCHandle gch = GCHandle.FromIntPtr(param); TextWriter tw = (TextWriter)gch.Target; tw.WriteLine(handle); return true; } }
Windows 7, Windows Vista SP1 ou ultérieur, Windows XP SP3, Windows XP SP2 Édition x64, Windows Server 2008 (installation minimale non prise en charge), Windows Server 2008 R2 (installation minimale prise en charge avec SP1 ou version ultérieure), Windows Server 2003 SP2
Le .NET Framework ne prend pas en charge toutes les versions de chaque plateforme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise du .NET Framework.
