Pro Visual C++-CLI And The .NET 2.0 Platform (2006) [eng]-1
.pdf858■I N D E X
ComparePosition method XPathNavigator class, 593
comparison operators, 62 precedence, 63
Compile method XPathNavigator class, 593
Complement method Region class, 469
ComponentResourceManager class ApplyResources method, 769
Component classes control inheritance, 323
components
ImageList component, 377–379 Timer component, 373–376
CompoundArray property Pen class, 482, 485
Computer Management tool Groups, 777
ComRegisterFunctionAttribute class, 208 ComSourceInterfacesAttribute class, 208 ComUnregisterFunctionAttribute class, 208 conditional operator, 64
Configuration namespace, 638 System::Net, 206 System::Web, 213
ConformsTo property WebServiceBinding attribute using, 640
Connect method
Socket class, 703, 711, 712 TcpClient class, 713, 714 connected ADO.NET, 527–543
Connected property Socket class, 705 Connection classes
connecting/opening/closing database, 529 nontransactional database access, 529
connection oriented sockets, 696 TCP client, 702
closing connection, 704
connecting to server IPEndPoint, 703 disconnecting from socket, 704, 705 example, 703, 704
TCP server, 696
accepting connection, 698 binding socket to IPEndPoint, 697 creating socket, 696
example, 700, 702
placing accepted connection on its own thread, 698
receiving message, 699, 700 sending message, 698, 699
setting socket to listening mode, 697 connection strings
managed providers, 530 ODBC/OLE DB/Oracle, 531 SQL Server, 531
connectionless sockets, 705, 706 UDP client example, 710, 711 UDP server, 706
binding socket to IPEndPoint, 707 creating, 706
example, 709
receiving message, 707, 708 sending message, 708
using Connect with UDP, 711, 712 connections
BeginConnect method, 722 BeginDisconnect method, 723 EndConnect method, 723 EndDisconnect method, 723 managed providers, 526–527 MaxConnections value, 698
console applications application development, 21
console Web services client application, 649 Console::WriteLine statements, 826
const operator
unary operator overloading, 114 const qualifier
data types, C++/CLI, 52 constants
enums/consts compared, 42 Constraint class, 198
ADO.NET, 548 constructor initialization
declaring variables, 30 ConstructorInfo class, 207, 730
retrieving, 732 constructors
ref class constructors, 101 constructor methods, 101 copy constructor, 102 initializer list, 101
static ref class constructors, 103 unmanaged class constructors, 101
container controls, 394–402 GroupBox control, 336–340 Panel control, 340–343 SplitContainer control, 398–402 TabControl control, 394–398 ToolStrip control, 404
“contains a” relationship, 128 Contains method
ArrayList collection, 247 Rectangle/RectangleF structures, 465, 466
ContainsKey method Hashtable/SortedList collections, 253
ContainsValue method Hashtable/SortedList collections, 253
content nodes
MoveToContent method, 563 ReadContentAs method, 563 ReadElementContentAs method, 563 XML document elements, 559
Content table
column descriptions, 520 entering data, 524
ContentPanel property ToolStripContainer control, 403
ContextMenu property NotifyIcon control, 430
ContextMenuStrip control, 414–420 Contexts namespace, 210 context-sensitive keywords
variable naming restrictions, 32 ContextUtil class, 202
Continue method ServiceController class, 628
continue statement looping, C++/CLI, 75
Control class, 214
control inheritance, 323 OnPaint method, 450 Validating event, 352
controls, 323
AccessControl namespace, 212, 776 button controls, 327–343 container controls, 394–402
event for updating controls, 449 HtmlControls namespace, 214 ListControl class, 358
selection controls, 358–372
■I N D E X 859
strip controls, 402–420 text controls, 343–358 view controls, 379–393
WebControls namespace, 214 controls, list of
Button, 327–329 CheckBox, 330–333 CheckedListBox, 368–372 ComboBox, 364–368 ContextMenuStrip, 414–420 DataGridView, 556–558 ErrorProvider, 426–430 GroupBox, 336–340 ImageList, 377–379
Label, 324–326
ListBox, 359–364
ListView, 379–386 MaskedTextBox, 345–352 MenuStrip, 414–420 MonthCalendar, 423–425 NotifyIcon, 430–433 Panel, 340–343 PictureBox, 420–422 ProgressBar, 374 RadioButton, 334–336 RichTextBox, 352–358 SplitContainer, 398–402 StatusStrip, 410–413 TabControl, 394–398 TextBox, 345
Timer, 373–376 ToolStrip, 404–409
ToolStripContainer, 402–403
ToolStripManager, 403–404 ToolStripPanel, 402–403 TreeView, 387–393
coordinate systems, GDI+, 459–462 changing unit of measure and origin, 462 correctly rendered coordinate strings, 459 default GDI coordinate system, 460 disappearing coordinates, 457
GDI+ GraphicsUnits, 460 GraphicsUnits supported, 460 moving origin, 460
copy constructor
ref class constructors, 102 Copy method
TextBoxBase class, 344
860■I N D E X
Count property
ArrayList collection, 245, 246 Create method
File/FileInfo classes, 288 XmlReader class, 562, 563 XmlWriter class, 575, 577
Create New SQL Server Database dialog box, 518
Create value
FileMode enumeration, 289 CreateAttribute method
XmlDocument class, 584 CreateCDataSection method XmlDocument class, 584
CreateComment method XmlDocument class, 584
CreateDocumentFragment method XmlDocument class, 584
CreateDocumentType method XmlDocument class, 584
CreateElement method XmlDocument class, 584
creating nodes dynamically, 592 CreateEntityReference method
XmlDataDocument class, 601 XmlDocument class, 584
CreateGraphics method Graphics class, 455 CreateInstance method
Activator class, 736, 845 CreateNavigator method
XmlNode class, 584 XPathNavigator class, 595
CreateNew value
FileMode enumeration, 289 CreateNode method
XmlDocument class, 584 CreateText method
File/FileInfo classes, 288 CreateTextNode method
XmlDocument class, 584 CreateXmlDeclaration method XmlDocument class, 585
CreationTime property FileSystemInfo class, 280
Cross enumeration
HatchStyle enumeration, 486 CRT heap
pointers and unsafe code, 30 cryptography
security, 211
Cryptography namespace, 212, 776 CTS (common type system)
.NET Framework elements, 17–20 CTS data types, 18
hierarchy illustrated, 18
language keywords for data types, 19 language support for, 19
Cube ref class, 94 culture, 765, 766
setting culture, 766, 767 CultureInfo class, 202, 765, 766
changing in CurrentThread property, 766 curly brackets
statements, 29 Currency value
UnmanagedType enumeration, 834 CurrentCulture class, 767 CurrentPrincipal property
Thread class, 778, 779, 781 CurrentThread class
CurrentUICulture property, 770 CurrentThread property
Thread class, 666, 670, 766 CurrentUICulture class, 767, 772 CurrentUICulture property
CurrentThread class, 770 Cursor class, 215
Cursor property Form class, 315
custom dialog boxes, 434–442 implementing, 439
CustomAttributeData class, 730 CustomEndCap property
Pen class, 482 CustomStartCap property
Pen class, 482 Cut method
TextBoxBase class, 344
■D
DashXyz properties, Pen class, 482 data
CustomAttributeData class, 730 managed data, 13 PropertyData class, 205
PropertyDataCollection class, 205 QualifierData class, 205 QualifierDataCollection class, 205
data diagrams
DCV_DB data diagram, 519 data marshalling, 833
MarshalAsAttribute class, 833
marshalling ref/value classes, 835, 836, 837 marshalling strings with P/Invoke, 835
Data namespaces, 23, 197, 198, 516, 527 data providers
System::Data namespace, 197 Data Source clause
connection strings, 530 data types, 29–55
arrays type, 46 Boolean type, 38–39
boxing/unboxing, 51–52 character type, 39–40 class templates, 158 CLS primitive types, 20
common type system (CTS), 17 Decimal type, 36–38 declaring/accessing in libraries, 145 Double type, 35
enums/enum classes/enum structs, 42 floating-point types, 35–36
function templates, 157 fundamental types, 32, 33–40 handle data type, 30
integer types, 33–35 namespaces, 54–55 Object type, 41
operator overloading, 117
partial template specialization, 159 pointer types, 17, 30
predefined data types, 32–42 ref class initialization value, 101
reference types, 17, 32, 40–42, 46–51 Single type, 35
String type, 41–42
■I N D E X 861
template specialization, 159 type conversions, 53–54
type modifiers/qualifiers, 52–53 typedef operator, 166
user defined data types, 42–51 using old data types, 29
value struct/value class types, 44 value types, 17, 42–45
data validation
text controls, 352 Data::OleDb namespace, 23 Data::SqlClient namespace, 23 DataAdapter classes, 545
see also DataSet class; SqlDataAdaptor class building DataAdaptor, 549–551 DeleteCommand property, 551 disconnected class interaction, 544 InsertCommand property, 550
managed providers, 526 SelectCommand property, 550 UpdateCommand property, 550
database access
connected ADO.NET, 527–543 disconnected ADO.NET, 544–558 managed providers, 526–527
database connections managed providers, 526–527
databases
building stored procedures, 525–526 building with Visual Studio 2005, 517–526 connecting/opening/closing, 529 creating new database, 518
creating relationships between tables, 520–522 creating tables, 519–520
creating views, 522–524 data diagram, 519
Insert/Update/Delete commands, 536–537 querying database, 532–535
which database to install, 517 DataColumn class, 547
disconnected class interaction, 544 System::Data namespace, 198
DataGridView control
developing with disconnected ADO.NET, 556–558
DataRelation class, 548
disconnected class interaction, 544 namespace, 198
862■I N D E X
DataRelationCollection class, 547 disconnected class interaction, 544 namespace, 198
DataRow class, 547
caution: first index number, 547 disconnected class interaction, 544 namespace, 198
DataSet class, 546
see also DataAdapter class committing/rolling back changed rows, 554 deleting rows from data source, 551, 553 disconnected class interaction, 544 inserting rows into data source, 550, 552 namespace, 198
passing data using Web service, 653, 654, 655 populating DataSet, 550
relationships between tables, 546 selecting records from, 551 Typed DataSet, 554–556
updating rows in data source, 550, 553 DataSet property
XmlDataDocument class, 601 DataSource property
ListControl class, 358 DataTable class, 546
creating table manually in code, 548 disconnected class interaction, 544 namespace, 198 properties/methods, 547
selecting records from DataSet, 552 DataTableCollection class, 546
caution: first index number, 546 collection class functions, 546 disconnected class interaction, 544 namespace, 198
DataView class, 198 dates
AnnuallyBoldedDates property, 423 BoldedDates property, 423 MaxDate property, 423
MinDate property, 423 MonthlyBoldedDates property, 423 ShowToday property, 423 ShowTodayCircle property, 423 ShowWeekNumbers property, 423 TodayDate property, 423 TodayDateSet property, 423
DateTime classes
BinaryReader/Writer classes handling, 300 value type structure, 425
DateTimeFormatInfo class, 202, 765 DCV_DB data diagram, 519 deadlocks
multithreaded programming, 692 Debug/Debugger classes, 199 debugging
self-descriptive variable naming, 32 System::Diagnostics namespace, 199 Web services, 650–651
client and Web service scenarios, 651 Windows services, 630–633
Decimal data type GetBits method, 37
loading number with 15+ significant digits, 37
Decimal data type, 36–38 decimal numbers, 56
declarative role-based security, 781 declaring variables, 29–31 Decrement method
Interlocked class, 692 decrement operator, 61 default
IsDefault property, 327 default keyword
default indexed property, 126 DefaultPageSettings property
PrintDocument class, 509 DefaultTraceListener class, 199
define (#define) directive, 140–142, 156 defined/!defined preprocessor operators, 143 delegate keyword
creating delegates, 180 delegates, 51, 179–183
see also events
.NET Framework support, 179 building event receiver classes, 186 caution: comparing to nullptr, 186 constructors, 181
creating, 179, 180
creating event receiver class, 319 creating method to be delegated, 180 creating/delegating event handlers, 320 CTS data types, 19
events and, 184
handling, Win Forms, 319–323 invoking, 182
multicast delegates, 179, 181 naming conventions, 184 placing method on delegate, 181
delete command, 815 garbage collection, 14
Delete method
deleting rows from data source, 553 FileSystemInfo class, 280
delete operator
IDisposable interface, 105
memory management destructors, 104 ref class drawbacks, 93
DeleteCommand property DataAdapter classes, 551
Delta property MouseEventArgs class, 319
Demand method PrincipalPermission class, 781
DependentServices property ServiceController class, 628
deployment, software, 6 Deployment namespace, 198 depth
ColorDepth property, 378 Depth property
XmlReader class, 562, 567 Dequeue method
Queue collection, 256 dereferenced value
modifying, 68 Description namespace, 638 Description property
CodeGroup class, 786 description services
Web services, 636 WSDL, 637
deserialization, 211, 302 Deserialize method
BinaryFormatter class, 305 designer code
ASP.NET Web Service template, 640 destructors
Finalize destructor method, 105 memory management destructors, 104
■I N D E X 863
ref class objects, 104
resource management destructors, 105 Details mode
View property, ListView control, 379 deterministic cleanup, 104
Graphics objects, 455 development, software, 6 CLR and MSIL, 15
using OOP, 87
Diagnostics namespace, 24, 198, 199, 687 DiagonalBrick enumeration
HatchStyle enumeration, 486 dialog boxes, 434–444
AcceptButton property, 436 assigning default buttons, 436 CancelButton property, 436 changing style, 435
common dialog boxes, 442–444 custom dialog boxes, 434–442 DialogResults, 435
returning DialogResult value, 436 implementing custom dialog boxes, 439 passing/getting information, 435 Show/ShowDialog modes, 441
DialogResults dialog boxes, 435
returning DialogResult value, 436 dictionary collections
HybridDictionary collection, 258 ListDictionary collection, 257–259
SortedDictionary<K,V> collection, 197, 242, 260–261
Dictionary<K,V> collection, 197, 242, 273–277 Add method, 273
constructors, 273 interfaces, 273
Key/ValueCollection classes, 274 KeyValuePair<K,V> element type, 274 properties accessing keys/values, 274 Remove method, 274
DictionaryBase collection, 241 dimensions
CalendarDimensions property, 423 PhysicalDimensions property, 490
directives
preprocessor directives, 139
864■I N D E X
directories
common activities with, 282 examining details of directory, 281 file system I/O, 279
listing files/directories, 281 maintaining directory structure, 280
Directory attribute, files, 286 Directory class, 203
examining details of directory, 281 managing file system, 280 methods, 281
DirectoryEntry class, 200 DirectoryInfo class, 203
examining details of directory, 281 managing file system, 280 methods, 281
using, 282 DirectorySearcher class, 200
DirectoryServices namespace, 24, 200 DISCO (Web Services Discovery tool), 637 Disconnect method
Socket class, 705
disconnected data access, 544–558 benefits of, 544
classes assisting, 544 developing with, 549–558
building DataAdaptor, 549–551 committing/rolling back changed rows, 554 DataGridView, 556–558
deleting rows, 553–554 effortless development, 554–558 inserting rows, 552
selecting rows, 551–552 Typed DataSet, 554–556 updating rows, 553
Discovery namespace, 638 discovery services
Web Services, 637 Web services, 636
DispIdAttribute class, 208 Display units
GDI+ GraphicsUnits, 460 DisplayName property
ServiceController class, 628 DisplayStyle property
ToolStrip control, 405 Dispose method
IDisposable interface, 105
distributed applications
.NET Framework advantages, 6 Web services, 635–659
Divots enumeration HatchStyle enumeration, 486
DLL's
calling without P/Invoke, 826, 827, 828 dllimport function, 826 DllImportAttribute class, 208, 209, 829, 830
adding CharSet named parameter, 831 CallingConvention field, 831
CharSet field, 831 EntryPoint field, 831 ExactSpelling field, 831 PreserveSig field, 832 SetLastError field, 832
do while loop, 72–73 continue statement, 75
dock property
SplitContainer control, 398 DOCTYPE declarations
WriteDocType method, 575 Document node type, XML, 564 Document Object Model
see DOM Document units
GDI+ GraphicsUnits, 460 documentation
see also comments danger of omitting, 217
how much documentation, 217, 218 integrated XML documentation
see integrated XML documentation setting standards, 218
documentation tags
see under integrated XML documentation DocumentElement property
XmlDocument class, 584 reading XML documents, 586
documents
CreateDocumentFragment method, 584 CreateDocumentType method, 584 OwnerDocument property, 583 PrintDocument class, 508, 509, 511 XmlDocumentFragment class, 582 XmlDocumentType class, 582
DocumentFragment node type, XML, 564
DocumentName property PrintDocument class, 509
DocumentType node type, XML, 564 DocumentType property
XmlDocument class, 584 dollar ($) character, 347
DOM (Document Object Model), 581 DOM trees
advantages, 581 disadvantages, 581 querying, 584 reading, 585–587
reading recursively, 585 storing in memory, 590 updating, 588–589 working with, 581–592
writing XmlNodes in, 590–592 XmlNode class, 582
XPath expressions accessing, 596 dot (.) character, 346
dot (.) operator, 96
accessing ref class members, 97 double alias, floating-point data types, 35 double buffering, GDI+, 501–508
Happy Face example, 503–508 Double data type, 35 double-word keywords
variable naming restrictions, 31 DrawArc method, 454 DrawClosedCurve method, 454 DrawCurve method, 454 DrawEllipse method, 454 DrawIcon method, 454 DrawImage method, 454
rendering existing images, 490 stretching image, 490
DrawImageUnscaled method, 454 rendering existing images, 489, 490
drawing
optimizing GDI+, 498
Drawing namespaces, 24, 200, 201, 446 DrawLine(s) methods, 454
DrawPie method, 454 DrawPolygon method, 454 DrawRectangle(s) methods, 454
DrawString method, 449, 454, 472–475 parameters, 472
StringFormat parameter, 473
■I N D E X 865
drop down lists
MaxDropDownItems property, 365 ToolStripDropDownButton, 404
DropDown value ComboBoxStyle list, 364
DropDownItems property ToolStripMenuItem control, 415
DropDownList value ComboBoxStyle list, 364
DropDownStyle options ComboBox control, 364
DroppedDown property ComboBox control, 365
DTD (document type definition) caution: validation using, 571 ProhibitDtd property, 571 validating XML file, 569, 570
dynamic_cast operator
type casting between class types, 131 verifying, 131
■E
editing
LabelEdit property, 380, 387 Elapse handler
Timer component, 616 Element node type, XML, 564
processing node types, 568 elements
CreateElement method, 584, 592 DocumentElement property, 584 EndElement node type, XML, 564 GetElementById method, 585, 601 GetElementFromRow method, 601 GetElementsByTagName method, 585 GetRowFromElement method, 601 IsEmptyElement property, 562, 593 IsStartElement method, 563 MoveToElement method, 563 ReadElementContentAs method, 563 ReadElementString method, 563 ReadEndElement method, 563 ReadStartElement method, 563 WriteElementString method, 575 WriteEndDocument method, 575 WriteEndElement method, 575 WriteFullEndElement method, 575 WriteStartElement method, 575
866 ■I N D E X
XML documents, 559 XmlElement class, 582
elif (#elif) preprocessor directive, 142 else (#else) preprocessor directive, 142 else constructs, if statement, 69 EmitConformanceClaims property
WebServiceBinding attribute using, 640 empty
IsEmpty method, 469 MakeEmpty method, 469
Enable property Panel control, 340
Enabled property
Timer component, 373 ToolStripMenuItem control, 415
EnableVisualStyles method Application class, 311
encapsulation, OOP, 85 inheritance and, 93
member properties, ref class, 118 software development using objects, 87
Encoding property XmlWriterSettings class, 574
Encrypted attribute, files, 286 end caps
CustomEndCap property, 482 end tag
XML document elements, 559 EndAccept method
Socket class, 722 EndCap property
Pen class, 482 EndConnect method Socket class, 723
EndDisconnect method Socket class, 723
EndElement node type, XML, 564 EndEntity node type, XML, 564 EndPoint class
creating from IPEndPoint constructor, 708 providing origin of messages, 707
Enqueue method Queue collection, 256
EnsureVisible method ListView control, 380
Enter method Monitor class, 684
Enterprise policy statements, 785 EnterpriseServices namespace, 201, 202 entities
CreateEntityReference method, 584, 601 EndEntity node type, XML, 564 XmlEntity class, 582 XmlEntityReference class, 582
Entity node type, XML, 564 EntityReference node type, XML, 564
WriteEntityRef method, 575 EntryPoint field
DllImportAttribute class, 831 EntryPoint string value, 831 EntryWrittenEventHandler class, 199 enum class
displaying String name, 586 Enum value
AttributeTargets enumeration, 739, 740 enumerations
see also GetEnumerator method CTS data types, 19
enums/enum classes/enum structs, 42 CLI enums, 43
declaring enums, 43 enums/consts compared, 42 native enum, 43
ToString method, 43 EOF property
XmlReader class, 562
equal to (= =)/not equal to (!=) operators, 62 caution: assignment (=) operator, 62
equals
ReferenceEquals method, 41 Equals method, Object data type, 41
updating DOM trees, 589
error (#error) preprocessor directive, 140 error handling
see also exceptions code verification, 14
ErrorProvider control, 426–430 methods/properties, 426
errors
BeepOnError property, 345 GetLastWinError method, 832 SetError method, 426 SetLastError field, 832
escape sequences character literals, 58 string literals, 59
table of special escape sequences, 58 Evaluate method
XPathNavigator class, 593 event handling
creating/delegating event handlers, 320 delegating event handler, XML, 573 properties view of, 320
TooMany_Click method, 329 Win Forms, 319–323
event keyword creating events, 184
event log files
System::Diagnostics namespace, 199 event receiver class, 319
event source class creating, 184
EventClassAttribute, 202 EventInfo class, 207, 730
retrieving, 732 EventLog control, 199
customizing Windows services, 615 EventQuery class, 205
events, 51, 184–189 see also delegates
add_<delegate-name> method, 185 AutoResetEvent class, 662 building event receiver classes, 186 CancelEventArgs argument, 352
CanHandleSessionChangeEvent property, 614 caution: comparing to nullptr, 186
checking SelectedItem for nullptr, 363 classes and events, 184
creating event source class, 184 delegates and, 184 EntryWrittenEventHandler class, 199 event handler accepting Tick events, 373 GetEvent(s) methods, 732 implementing, 187
introduction, 179 ManualResetEvent class, 663 MouseEventArgs class, 319 MouseEventHandler delegate, 319 naming conventions, 184 PaintEventArgs class, 449
■I N D E X 867
PaintEventHandler event handler, 449, 450–453
raise_<delegate-name> method, 185 remove_<delegate-name> method, 185 scheduling events, 373 TreeViewCancelEventHandler, 392 triggering, 185 TypeValidationEventArgs argument, 346 ValidationEventHandler, 573
evidence
code access security, 790–795 ExactSpelling field
DllImportAttribute class, 831 ExactSpelling value
CharSet enumeration, 831 example tag
example using, 237, 238
integrated XML documentation, 226 Exception class
.NET Framework, 168 ApplicationException, 168, 170
catching previously uncaught exceptions, 176
exception types, 168 properties, 168 SystemException, 168, 169
exception tag example using, 238
integrated XML documentation, 228 exceptions, 166–178
.NET Framework exception types, 168 ADO.NET, 531 ApplicationException, 168
throwing ApplicationExceptions, 170 catching multiple exceptions, 173
catching previously uncaught exceptions, 176 code access verification, 14
code verification, 14
exception handling described, 166 executing code regardless of, 177
order of system exception inheritance, 174 rethrowing exception, 172 SystemException, 168, 169 ThreadAbortException, 671, 673 ThreadStateException, 671, 673
Exclude method Region class, 469