STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
gcroot.h
Go to the documentation of this file.
1 //
2 // gcroot.h - Template class that wraps GCHandle from mscorlib.dll.
3 // Copyright (C) Microsoft Corporation
4 // All rights reserved.
5 //
6 // This include file is provided for back-compatibility.
7 // Include <msclr/gcroot.h> and use ::msclr::gcroot instead of ::gcroot.
8 //
9 // Use this class to declare gc "pointers" that live in the C++ heap.
10 //
11 // Example:
12 // struct StringList {
13 // gcroot<String^> str;
14 // StringList *next;
15 // StringList(); // should have ctors and dtors
16 // ~StringList();
17 // };
18 //
19 // By convention, we maintain a 1-to-1 relationship between C++ objects
20 // and the handle slots they "point" to. Thus, two distinct C++ objects
21 // always refer to two distinct handles, even if they "point" to the same
22 // object. Therefore, when the C++ object is destroyed, its handle can
23 // be freed without error.
24 //
25 // Note that we cannot currently embed a GCHandle directly in an unmanaged C++
26 // class. We therefore store a void*, and use the conversion methods of
27 // GCHandle to reconstitute a GCHandle from the void* on demand.
28 //
29 // See msclr/gcroot.h for implementation details.
30 
31 #if _MSC_VER > 1000
32 #pragma once
33 #endif
34 
35 #if !defined(_INC_GCROOT)
36 #define _INC_GCROOT
37 #ifndef RC_INVOKED
38 
39 #include <stddef.h>
40 #if !defined (_INC_MSCLR_GCROOT) // This means that msclr/gcroot.h is already included
41 #define __DEFINE_GCROOT_IN_GLOBAL_NAMESPACE // Scheduled for removal. The intention is to retain ::msclr::gcroot
42 #include <msclr/gcroot.h>
43 namespace msclr
44 {
45  using ::gcroot;
46 }
47 #endif /* !defined (_INC_MSCLR_GCROOT) */
48 
49 #endif /* RC_INVOKED */
50 #endif // _INC_GCROOT
Definition: gcroot.h:43