Pro Visual C++-CLI And The .NET 2.0 Platform (2006) [eng]-1
.pdf878 ■I N D E X
access, 135 creating, 135
defining properties within, 135 instantiating object from, 135 pure virtual methods, 135
ref class benefits, 92 InterfaceTypeAttribute class, 209 interior pointers, 815, 816, 817 Interlocked class, 212, 662, 682–684
Decrement method, 692 interlocked variable
multithreaded programming using, 682–684 Internet permission, 784
Interop Assembly, 839 creating, 839
tlbimp tool, 839, 840
generating in Visual Studio .NET, 840, 841 invoking, 841, 843
InteropServices namespace, 24, 208, 821, 829, 834
Interrupt method Thread class, 666, 675
Intersect method Region class, 469
Intersection method
Rectangle/RectangleF structures, 465, 466 Interval property
Timer component, 374 Invalidate method, 459
stopping form from clearing itself, 507 Invoke method
invoking delegates, 182, 185 MethodInfo class, 736
InvokeMember method Type class, 845
IO namespaces, 24, 203, 204, 750 IOException class, 203, 716
Ipc namespace, 210 IPEndPoint class
assigning by SendTo method, 710 binding socket to, 707
communicating with other systems, 707 creating EndPoint from constructor, 708 incoming messages, 707
no bind to, 710 IPrincipal interface, 778
IsInRole method, 780 members, 778
“is a” relationship, 128 IsAbstract property
Type class, 732 IsArray property
Type class, 732 IsAuthenticated property
IIdentity interface, 777 IsBackground property
Thread class, 665, 666 IsClass property
Type class, 732 IsDefault property
ButtonBase class, 327 IsDescendant method
XPathNavigator class, 593 IsEmpty method
Region class, 469 IsEmpty property
Point/PointF structures, 463 Rectangle/RectangleF structures, 465 Size/SizeF structures, 464
IsEmptyElement property XmlReader class, 562 XPathNavigator class, 593
IsEnum property Type class, 732 IsImport property Type class, 732 IsInfinite method
Region class, 469 IsInRole method
IPrincipal interface, 778, 780 IsKnownColor method
Color class, 480 IsNamedColor method Color class, 480 IsNotPublic property
Type class, 733 IsPrimitive property Type class, 733
IsPublic property Type class, 733
IsReadOnly property XmlNode class, 583
IsSamePosition method XPathNavigator class, 593
IsSealed property Type class, 733
IsSerializable property Type class, 733 IsStartElement method
XmlReader class, 563 IsSynchronized property
generic collection classes, 264 IsSystemColor method
Color class, 480 IsValidInput property
TypeValidationEventArgs argument, 346 IsValueType property
Type class, 733 Italic property
Font class, 476 Item property
XmlNode class, 583 XmlReader class, 563
Items Collection Editor dialog box, 409 Items property
ListBox control, 359
■J
JIT (just-in-time) compilation common language runtime, 17
Join method
Thread class, 666, 673 JustInTimeActivationAttribute, 202
■K
KernelDriver service, 607 KeyCollection class
Dictionary<K,V> collections, 274 KeyedCollection<K,V> class, 197, 242, 278 keys
AllKeys property, 262 AssemblyKeyFileAttribute attribute, 752 ContainsKey method, 253 ForeignKeyConstraint, 548
GetKey method, 262 IndexOfKey method, 253 RegistryKey class, 216 ShortcutKeys property, 415 ShowShortcutKeys property ToolStripMenuItem control, 415 SortKey class, 203
■I N D E X 879
key/value pairs
Hashtable collection, 252, 253 ListDictionary collection, 258 SortedList collection, 252, 253 KeyValuePair<K,V> element type
Dictionary<K,V> collections, 274 keywords
reserved double-word keywords, 31 variable naming restrictions, 31
■L
L masking character, 346 Label control, 324–326
MightyLabel example, 326 namespace, 215 properties, 324, 325
LabelEdit property ListView control, 380 TreeView control, 387
labels ToolStripLabel, 404
LabelWrap property ListView control, 380
Language attribute
C++/CLI support for Web services, 638 Language property
Form class, 769 languages
see programming languages LargeIcon mode
View property, ListView control, 379 LargeImageList property
ListView control, 380 LastAccessTime property
FileSystemInfo class, 280 LastChild property
XmlNode class, 583 last-in-first-out (LIFO) collection
see Stack collection LastNode property
TreeNode class, 389 LastWriteTime property
FileSystemInfo class, 280 late binding
COM objects, 844, 845 LayoutKind::Sequential arrangement
StructLayoutAttribute class, 836
880■I N D E X
Left property
Rectangle/RectangleF structures, 465 left shift (<<) operator, 63, 64
length
MaxLength property, 344, 365 SelectionLength property, 344, 365
Length property Array object, 46 Stream class, 292
less than (<) character, 347
avoiding in integrated XML documentation, 223
less than (<) operator, 62 LevelFinal attribute
PolicyStatementAttribute class, 785 libraries
.NET Framework class library, 193–216 adding namespaces to, 147–149
building library assembly from command line, 154
declaring/accessing data types, 145 header files, 145, 146
multifile libraries, 145–154
building assemblies from, 149–154 source files, 145, 147
splitting into file types, 145 Lifetime namespace, 210 line (#line) directive, 140 LineAlignment property
StringFormat class, 474 LineJoin property
Pen class, 482 lines
drawing custom shapes/lines, 492–494 Multiline property, 344, 395 ShowLines property, 387 ShowRootLines property, 388
LinkedList<T> collection, 269–271 AddXyz methods, 270
arrays compared, 269 constructors, 269 description, 242 Find method, 270 FindList method, 270
LinkedListNode<T> properties, 270 namespace, 197
RemoveXyz methods, 270
LinkedListNode<T> collection navigation using, 270
Next property, 270 Previous property, 270 properties, 270
LinkLabel class, 215 List mode
View property, ListView control, 379 list tag
example using, 238
integrated XML documentation, 231 creating bulleted list, 231 creating definition of term, 232 creating numbered list, 232 creating table, 232
List<T> collection, 265–268 Action<T> delegate, 265, 266 ArrayList collection and, 265 constructors, 265 description, 242
Exists method, 266 Find method, 266
FindAll method, 266, 267 FindIndex method, 267 FindLastIndex method, 267 FindList method, 267 ForEach method, 266 namespace, 197
Predicate<T> delegate, 265, 266 TrueForAll method, 267
ListBox control, 359–364 CheckedListBox control, 368–372 handling double-click event, 363 methods, 359
modes controlling number of selections, 359 namespace, 215
properties, 359 SelectionMode property, 359
transferring selected items between lists, 360 ListBoxItem method
selecting records from DataSet, 552 ListControl class, 358
ListDictionary collection, 257–259 Add method, 258
description, 242 key/value pairs, 258 namespace, 196
Listen method Socket class, 697
lists
ArrayList collection, 245–248 CheckedListBox control, 368–372 CheckListBox class, 214 DropDownList value, 364
FindList method, List<T> collection, 267, 270 IList interface, 243, 358
ImageList component, 377–379 ImageList property, 387, 395, 405 LargeImageList property, 380 LinkedList<T> collection, 269–271 SmallImageList property, 380 SortedList collection, 251–255 XmlNodeList, 584
ListView control, 379–386 adding list items to view, 386 creating/configuring, 385
creating headers for ListView items, 386 methods, 380
properties, 379 View property, 379
literals, C++/CLI, 55–60 Boolean literals, 57 character literals, 58–59 numeric literals, 55–56 string literals, 59–60
load factor
Hashtable collection, 252 Load method
XmlDataDocument class, 601 XmlDocument class, 585
loading XML documents, 586 LoadFile method
RichTextBox control, 352, 353 LoadWithPartialName method, 735 LoadXml method
XmlDocument class, 585 local instances/objects, 96
instantiating ref class objects, 96 local scope/variables, 54
caution: multiple namespaces, 55 caution: returning handle to variable of, 78
caution: returning reference to variable of, 79 namespaces, 55
LocalIntranet permission, 784
■I N D E X 881
localization, 764, 765
building multicultural console application, 770, 771, 772, 773
building multicultural Windows application, 767, 768, 769, 770
localization tools, 767 LocalName property XmlNode class, 583
XmlReader class, 563 XPathNavigator class, 593
LocalService context Windows services, 608
LocalSystem context Windows services, 608, 609
Location property Rectangle/RectangleF structures, 465
locks
AcquireReaderLock method, 691 AcquireWriterLock method, 692 deadlocks, 692
ReaderWriterLock class, 213, 663, 691–693 ReleaseReaderLock method, 692 ReleaseWriterLock method, 692
logical operators, 62
binary operator overloading, 115 precedence, 63
long alias, integer data type, 33 long long alias, integer data type, 33 looping, C++/CLI, 71–75
break statement, 75 continue statement, 75 do while loop, 72–73 for each loop, 74–75 for loop, 73–74 skipping iterations, 75 while loop, 71–72
LPStr/LPTStr/LPWStr values UnmanagedType enumeration, 834
■M
Machine policy statements, 785 MachineName property
ServiceController class, 628 Madd
comparing to UMadd, 808 Mail namespace, 24
System::Net, 206
System::Web, 213
882■I N D E X
main function
C++/CLI programs, 28
debugging Windows services, 632–633 new main function, 82
passing arguments to, 80–82 standard main function, 81 unsafe code, 81
void parameter, 28 WinMain function, 28
major version, 749 MakeEmpty method Region class, 469 MakeInfinite method Region class, 469
managed and unmanaged #pragma directives, 807, 808, 809
Managed C++, 14 managed classes
declarations compared to unmamaged classes, 812
mixing with unmamaged classes, 812 managed code
.NET Framework advantages, 6 C++/CLI compiler, 13 command-line switches, 13 common language runtime, 13
managed data
common language runtime, 13 Managed Extensions for C++, 812 managed heap
default to CRT heaps, 92 instantiating ref class objects, 96 pointers/unsafe code, 30
String data type, 41 managed heap declaration
template parameters, 160 managed objects
serialization, 302–307
setting up classes for serialization, 302–304 managed providers
ADO.NET, 526–527 connection strings, 530
managed types
generic collection classes, 264 Management namespace, 204, 205 ManagementClass class, 205 ManagementEventWatcher class, 205
ManagementNamedValueCollection class, 205 ManagementObject class, 205 ManagementObjectCollection class, 205 ManagementObjectSearcher class, 205 ManagementPath class, 205 ManagementQuery class, 205
manifest
assembly metadata/manifest, 8 ManualResetEvent class, 663 margins
RightMargin property, 353 ShowSelectionMargin property, 353
Marshal class
GetLastWinError method, 832 ReleaseComObject method, 839
Marshal class, 209 MarshalAsAttribute class, 833, 833 MaskCompleted property
MaskedTextBox control, 345 MaskedTextBox control, 345–352
events, 345
example illustrating, 347 masking characters, 346 properties, 345, 346
TypeValidationCompleted event, 346 ValidatingType property, 345
MaskFull property MaskedTextBox control, 345
masking characters MaskedTextBox control, 346
MaskInputRejected event MaskedTextBox control, 345
Matches method XPathNavigator class, 593
Math class, 195 MaxConnections value
SocketOptionName enumeration, 698 MaxDate property
MonthCalendar control, 423 MaxDropDownItems property
ComboBox control, 365 MaximizeBox property
Form class, 315 MaxLength property
ComboBox control, 365 TextBoxBase class, 344
MaxSelectionCount property MonthCalendar control, 423
member access operator dot (.) operator, 96, 97
member methods, ref class, 98–118 constructors, 101
destructors, 104 method overloading, 111
operator overloading, 112 static member methods, 100 static ref class constructors, 103 virtual methods, 106
member properties, ref class, 118–128 array properties, 123
indexed properties, 124
default indexed property, 126 naming restrictions, 119
scalar properties, 119 static properties, 121 trivial properties, 118
member variables, 97 defining, 97
initializing variables, 97 public/protected/private, 98 static member variables, 98
MemberInfo class, 207, 730 retrieving, 732
members tag
NDoc generated documentation, 221 memory management
destructors, 104 garbage collection, 14 pointers/unsafe code, 30
MemoryStream class, 204, 294–297 properties/methods, 295
Menu class, 215 Menu property
Form class, 315 menus
ContextMenu property, 430 ContextMenuStrip control, 414–420 ToolStripMenuItem, 414
MenuStrip control, 414–420 building menu, 414 creation of MenuStrip, 415
ToolStripComboBox, 414, 415 ToolStripItems, 414
■I N D E X 883
Merge method ToolStripManager class, 404
merging
AllowMerge property, 404 Message property
Exception class, 168 MessageBox function, 826 Messaging namespace, 210 metadata
assembly metadata/manifest, 8 assembly type metadata, 9
“Hello World” Win Forms style, 311 IntelliSense using, 9
reflection, 15 Metadata namespace, 210
MetadataServices namespace, 210 method declarations
virtual keyword, 106 method overloading, 111 method overriding, 111 method signature
Web services description service, 637 MethodInfo class, 207, 730
Invoke method, 736 retrieving, 732
methods
CLS rule for parameter lists, 193 creating method to be delegated, 180 member methods, ref class, 98 placing method on delegate, 181 virtual methods, 106
Microsoft Foundation Classes (MFC) MFC library, 21
Win Forms and, 309
Microsoft intermediate language (MSIL), 10 Microsoft::Win32 namespace, 23, 216 Millimeter units
GDI+ GraphicsUnits, 460 Mime namespace, 206 MinDate property
MonthCalendar control, 423 MinimizeBox property
Form class, 315 minor version, 749 minus
ShowPlusMinus property, 388
884■I N D E X
modes
FileMode enumeration, 289 RenderMode property, 404, 405 SelectionMode property, 359 SizeMode property, 420 WrapMode parameter, 487 WrapModes enumeration, 487
Modified property TextBoxBase class, 344
modifiers
auto modifier, 52
data types, C++/CLI, 52–53 extern modifier, 52
static modifier, 53 Module class, 207, 730 Module value
AttributeTargets enumeration, 739, 740 modulus operator, 61
Monitor class, 212, 663, 684–687 Enter method, 684
Exit method, 685
locking for single thread execution, 684 Pulse method, 685, 687
PulseAll method, 685 TryEnter method, 684, 685 Wait method, 685, 687
MonthCalendar control, 423–425 properties, 423
selecting dates at random intervals, 423 MonthlyBoldedDates property
MonthCalendar control, 423 MouseDown event
creating event receiver class, 319 MouseEventArgs class
properties, 319 MouseEventHandler delegate
handling Win Form delegates/events, 319 Move method, File class
caution: destination a directory, 286 MoveNext method
IEnumerator interface, 244 ResourceReader class, 762 MoveTo method, FileInfo class
caution: destination a directory, 286 MoveToRoot method
XPathNavigator class, 595
MoveToXyz methods XPathNavigator class, 593, 594 XmlReader class, 563
MSIL (Microsoft intermediate language), 10 multicast chain, 179
combining/removing delegates from, 181 multicast delegates, 179
events and, 184 MultiColumn property
ListBox control, 359
multicultural console application, 770, 771, 772, 773
multicultural Windows application, 767, 768, 769, 770
multidimensional arrays, 47 MultiExtended list
transferring selected items between lists, 360 MultiExtended value
SelectionMode property, 359 multifile libraries, 145–154 multiline comments, 60 Multiline property
TabControl control, 395 TextBoxBase class, 344
multiple language support common language runtime, 15
multiple platform support common language runtime, 16
MultiSimple list
transferring selected items between lists, 360 MultiSimple value
SelectionMode property, 359 multithreading, 212, 661–694
see also threading aborting threads, 671–673
command types threads are executing, 662 creating Thread instance, 666
defining regions across processes, 687, 689 description, 661–662
executing block of code as single threaded, 684–687
getting thread to sleep, 669–671
interrupting/suspending/resuming threads, 675–677
introduction, 661 joining threads, 673–674 multitasking, 661, 662
MUTually EXclusive (MUTEX) code, 687–691 resolving competing threads, 675–677
caution: changing priorities, 675 obsolete methods, 676
shared resources problem, 679 sharing static variable problem, 682 starting threads, 666–669
delegate from member/static method, 668 static variables problem, 680 synchronization, 679–693
Interlocked class, 682–684 Monitor class, 684–687 Mutex class, 687–691
ReaderWriterLock class, 691–693 ThreadStaticAttribute class, 680–682
System::Threading namespace, 662–663 thread deadlock condition, 692
thread priorities, 665 thread state, 663–665
execution states of thread, 664 threads reading shared resource, 691 using on single CPU, 662
using ThreadPools, 677–679 using threads, 666–677
Mutex class, 212, 663, 687–691 constructors, 689 ReleaseMutex method, 689 WaitOne method, 689
■N
Name property CodeGroup class, 786 Color class, 480 FileSystemInfo class, 280 Font class, 476
IIdentity interface, 777 Thread class, 666, 670 XmlNode class, 583 XmlReader class, 563 XPathNavigator class, 593
named pens, GDI+, 482 named virtual overriding, 107 names
AssemblyName class, 207, 730 AssemblyNameProxy class, 207 DocumentName property, 509 DisplayName property, 628
■I N D E X 885
FromName method, 480 FullName property, 280 IsNamedColor method, 480 LocalName property, 563, 593 MachineName property, 628 ServiceName property, 628 WriteName method, 575
namespaces
see also System::Xyz namespaces, 23 adding to libraries, 147–149 ADO.NET, 516
caution: making classes public, 148 data types, C++/CLI, 54–55
GDI+, 446–447
implementing member methods, 148 inheritance and namespace hierarchy, 194 local scope, 55
public keyword, 148 NameValueCollection collection, 261–263
Add method, 261 AllKeys property, 262 description, 242
Get method, 262 GetKey method, 262 GetValues method, 262 namespace, 196 Remove method, 262 Set method, 261, 262
naming conventions delegates/events, 184
naming restrictions functions, C++/CLI, 76
member properties, ref class, 119 variables, C++/CLI, 31–32
native classes
see unmanaged classes native code, 13, 806 navigation
XPathNavigator class, 593–601 NDoc generated documentation, 221 nested ref classes, 128
accessing, 128
public members, 131 NET (.NET)
explained, 3–4
886■I N D E X
NET (.NET) Framework ADO.NET, 515–558
advantages for programming, 5–6 application development, 21–23 assemblies, 7–11
class library, 23–24 namespaces, table of, 23
common language runtime, 11–17 common language specification, 20 common type system, 17–20 console applications, 21
controls, 323 elements of, 6 Exception class, 168 exception types, 168 explained, 4–5 hierarchy illustrated, 4
language compatibility with, 20 ports, 6
versioning, 750
Web applications, 22 Web services, 22 Windows applications, 21 Windows services, 22
XML implementations, 560–561
NET (.NET) Framework class library, 193–216 assemblies, 194
dialog boxes, 442–444 GDI+ namespaces, 446–447
managing file system, 280–288 Microsoft::Win32 namespace, 216 opening files, 288–290 organizational structure, 193 processing XML data, 560–561
forward-only access, 561–580 working with DOM trees, 560, 581–592
System namespaces, 194 Collections, 195 Data, 197 Deployment, 198 Diagnostics, 198 DirectoryServices, 200 Drawing, 200
EnterpriseServices, 201 Globalization, 202
IO, 203 IO::Ports, 204
Management, 204
Net, 205 Reflection, 206 Resources, 207
Runtime::InteropServices, 208 Runtime::Remoting, 209 Runtime::Serialization, 211 Security, 211
System, 194 Threading, 212 Web, 213
Windows::Forms, 214 Xml, 215
Net namespaces, 24, 205, 206, 695 network programming, 695
asynchronous sockets, 720, 721 accepting connections, 721, 722 asynchronous TCP server, 725–727 connecting to connections, 722, 723 disconnecting from connections, 723 receiving message, 724, 725
sending message, 724 connectionless sockets, 705, 706
UDP client example, 710, 711 UDP server, 706–709
using Connect with UDP, 711, 712 connection-oriented sockets, 696
TCP client, 702–705 TCP server, 696–702
namespaces, 695
socket helper classes/methods, 712 changing socket options, 719, 720 TcpClient, 713, 714
TcpHelper, 714, 715, 716, 717 TcpListener, 712, 713 UdpClient, 717, 719
NetworkInformation namespace, 206 NetworkService context
Windows services, 608, 609 new command, 815
new operator
gcnew operator, 46 NewLineXyz properties
XmlWriterSettings class, 574 NewRow method
DataTable class, 547 Next property
LinkedListNode<T> collection, 270 NextNode property
TreeNode class, 389
NextSibling property XmlNode class, 583
No type DialogResult, 436 nodes
ChildNodes property, 583 CloneNode method, 584 CreateNode method, 584 CreateTextNode method, 584 FirstNode property, 389 HasChildNodes property, 583 ImportNode method, 585 LastNode property, 389 LinkedListNode<T> collection, 270 MoveToContent method, 563 MoveToRoot method, 594 NextNode property, 389 ParentNode property, 583 PrevNode property, 389 processing node types, 568 ReadContentAs method, 563
ReadElementContentAs method, 563 ReadNode method, 585 SelectedNode property, 387 SelectNodes method, 584 SelectSingleNode method, 584 tokens, XML, 564
TreeNode class, 388–393 valid XML, 569 WriteNode method, 575
XML document elements, 559 XML node types, 564 XmlLinkedNode class, 582 XmlNode class, 582 XmlNodeList, 584
Nodes property
TreeNode class, 389, 393 TreeView control, 387
NodeType property XmlNode class, 583 XmlReader class, 563 XPathNavigator class, 593
None node type, XML, 564 None type DialogResult, 436 None value
FileShare enumeration, 290 PermissionState enumeration, 784
nontransactional database access connected ADO.NET, 527–539
■I N D E X 887
NoPrincipal value
PrincipalPolicy enumeration, 779 Normal attribute, files, 286
NOT (!) operator, 62 Not method
BitArray collection, 249 Nothing permission, 784 NotifyIcon control, 430–433
properties, 430 nullptr command, 779
number formats based on culture, 764 number sign (#) symbol
see preprocessor directives numbered lists
integrated XML documentation, 232 NumberFormatInfo class, 202 numeric literals
decimal numbers, 56 exponential numbers, 56 hexadecimal numbers, 56 integer numbers, 56 literals, C++/CLI, 55–56 octal numbers, 55 ToString method, 56
■O
Object class, 194 GetType method, 731
Object data type methods, 41
object initialization
ref class constructors, 101 object model
.NET Framework advantages, 6 object oriented programming
see OOP Object method
Object data type, 41 objects
destructors, 104 handles to, 96
instantiating ref class objects, 95 octal numbers, 55
ODBC managed provider, 526 connection strings, 531
Odbc namespace
ADO.NET namespaces, 516, 527