|
|
|
| 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-compatibilty. |
| 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 implementations details. |
| 30 |
|
|
| 31 |
|
|
| 32 |
|
#if _MSC_VER > 1000 |
| 33 |
|
#pragma once |
| 34 |
|
#endif |
| 35 |
|
|
| 36 |
|
#if !defined(_INC_GCROOT) |
| 37 |
|
#define _INC_GCROOT |
| 38 |
|
#ifndef RC_INVOKED |
| 39 |
|
|
| 40 |
|
#include <stddef.h> |
| 41 |
|
#define __DEFINE_GCROOT_IN_GLOBAL_NAMESPACE |
| 42 |
|
#include <msclr\gcroot.h> |