accessors
get, 442
let, 442
set, 442
Activated event, 625
Activator.CreateInstance method (COM Interoperability), 91
ActiveX
Assembly, 712
containers, hosting Windows Forms controls in, 471–477
controls, 120–121
converting, 196–198
referencing in Visual Studio .NET, 121–122
referencing with .NET Framework SDK, 122–123
events, 240–245
importer transformations, 235–240
ActiveX Control. See AXIMP.EXE
ActiveX Data Objects, 92–94
adapter objects
CCWs, 904–905
custom marshalers, 901–909
alternative to, 910–913
ICustomAdapter interface implementation, 909
RCWs, 904–906
Add Reference command (Project menu), 25
C# definition, 994
VB .NET definition, 994
AddMessage method, 625
AddNotificationType method, 285
AddRef method (Marshal class), 1294
AddressLists dispinterface
IDL representation, 982
.NET Definition in Visual C++, 982–984
AddrOfPinnedObject method (GCHandle value type), 1275
addRule parameter
C# definition, 994
VB .NET definition, 994
add_EventName method, 592
ADO (ActiveX Data Objects), 92–94
Advise method, 216
Alias keyword, customizing PInvoke function names, 796
Alloc method (GCHandle value type), 1275
AllocCoTaskMem method (Marshal class), 1295
AllocHGlobal method (Marshal class), 1295
AllowMultiple property, 30
AllowPartiallyTrusted-CallersAttribute, 305–307, 419, 473
AnimatedEnvelopePicture class, 1133, 1143, 1146
AnimatedEnvelopePicture method, 1144
AnimatedPicture class, 1133, 1139
fields, 1140
methods, 1140–1143
properties, 1140
AnimatedPicture method, 1140
AnnoyingMessage method, 206
Ansi setting, string behavior, 797–798
Ansi value, CharSet enumeration, 1256
Apartment string value, 276
apartment-threaded components, 277–278
COM, 276
callbacks from COM objects to .NET objects, 282–289
choosing states, 277–282
defined, 276
incompatibility, 291–292
MTAs (Multi-Threaded Apartments), 276–278
NAs (Neutral Apartments), 276–277
STAs (Single-Threaded Apartments), 276–277
ApartmentState property, 280–281
C#, 280–281
starting new threads, 282
Visaul Basic .NET, 281
APIs
ClrCreateManagedInstance, 468–471
CoCreateGuid, 60
GetPrivateProfileSectionNames, 789–791
Interactive Interop Tool, 1062–1064
COM+ tab, 1097–1100
compared to SDK, 1062–1063
Exporter tab, 1083–1092
Importer tab, 1069–1083
MainForm class, 1100–1101
MiscTypes.cs, 1064–1068
Register tab, 1092–1097
structure, 1063
Interop, 52
names, 499–502
.NET Visualization API, 1224
ColorfulVisualization, 1231–1235
Dancing Cat Visualization, 1235–1243
SimpleVisualization, 1224–1226
WizardVisualization, 1227–1230
SafeArrayGetVartype, 946
System.Runtime.InteropServices, versus unsafe C# code, 250–258
BookExamples.WindowsMediaPlayer assembly, 1201
IWMPEffects interface, 1199–1223
registry keys, 1197–1198
Visualization Wizard, 1198
converting data types into .NET types to define PInvoke signatures, 778–781
CopyFileEx, 810–815
customizing string behaviors, 796–799
error handling, 800–807
GetWindowsDirectory function, 784–788
MessageBeep, 810
PInvoke, 772
PlaySound, 810
ReadConsoleInput, 865–868
RegCloseKey, 856
RegDeleteKey, 860
RegEnumKey, 856
RegOpenKey, 856
SetVolumeLabel function, 783–784
AppDomain interface, exported methods, 488–489
Application object, 646
ApplicationAccessControlAttribute, 584
ApplicationActivation-Attribute, 584
ApplicationCrmEnabled-Attribute, 584
ApplicationEvents_SinkHelper class, constructor, 332
ApplicationIDAttribute, 584
ApplicationNameAttribute, 584
ApplicationQueuing-Attribute, 584
applications, .NET framework sound, 810
/appname (REGSVCS.EXE), 1394–1395
arcade games. See E-mail Attack
architecture, custom marshaling, 895–896
adapter objects, 901–909
ICustomMarshaler interface, 896–898
MarshalAsAttribute, 898–901
marshaling by value versus reference, 910–913
arrays, 154, 792–794. See also parameters
associative, 1242
conformant, 160–161
conformant varying, 161–162
custom marshaling, 943–947
customizing, MarshalAsAttribute, 549–550
exposing, 524–527
fixed-length, 157–158
frequency, 1199
nested, 518–519
parameter
method conversions, 169–171
SAFEARRAYs, 717–719
single-dimensional, 719–720
zero-bounded, 719
adding size to C-style arrays, 349–351
UnmanagedType enumeration, 550–552
type library transformations, 440–441
varying, 158–159
waveform, 1199
ArraySubType parameters, 337, 1343
ArrayWithOffset value type (System.Runtime.InteropServices namespace), 1252–1254
AskYesNoQuestion method, 1068
asmFileName,
setting to string, 1043
parameter (ConvertTypeLibToAssembly method), 1357
asmNamespace parameter, 1046, 1357
/asmversion (TLBIMP.EXE), 1377
asmVersion parameter (ConvertTypeLibToAssembly method), 1357
ASP Compatibility Mode, 279
ASP.NET
aspcompat=true directive, 280
COM components, 90–94
System.STAThreadAttribute, 279–280
aspcompat=true directive, 280
assemblies, 22. See also components; Interop Assembly
ActiveX controls, 712
adding methods to modules, 372–373
BookExamples.Windows-MediaPlayer, 1201, 1217, 1223–1224
content modifications,
324-328
changing data types, 340–342
custom attributes, 351–366, 370–372
custom marshalers, 248, 364–366
errors, 328
exposing success HRESULTs, 342–348
key option, 327
malicious edits, 327
managed resources, 326
output file names, 328
SAFEARRAYs, 348–351
unmanaged resources, 326
converting, 426
exported type library, 428
helpstrings, 427
LCID, 427
library names, 427–428
type library identification, 426–427
version numbers, 427
ConvertTypeLibTo-Assembly, 1048
creating from type libraries, 1040
dynamic assemblies, 1042–1046
GetPrimaryInteropAssembly method, 1047–1048
saving, 1048–1050
TypeLibConverter class, 1040–1042
creating type libraries, 1050
dynamic libraries, 1050–1055
saving dynamic libraries, 1055
custom attributes. See custom attributes
deployment, 532–535
disassembling/reassembling, managed resources, 326–327
dynamic
creating, 1042–1046
saving, 1048–1050
global assembly cache. See GAC
installing GAC, 392
installing in GAC, 649–650
Interop Assembly, 84–86
ActiveX control conversions, 196–198
class conversions, 179–186
creating, 85
data type conversions, 143–162
DISPIDs conversions, 173–176
enumeration conversions, 193–194
GetPrimaryInterop-Assembly method, 1047–1048
ILDASM.EXE, 653
interface conversions, 177–179
method conversions, 162–171
module conversions, 187–188
property conversions, 171–173
registering, 297
signatures, 344
structure conversions, 189–191
type library conversion, 141–143
typedef conversions, 194–196
union conversions, 191–192
KeywordAttributes, 30
ManagedForm, 923
meta data, reflection, 26–28
Microsoft.VisualBasic, 38, 356–358
mscorlib, 23, 34–35, 38, 71, 463, 522
exceptions to HRESULT transformations, 1416–1417, 1423, 1429
HRESULT, 1400, 1406–1407, 1413
Interop API, 52
MyCustomMarshalers, 365
namespaces, 23
parameter, 1060
partial binding, 91
PIAs
ActiveX controls, 712
constants, 709–710
constructs, 710
creating, 686
customizing metadata, 693–694
defining classes in IDL files, 702–707
deployment, 694–696
IDL type libraries, 697–702
names, 686–687
naming enums, 707–709
naming output assembly, 690–693
opening, 695
reasons for creating, 684–685
registering type libraries, 711
registration, 694–696
type library references, 687–689
Primary Interop, 1003
referencing, 25
REGASM.EXE, 535
HRESULTs, 393
REGASM.EXE, 391–394
RegistrationServices class, 391, 1056–1058
TypeLoadException, 392
VB6.EXE, 392
WSCRIPT.EXE, 392
signing, 24
spoofing public key token, 61
System.Web, 510
System.Windows.Forms, 50, 427, 1221
System.Xml, 34
TLBEXP.EXE, 535
type libraries. See type libraries
versioning, 527–529
Windows Registry, 80
Assembly class, 512
Assembly Registration Utility. See REGASM.EXE
Assembly to Type Library Converter. See TLBEXP.EXE
Assembly.GetExported-Types method, 1052
Assembly.Load method, 1050
Assembly.LoadFrom method, 1050
AssemblyBuilder.Save method, 1048
AssemblyKeyFileAttribute, 381
AssemblyName.tlb, 426
AssemblyQualifiedName property, 61
AssemblyRegistration-Flags enumeration (System.Runtime.InteropServices namespace), 1056–1057, 1096, 1254
AssemblyVersionAttribute, 530
associative arrays, 1242
ATL COM Wizard (C++), 725
ATL Simple Object Wizard (C++), 726
attributes
ApplicationAccess-ControlAttribute, 584
ApplicationActivation-Attribute, 584
ApplicationCrmEnabledAttribute, 584
ApplicationIDAttribute, 584
ApplicationName-Attribute, 584
ApplicationQueuing-Attribute, 584
AssemblyKeyFile-Attribute, 381
AssemblyVersion-Attribute, 530
AttributeUsageAttribute, 1223
AutoCompleteAttribute, 585
AutomationProxyAttribute, 581–582, 1254
C#, 36–38
C++, 43–45
ClassInterface(Class-InterfaceType.Auto-Dual), 435
ClassInterfaceAttribute, 556–560, 1256–1257
CoClassAttribute, 1258
COM interfaces, 963–964
ComAliasNameAttribute, 1258
ComClassAttribute, 560–565, 605–608, 613
ComConversionLoss-Attribute, 1258
ComEventInterface-Attribute, 1258–1259
ComponentAccess-ControlAttribute, 585
ComRegisterFunction-Attribute, 568, 1261
ComSourceInterfaces-Attribute, 598–605, 611, 631, 1261
COMTIIntrinsics-Attribute, 585
ComUnregisterFunction-Attribute, 568, 1262
ComVisibleAttribute, 562–565, 1262–1263
ConstructionEnabled-Attribute, 585
controlling apartments that .NET components reside on, 278–280
creating, 29–30
custom marshalers. See custom marshaling
customizing structures, 829–839
DescriptionAttribute, 359, 585
DispIdAttribute, 574–578, 601, 651, 1265–1266
EventClassAttribute, 585
EventTrackingEnabledAttribute, 585
ExampleAttribute, 354
ExceptionClassAttribute, 585
exported type libraries, 428
GetCustomAttributes, 1220
GuidAttribute, 331, 427, 574, 1278
helpstring, 358–363
IDispatchImplAttribute, 660–661, 1282
IDL, 371–372
IISIntrinsicsAttribute, 585
ILASM.EXE, 351–356
ImportedFromTypeLib-Attribute, 331, 1284
InterfaceQueuing-Attribute, 585
InterfaceTypeAttribute, 578–579, 601, 1285
JustInTimeActivation-Attribute, 585
KeywordAttribute, 509
LCIDConversion, 583
LCIDConversionAttribute, 582, 1290–1291
LoadBalancingSupportedAttribute, 585
Microsoft.VisualBasic.CompilerServices.StandardModule-Attribute, 356
MustRunInClient-ContextAttribute, 585
ObjectPooling-Attribute, 585
PresetEnumAttribute, 1220–1223
PrimaryInterop-AssemblyAttribute, 1348
PrivateComponent-Attribute, 585
pseudo, 33
reflection, 31–33
RestrictedAttribute, 508–509
SecureMethodAttribute, 585
SecurityPermission-Attribute, 305
SecurityRoleAttribute, 585
STAThreadAttribute, 1100
SuppressUnmanaged-CodeSecurityAttribute, 308
Synchronization-Attribute, 276, 586
System.EnterpriseServices, 584–586
System.FlagsAttribute, 1022
System.MTAThread-Attribute, 278
System.Reflection.-AssemblyDescriptionAttribute, 1067
System.Runtime.CompilerServices.MethodImplAttribute, 276
System.Runtime.InteropServices namespace, 1250
System.Security.SuppressUnmanagedCodeSecurityAttribute, 308
System.STAThread-Attribute, 278–280
TransactionAttribute, 586
TypeLibFuncAttribute, 1358
TypeLibTypeAttribute, 1359
TypeLibVarAttribute, 1359
usage guidelines, 508–510
VB .NET modules, 356–358
Visual Basic .NET, 40–42
pseudo-custom
DllImportAttribute, 772, 776–777, 795, 863, 865, 1266–1267
FieldOffsetAttribute, 832–833, 1271–1272
InAttribute, 438, 553–554, 792–794, 1284–1285
MarshalAsAttribute, 334–340, 541–553, 651, 834–839, 898–901, 1222, 1342–1344
OptionalAttribute, 583–584, 1345–1346
OutAttribute, 438, 553–554, 786, 792–794, 1346–1347
PreserveSigAttribute, 436, 579, 1347–1348
StructLayoutAttribute, 270, 554–556, 829–832, 839–844, 1354
AttributeUsageAttribute, 1223
AttributeUsageAttribute class, 30
audioTitle field, 1217
Auto setting, string behavior, 797–798
Auto value
CharSet enumeration, 1256
LayoutKind enumeration, 1290
auto-dispatch class interface, 398
auto-dual class interface, 398
AutoCompleteAttribute, 585
AutoDispatch value, ClassInterfaceType enumeration, 1257
AutoDual value, ClassInterfaceType enumeration, 1257
AutomationProxyAttribute (System.Runtime.InteropServices namespace), 581–582, 1254
AxCoClassName class, 236
AxCoClassNameEvent-Multicaster class, 236
AXIMP.EXE, 324, 712, 1252, 1390–1391
/?, 1393
/delaysign, 1391
/help, 1393
/keycontainer, 1391
/keyfile, 1392
/nologo, 1393
/out, 1392
/publickey, 1392
/silent, 1393
/source, 1393
/verbose, 1393
syntax, 1390
AxImporter class, 1252
AxWebBrowser class, 239
AxWebBrowserEvent-Multicaster class, 240
back buffer surfaces, 1118
background field, 1150
balloon effect, manually defining COM types, 1033–1036
basic string. See BSTR
bi-directional communication, 202
binary compatibility
Visual Basic 6, 294–295
components, 628–633
instancing, 633–634
binding
late, 91
COM components, 119–120
.NET members, 119
unmanaged C++, 404–407
partial, 91
BINDPTR value type (System.Runtime.InteropServices namespace), 1255
BindToMoniker method (Marshal class), 1296
BIND_OPTS value type (System.Runtime.InteropServices namespace), 1255
BitConverter.ToString method, 946
blittable data types, 98
blittable value types, 792
BonusPicture field, 1120
BookExamples.WindowsMediaPlayer assembly, 1201,1217, 1223–1224
Boolean parameters, MarshalAsAttribute, 1343
Both string value, 276
Both threading model, 733
BSTR (basic string), 149–150, 249
by-reference null value types (IntPtr type), manipulating, 264–265
by-reference parameters, 119–120, 518
ILASM.EXE, 334
method conversions, 164–167
.NET method transformations, 436–438
by-value parameters
method conversions, 164–167
.NET method transformations, 436–438
ByValArray
UnamangedType enumeration values, 549
value, 834
ByValTStr value, 834
/c (REGSVCS.EXE), 1395
C#, 34
ApartmentState property, 280–281
callback functionality
using delegates, 205–206
using events, 210–211
calling GetObjectAttribute method, 260
clients, assembly modifications, 345–348
coclass IDL representation of .NET classes, 450–452
COM View and .NET View
of an event, 446
of fields exported as properties, 444
of methods with parameter arrays, 441
of properties, 442
ComImport-marked class, 1026
compiler, 1006
custom attributes, 29–30, 36–38
custom marshalers, converting Stream to IStream, 901–905
defining IWMPEffects Interface, 971, 973
definition of IMarshal, 672–673
definition of IRunningAppCollection, 976–979
definitions
addImport and addRule parameters, 994
C# IHTMLStyleSheet interface, 1035–1036
IHTMLStyleSheet interface, 996–998
IPersist and IPersistStream Interfaces, 985–987, 1000–1001
NetMeeting Coclass interface, 1009, 1016–1018
enumerations and parameters, and the IDL representation of exported types, 454, 457
explicit interface implementation, 656
exposing .NET events as COM connection points, 592–593
Form1.cs. Using Microsoft Word Spell Checking listing, 128–130, 133–137
fully qualified names, 61–62
Hello, World, 36
ICustomMarshaler interface, 896
IDictionary interface, 746
ITypeLibImporterNotifySink interface methods, 1044, 1051
keywords corresponding to System namespace, 35
manual SAFEARRAY marshaling, 273–275
manual variant marshaling, 267, 270–272
marking array parameters with InAttribute and OutAttribute, 792–794
MyWebBrowser.cs. Using the WebBrowser ActiveX Control in C# listing, 123, 126
Non-Static Extern Members feature, 1029–1031
raw connections points, 219–222
reflection, 26–28
Register for COM Interop option, 534
RegistrationHelper class methods, 1059
signatures, MarshalAsAttribute, 899–901
StringValidator class, 380–381
syntax for imported C-style array fields, 262
System.Runtime.Interop-Services.UCOMIConnection Point syntax, 676–676, 684
System.STAThreadAttribute, 279
translation of IWMPEffects, 965–966, 1002
TypeLibConverter class, 1040, 1050
unsafe code, 849–852
unsafe code versus System.Runtime.Interop-Services APIs, 250–254
obtaining value type addresses, 254–255
obtaining value type sizes, 255–258
using construct, 1218–1220
using statement, 35
writing COM-creatable classes and non-COM-creatable classes, 514
C++
definition of ISupportErrorInfo, 674
ItypeLibImporterNotifySink interface methods, 1044, 1052
late binding, 404–407
RegistrationHelper class methods, 1059
RegistrationServices class methods, 1056
StringValidator class, 385–388
TypeLibConverter class, 1041, 1050
C-style array fields (IntPtr type), manipulating, 262
imported C# syntax, 262
imported Visual Basic .NET syntax, 262–264
C-style arrays, adding size to, 349–351
caches, GAC (global assembly cache), 24–25
callbacks
exceptions, 286
to .NET objects, 282–289
.NET, 202
delegates, 204–208
events, 208–214
interfaces, 202–204
Win32 functions, 810–811
delegates as function pointers, 811–817
invoking unmanaged pointers in managed code, 818–821
CALLCONV enumeration, 1255
CallerId
event, 592–593
method, 596
CallerIdEventArgs class, 610
CallerIdEventHandler class, 596
calling
GetObjectAttribute method, 260
members, .NET objects, 400–403
methods, COM objects, 101–109
properties, COM objects, 101–109
CallingConvention (PInvoke), 799–800
enumeration, 1255–1256
parameter, DllImportAttribute, 1266
camel casing, 503
Capabilities property, 1220
casing, type libraries, 489–492
casting
QueryInterface, 110–112
to RCW types, 295–297
categories, COM components, 569
CCWs (COM-Callable Wrapper), 69, 71, 394
class interfaces, 397–399
custom marshaling, 880–882
adapter objects, 904–905
deterministic release of resources, 947–952
exposing Stream as IStream, 932–943
Cdecl value, CallingConvention enumeration, 1255
CFileWriter class, 750–759
ChangeFontButton_Click method, 923
ChangeWrapperHandle-Strength method (Marshal class), 1296–1297
channelCount field, 1217
Character class, 1133
fields, 1157
private fields, 1158
Character method, 1158
CharSet enumeration, 1256
CharSet parameter
DllImportAttribute, 1266
StructLayoutAttribute, 830
ChatRoomDisplay interface, 204
ChatRoomServer class, 215
CheckForDeath method, 1121, 1133
class interfaces, 741–743
ClassInterfaceAttribute, 556–560
classes. See also coclasses
AnimatedEnvelopePicture, 1133, 1143–1146
fields, 1140
methods, 1140–1143
properties, 1140
ApplicationEvents_SinkHelper, 332
Assembly, 512
AttributeUsageAttribute, 30
AxCoClassName, 236
AxCoClassNameEvent-Multicaster, 236
AxImporter, 1252
AxWebBrowser, 239
AxWebBrowserEvent-Multicaster, 240
CallerIdEventArgs, 610
CallerIdEventHandler, 596
CFileWriter, 750–759
Character, 1133
fields, 1157
private fields, 1158
ChatRoomServer, 215
ClassVisibleToAll, 479
Client, 853
COM, 54
converting, 179–186
manually defining, 1022–1036
COM-creatable, writing in C#, 514
ComPlusInstaller, 1097–1100
ComVisibleForm, 479
ConsoleDisplay, 204
CorRuntimeHost, 468
creating instances
CreateObject method, 99–101
error detection, 101
new operator, 99
CustomCCW
exposing Stream as IStream, 932–943
MarshalManagedTo-Native, 948–952
CustomRCW, exposing IStream and Stream, 923–932
defining in IDL files, 702–703
default interfaces, 704–707
source interfaces, 703–704
DevTagRecognizer, 635, 643–644
DINPUT8STRING-CONSTANTS, 356
Display, 206
EmailAttackForm, 1166–1171
Envelope, 1162
public fields, 1162
Environment, 1171
EventNameEventArgs, 609
Exporter, 1083–1084, 1086–1092
formatted, customizing classes, 839–844
FrontLayer methods, 1154
Game, 1111, 1119–1121, 1131–1133, 1154, 1166
private fields, 1121
properties, 1121
public fields, 1120
GroundLayer methods, 1153
IDL coclass representation, 450–453
Importer, 1069–1083
INetMeetingEventsEventProvider, 1017
inheritance, COM, 311–315
IntroScreen, 1156–1157
Kernel32, 1167
fields, 1150
methods, 1150–1152
LoadTypeLibEx, 1066
MainForm, 1100–1101
ManagedIStream, 889–895
Marshal, 250, 263, 270, 306, 1067
MarshalGetObjectFor-NativeVariant method, 272
members, private, 653
Microsoft.Win32.Registry, 644
Monitor, 275
MustInherit, 506
Mutex, 275
methods, 1147–1150
private fields, 1147
Object, interface, 439–440
OwnerWindow, 1221
event handlers, 597
exposing .NET events to COM with CLR, 602–605
exposing .NET events to COM without CLR, 594, 596–597
Picture, 1133–1134
methods, 1136–1139
properties, 1136
RCW, converting, 182
Register, 1093–1097
Registrar, 1096
registration, REGASM.EXE, 568
RegistrationHelper, 1059, 1252
InstallationFlags enumeration, 1060–1061
methods, 1060
C#, 1059
C++, 1059
Visual Basic .NET, 1059
RegistrationServices, 391, 1097, 1056–1058
RegistryKey, 853, 856, 859–860
RegistryKeyEnumerator, 853, 856
RingEventHandler, 596
Sound, 1133–1136
SourceInterfaceName_MethodNameEvent, 236
Stack, late binding, 404
Stream, 889–895
StringValidator, 381
C#, 380–381
JScript, 388–390
Visual Basic 6, 382–384
StructLayoutAttribute, 433
System.Activator, 99
System.Collections.Stack, InvalidOperation-Exception, 403
System.ComponentModel, 620
System.Console, 868
System.Drawing.Font, custom marshaling, 910, 912
System.EnterpriseServices.ServicedComponent, 283, 507
System.EventArgs, 608
System.IDisposable, 69
System.IO.Stream, methods, 883–889
System.MarshalByRef-Object, 295, 507
System.Runtime.Interop-Services, 620
System.Runtime.Interop-Services namespace
CurrencyWrapper, 1263–1264
DispatchWrapper, 1264–1265
ErrorWrapper, 1267–1268
ExtensibleClassFactory, 1269–1271
Marshal, 1292–1342
RegistrationServices, 1349–1351
RuntimeEnvironment, 1351–1352
TypeLibConverter, 1356–1357
UnknownWrapper, 1366–1367
System.Runtime.InteropServices.CustomMarshalers namespace
EnumerableToDispatchMarshaler, 1370
EnumeratorToEnum-VariantMarshaler, 1371
ExpandoToDispatchExMarshaler, 1371–1372
TypeToTypeInfo-Marshaler, 1372
System.Runtime.Interop-Services.Marshal, 307, 501, 845
System.Text.Regular-Expressions.Regex, 396
System.Threading.ManualResetEvent, 286
System.Web.Services.WebService, 507
System.Web.UI.Page, 507
System.Windows.Forms.Form, 479, 507, 1221
System.Windows.Forms.MainMenu, 507
TAPI, methods, 227–229
type library transformations, 449–451
creating assemblies from type libraries, 1040–1048
creating type libraries from assemblies, 1050–1055
generating type libraries, 395
ResolveRef method, 1045
UnicodeEncoding, 946
UnmanagedType.LPArray, 337
UnmanagedType.Safe-Array, 337
usage guidelines, versus interfaces, 506–508
public fields, 1112
VB .NET modules, 356–358
Visualization, 1208–1223, 1229
_INetMeetingEvents_EventProvider, 1008
_INetMeetingEvents_SinkHelper, 1008
ClassInterface(ClassInterfaceType.AutoDual), 435
ClassInterfaceAttribute (System.Runtime.InteropServices namespace), 1256–1257
ClassInterfaceType enumeration, 556–560
ClassInterfaceType enumeration, 556–560, 1257
ClassVisibleToAll class, 479
CleanUpManagedData method (ICustomMarshaler interface), 897, 1282
CleanUpNativeData method (ICustomMarshaler interface), 897, 1281
Client class, 853
clients
defining exception types, COM, 520–522
.NET Framework
designing COM components for, 716–728
designing COM members for, 729–731
designing COM objects for, 731–738
versioning
COM, 528–529
.NET, 527–529
ClippedRectangle method, 1136, 1139
Closing event, 622–623
CLR (Common Language Runtime), 15
COM Interoperability. See COM Interoperability
core services, 52
exception object properties, 722
exposing COM connection points with, 598
ComClassAttribute, 605–608
ComSourceInterfaces-Attribute, 598–600
defining source interfaces, 600–605
design guidelines, 608–611
Phone class, 602–605
Windows Forms, 611–614, 620–625
hosting, 460–468
IDispatch implementation, 659–660
compatible, 660–665
internal, 660–665
IManagedObject, 658
IUnknown implementation, 657
JIT (just-in-time compiler), 21
managed code, 48
releasing COM objects, 109–110
unmanaged code, 48
versioning, 19
ClrCreateManagedInstance API, 468–471
CLS (Common Language Specification), 16, 868–870
CLSIDs
creating COM components in ASP.NET pages, 91
versioning, 530–531
COAUTHINFO structure, 873
CoClassAttribute (System.Runtime.InteropServices namespace), 1258
coclasses. See also classes
converting, 180–182
CorRuntimeHost, 460–461
HTMLDocument, 234
HTMLStyleSheet, 1023
interfaces, manually defining, 1003–1009, 1016- 1019
InternetExplorer, 218–222, 231
MultiPurposeObject, 705
NetMeeting, 1007
type library transformations of classes, 449–451
CoCreateGuid API, 60
CoCreateInstanceEx, activating remote COM objects, 871–874
code
luring attacks, 306
managed, 48
adapter objects, 905–909
connection points, 218–235
debugging COM Interoperability calls to unmanaged code, 315–319
interaction with unmanaged code, 49–53, 69–71
invoking unmanaged pointers in, 818–821
Registry, adding, 567–569
adapter objects, 905–909
debugging COM Interoperability calls from managed code, 315–319
goals for interaction, 48–49
interaction with managed code, 49–53, 69–71
late binding, 404–407
reflection, 482–488
unmanaged StringValidator class
JScript, 388–390
unsafe (C#), 849–852
code-access security, 21
/codebase (REGASM.EXE), 393–394, 1386
CoEEShutDownCOM, 492
collections
COM enumerations, 114
exposing, 524–527
COM
classes, 54
converting, 179–186
creating instances, 99–101
inheritance, 311–315
manually defining, 1022–1036
writing in C#, 514
clients, 53
defining exception types, 520–522
returned error codes/messages, 403–407
collections, enumerations, 114
compared to .NET Framework, 55–57
component locations, 62–64
component names, 59–62
error handling, 66–68
object lifetimes, 68–69
programming model, 57–58
type compatibility, 64
type information, 58–59
type safety, 66
versioning, 64–66
components
apartment-threaded, 277–278
ASP.NET, 90–94
Both threading model, 733
categories, 569
connection points, 202, 214–235
debugging into, 315–319
designing for .NET clients, 716–728
free-threaded, 277
late binding, 119–120
library names, 142
locations, 62–64
migration to .NET, 684–685
neutral, 277
referencing in Visual Studio .NET, 78–84
referencing with SDK, 81–84
registration, 460–471
sliced interfaces, 743–747
Windows Registry, 62
core interoperability tools. See TLBIMP.EXE; TLBEXP.EXE; REGASM.EXE
data types
BSTR, 149–150
converting, 143–162
converting .NET data types into, 429, 432–433
CURRENCY, 148–149
DECIMAL, 148–149
HRESULT, 150–151
LPSTR, 149–150
LPWSTR, 149–150
SCODE, 150–151
Variant, 146–147
DCOM. See DCOM
definitions, manually defining, 958–959
deploying .NET applications, 126–137
enumerations, converting, 193–194
enums, manually defining, 1022
event sinks, 623–625
exposing enumerators to, 524–527
exposing events as connection points
Windows Forms, 611–614, 620–625
with CLR, 598–611
without CLR, 592–597
extended interoperability tools. See AXIMP.EXE; REGSVCS.EXE
fonts, custom marshaling, 914–923
interfaces, 57–58, 506–508, 628
converting .NET interfaces to, 447–449
custom attributes, 963–964
customizations, 998–1003
default implementations, 657–677
definitions, 628–629
dual, 58
dual interfaces, 975–981
error handling, 112–114
explicit interface members, 655–656
HRESULTs, 656
IAmVisibleToAll, 479
IAssemblyCache, 1040
IConnectionPointContainer, 675–676
ICorRuntimeHost, 460
ICreateErrorInfo, 727–728
IDebuggerInfo, 461
IDispatch, 54–55, 58, 146–147, 654, 659–672
IDispatchEx, 152–153
IEnumVARIANT, 152–153
IGCHost, 460
IMarshal, 672–673
Implement Interface, option, 651–652
implementation, 112–114
IObjectSafety, 676–677
IPersist, 654–656
IPersistStream, 654–656
IPhoneEventHookup, 596
IPhoneEvents, 596–597
IProvideClassInfo, 296, 673–674, 705–706, 734
IRecordInfo, 271
ISmartTagAction, 635–636, 643–646, 654
ISmartTagRecognizer, 635–636, 643–646, 654
ISupportErrorInfo, 674, 725–726
IUnknown, 54, 57, 68, 70, 146–147, 654, 657–659
IUnknown-Only interfaces, 964–974
IValidator, 461
language limitations, 988–995, 998
manually defining, 962–963
method signatures, 652
MultiPurposeObject, 705
names, 500
non-public, 967
Office XP smart tags, 634–636, 643–650, 653–656
parameterized properties, 653–654
private members, 653
selecting members, 651
SetErrorInfo, 728
versioning, 65–66
Visual Studio .NET shortcuts, 650–653
invisibility, 477–482, 562–565
members
converting for .NET object models, 434–447
designing for .NET clients, 729–731
modules, converting, 187–188
names, 59–62
.NET types, 678–679
objects, 53
activating with CoCreateInstanceEx, 871–874
calling methods, 101–109
calling properties, 101–109
designing for .NET clients, 731–738
IProvideClassInfo interface, 734
Marshal.ReleaseCom-Object, 299–304
passing, 115–118
releasing, 109–110
visualizations, 572
objects created in source code, Activator.CreateInstance method, 91
optional parameters, 104–105
overview, 53–55
structures
converting, 189–191
manually defining, 1019–1022
testing components from, 535–536
threading, 275
apartment states, 277–282
apartment types, 276–277
callbacks to .NET objects, 282–289
HKEY_CLASSES_ROOTCLSID{CLSID}InProcServer32 string values, 276–277
incompatible apartments, 291–292
type systems, 64
typedefs, converting, 194–196
unions, converting, 191–192
utilities, 55–56
Visual Basic 6, 57
visualizations, 1196–1197
COM Interoperability, 51–53, 69–71
debugging calls from managed code into unmanaged code, 315–319
goals, 53
GUIDs, 529
performance monitoring, 320–321
versioning, 528–529
COM+
components, 96
objects, 309–311
exposing .NET objects as, 584–586
installing in Component Services explorer, 309
COM+ Catalog, installation, 1059–1061
COM+ tab (Interactive Interop Tool), 1097–1100
COM-Callable Wrapper. See CCW
COM-compatible components. See binary-compatible components
ComAliasNameAttribute (System.Runtime.InteropServices namespace), 1258
ComClassAttribute, 560–562, 613
ComConversionLoss-Attribute (System.Runtime.InteropServices namespace), 1258
ComEventInterface-Attribute (System.Runtime.InteropServices namespace), 1258–1259
COMException, 728 (System.Runtime.InteropServices namespace), 1259–1260
ComFriendlyForm class, 611, 621, 623
ComImport-marked class, C#, 1026
ComImportAttribute (System.Runtime.InteropServices namespace), 298, 1260
COM interface implementations, 658
custom attribute, 963
ComInterfaceType enumeration, 578–579, 1260
commands
CLS (clearing Console screen), 868–870
Project menu, Add Reference, 25
ComMemberType enumeration, 1261
Common Language Runtime. See CLR
Common Language Specification. See CLS
communication, bi-directional, 202
_ComObject, 71, 104, 229–232, 295–298, 422, 696, 734–735
compatibility, Visual Basic .NET, 38
compatible IDispatch CLR implementation, 660–665
compiler, C#, 1006
compilers, managed, 15
ComPlusInstaller class, 1097–1100
Component parameter, 508
Component Services explorer, installing COM+ objects, 309
ComponentAccessControlAttribute, 585
components. See also assemblies
binary-compatible, 628–634
COM
apartment-threaded, 277–278
ASP.NET, 90–94
Both threading model, 733
categories, 569
connection points, 202, 214–235
debugging into, 315–319
free-threaded, 277
library names, 142
migration to .NET, 684–685
neutral, 277
referencing in Visual Studio .NET, 78–84
referencing with SDK, 81–84
registration, 460–471
sliced interfaces, 743–747
Windows Registry, 62
COM+, 96
designing for .NET clients, 716–717
array parmeters, 717–719
error reporting, 720–728
VARIANT parameters, 720
locations
.NET Framework, 62–64
COM, 62–64
names, COM compared to .NET Framework, 59–62
.NET Framework, 380
C# StringValidator class, 380–381
C++ StringValidator class, 385–388
DirectX, 1106
JScript StringValidator class, 388–390
Visual Basic 6 StringValidator class, 382–384
side-by-side, 18–19
testing from COM, 535–536
version policies, 19
versioning, 527–529
/componly (REGSVCS.EXE), 1395
ComptibleImpl value, IDispatchImplType enumeration, 1283
ComRegisterFunction--Attribute (System.Runtime.InteropServices namespace), 568, 1261
ComSourceInterfaces-Attribute (System.Runtime.InteropServices namespace), 598–600, 611, 631, 1261
defining source interfaces, 600–605
COMTIIntrinsicsAttribute, 585
ComUnregisterFunction-Attribute (System.Runtime.InteropServices namespace), 568, 1262
ComVisibleAttribute (System.Runtime.InteropServices namespace), 562–565, 1262–1263
ComVisibleForm class, 479
concurrency, .NET Framework, 275
Configure value, 1061
ConfigureComponents-Only value, 1061
conformant arrays, 160–161
conformant varying arrays, 161–162
ConformantArray1D method, 161
connectable objects, 229–235
CONNECTDATA value type (System.Runtime.InteropServices namespace), 1263
connection points, COM components, 202, 214–217
connectable objects, 229–235
event handling, 219–222
lazy connection point initialization, 227–229
managed code, 218–222
type library importer transformations, 222–227, 235–240
Console
clearing screen, 868–870
input, responding to immediately, 865–868
ConsoleDisplay class, 204
ConsoleMessage method, 206
constants, 709–710
ConstructionEnabled-Attribute, 585
constructors
adding to RCW class, 182
usage guidelines, 513–514
constructs, 710
containers, ActiveX hosting Windows Forms controls in, 471–477
Control property, 621
controls
ActiveX, 120–121
converting, 196–198
referencing in Visual Studio .NET, 121–122
referencing with .NET Framework SDK, 122–123
TreeView, 624
WebBrowser, 236
referencing ActiveX controls, 123, 126
Windows Forms, hosting in ActiveX containers, 471–477
ConvertAssemblyToType-Lib method (TypeLibConverter class), 1356
C#, 1050
C++, 1050
converting
assemblies, 426
exported type library, 428
helpstrings, 427
LCID, 427
library names, 427–428
type library identification, 426–427
version numbers, 427
classes, 449–451
COM members for .NET object models, 434
.NET events, 446–447
.NET fields, 444–446
.NET methods, 434–441
.NET properties, 441–444
.NET interfaces to COM interfaces, 447–449
value types, 452–453
ConvertTypeLibToAssembly assembly, 1048
ConvertTypeLibToAssembly method (TypeLibConverter class), 1041–1042, 1356–1357
creating assemblies from type libraries 1042-1044
parameters, 1357
Copy method, Marshal class, 1297–1298
CopyFileEx API, callbacks, 810–815
CorExitProcess, 492–493
CorRuntimeHost class, 468
CorRuntimeHost coclass, 460–461
Counter field, 1112
CreateInstance method, 468
CreateObject method, creating instances, 60, 99–101
CreateRemoteInstance method, 874
CreateSink method, 239
CreateSoundBufferFromFile method, 1112
CreateSurfaceFromFile method, 1112, 1118
CreateTargetApplication value, 1061
CreateTypeInfo method, 1068
CreateWrapperOfType, 298–299, 1298–1299
creating. See writing
CURRENCY data type, 148–149
CurrencyWrapper, 115, 119, 1263–1264
CurrentAudioTitle property, 1220
CurrentChannelCount property, 1220
CurrentPreset property, 1217, 1229
CurrentSampleRate property, 1220
ApplicationAccessControlAttribute, 584
ApplicationActivation-Attribute, 584
ApplicationCrmEnabled-Attribute, 584
ApplicationIDAttribute, 584
ApplicationNameAttribute, 584
ApplicationQueuing-Attribute, 584
AssemblyKeyFileAttribute, 381
AssemblyVersionAttribute, 530
AttributeUsageAttribute, 1223
AutoCompleteAttribute, 585
AutomationProxyAttribute, 581–582
C#, 36–38
C++, 43–45
ClassInterface(Class-InterfaceType.AutoDual), 435
ClassInterfaceAttribute, 556–560
COM interfaces, 963–964
ComImportAttribute, 963
GuidAttribute, 963
InterfaceTypeAttribute, 964
ComClassAttribute, 560–562, 605–608, 613
ComponentAccessControlAttribute, 585
ComRegisterFunction-Attribute, 568
ComSourceInterfaces-Attribute, 598–605, 611, 631
COMTIIntrinsicsAttribute, 585
ComUnregisterFunction-Attribute, 568
ComVisibleAttribute, 562–565
ConstructionEnabled-Attribute, 585
controlling apartments that .NET components reside on, 278–280
creating, 29–30
custom marshalers, 364–366
customizing structures, 829
FieldOffsetAttribute, 832–833
MarshalAsAttribute, 834–839
StructLayoutAttribute, 829–832, 839–844
DescriptionAttribute, 359, 585
DispIdAttribute, 574–578, 601, 651
EventClassAttribute, 585
EventTrackingEnabled-Attribute, 585
ExampleAttribute, 354
ExceptionClassAttribute, 585
exported type libraries, 428
FieldOffsetAttribute, customizing structures, 832–833
GetCustomAttributes, 1220
helpstring, 358–363
IDispatchImplAttribute, IDispatch implementation, 660–661
IDL, 371–372
IISIntrinsicsAttribute, 585
ILASM.EXE, 351–356
ImportedFromTypeLib-Attribute, 331
InAttribute
customizing data flow, 553–554
export behavior, 438
marking array paraetmers, 792–794
InterfaceQueuingAttribute, 585
InterfaceTypeAttribute, 578–579, 601
JustInTimeActivation-Attribute, 585
KeywordAttribute, 509
LayoutKind enumeration, 829–830
LCIDConversion, 582–583
LoadBalancingSupported-Attribute, 585
MarshalAsAttribute, 895, 898, 1222
C# signatures, 899–901
COM interface shortcuts, 651
customizing arrays, 549–550
customizing data types, 541–549, 552–553
customizing structures, 834–839
detecting errors in, 552–553
Inherited property, 546
parameters, 898–900
syntax, 334–340
UnmanagedType enumeration, 542–545, 549–552
UnmanageType values, 834
Microsoft.VisualBasic.CompilerServices.StandardModuleAttribute, 356
MustRunInClientContext-Attribute, 585
ObjectPoolingAttribute, 585
OptionalAttribute, 583–584
OutAttribute, 786
customizing data flow, 553–554
export behavior, 438
marking array parameters, 792–794
parameters, 830
PreserveSigAttribute, 436, 579
PresetEnumAttribute, 1220–1223
PrivateComponentAttribute, 585
ProgIdAttribute, customizing registration, 566
pseudo, 33
reflection, 31–33
RestrictedAttribute, 508–509
SecureMethodAttribute, 585
SecurityPermissionAttribute, 305
SecurityRoleAttribute, 585
STAThreadAttribute, 1100
StructLayoutAttribute, 270
customizing structure layout, 554–556
customizing structures, 829–832
LayoutKind enumeration, 554
SuppressUnmanagedCodeSecurityAttribute, 308
SynchronizationAttribute, 276, 586
System.EnterpriseServices namespace, 584–586
System.FlagsAttribute, 1022
System.MTAThread-Attribute, 278
System.Reflection.|AssemblyDescription-Attribute, 1067
System.Runtime.CompilerServices.MethodImpl-Attribute, 276
System.Runtime.InteropServices namespace, 1250
AutomationProxy-Attribute, 1254
ClassInterfaceAttribute, 1256–1257
CoClassAttribute, 1258
ComAliasNameAttribute, 1258
ComConversionLoss-Attribute, 1258
ComEventInterface-Attribute, 1258–1259
ComRegisterFunction-Attribute, 1261
ComSourceInterfaces-Attribute, 1261
ComUnregisterFunctionAttribute, 1262
ComVisibleAttribute, 1262–1263
DispIdAttribute, 1265–1266
GuidAttribute, 1278
IDispatchImplAttribute, 1282
ImportedFromTypeLib-Attribute, 1284
InterfaceTypeAttribute, 1285
LCIDConversion-Attribute, 1290–1291
PrimaryInterop-AssemblyAttribute, 1348
ProgIdAttribute, 1349
TypeLibFuncAttribute, 1358
TypeLibTypeAttribute, 1359
TypeLibVarAttribute, 1359
System.Security.Suppress-UnmanagedCodeSecurityAttribute, 308
System.STAThreadAttribute, 278
in ASP.NET, 279–280
in C#, 279
TransactionAttribute, 586
usage guidelines versus interfaces, 508–510
VB .NET modules, 356–358
Visual Basic .NET, 40–42
custom marshalers, 248, 364–366, 880, 895–896
adapter objects, 901–903, 905–909
ICustomAdapter interface implementation, 909
marshaling by value versus reference, 910–913
arrays, 943–947
by value, 914
FontMarshaler class, 914–918
.NET Windows Form consumer, 918–920
Visual Basic 6 .NET form, 921–923
CCWs, 880–882
adapter objects, 904–905
deterministic release of resources, 947–952
exposing Stream as IStream, 932–943
data type transformations without, 882–883
ComStream adapter class exposing IStream implementation as .NET streams, 883–889
ManagedIStream class exposing Stream objects through IStream implementation, 889–895
.NET definition of UCOMIStream in C#, 883, 888
deterministic release of resources, 947–952
FontMarshaler class, 365
ICustomMarshaler interface, 896–898
Interop Marshaler without marshaling, 880
limitations, 952–953
MarshalAsAttribute, 895, 898–901
marshaling between .NET and COM fonts, 914
FontMarshaler class, 914–918
.NET Windows Form consumer, 918–920
Visual Basic 6 .NET form, 921–923
marshaling between System.IO.Stream and IStream, 923–943
.NET class implementation, 909
RCWs, 880–882
adapter objects, 904–906
exposing IStream and Stream, 923–932
System.Runtime.Interop-Services, 1252
CustomCCW class
exposing Stream as IStream, 932–943
MarshalManagedToNative, 948–952
customizing
arrays, MarshalAsAttribute, 549–550
C# definitions of IPersist and IPersistStream Interfaces, 986–987
COM interfaces, 998–1003
data flow, 553
InAttribute, 553–554
OutAttribute, 553–554
PIAs, 693–694
registration, 566
adding arbitrary registration code, 567–569
custom registration functions, 570–574
ProgIdAttribute, 566
System.Guid.ToString, 570
unregistration functions, 569–570
structure layout, 554–556
structures, 829
FieldOffsetAttribute, 832–833
formatted classes, 839–844
MarshalAsAttribute, 834–839
StructLayoutAttribute, 829–832
structure inspection, 844–847
translation of IWMPEffects to C#, 967
CustomRCW class, exposing IStream and Stream, 923–932
Dancing Cat visualization, 1235–1243
data flow, customizing, 553
InAttribute, 553–554
OutAttribute, 553–554
data types. See also types
blittable, 98
COM
BSTR, 149–150
converting, 143–162
converting into .NET, 429, 432–433
CURRENCY, 148–149
DECIMAL, 148–149
HRESULT, 150–151
LPSTR, 149–150
LPWSTR, 149–150
SCODE, 150–151
converting, 143–144, 429, 432–433
arrays, 433
combining types, 145–151
complex types, 152–162
custom marshaling, 895–896
adapter objects, 901–909
arrays, 943–947
deterministic release of resources, 947- 952
ICustomMarshaler interface, 896–898
limitations, 952–953
MarshalAsAttribute, 895, 898–901
marshaling between .NET and COM fonts, 914–923
marshaling between System.IO.Stream and IStream, 923–943
marshaling by value versus reference, 910–913
.NET class implementations, 909
by value, 914–923
System.IntPtr, 248–250
transformations without custom marshaling, 882–883
ComStream adapter class, 883–889
ManagedIStream class, 889–895
NET definition of UCOMIStream in C#, 883, 888
usage guidelines, 516
nested arrays, 518–519
OLE Automation, 516–518
pointers, 518
user-defined value types, 519
Variant, 146–147
Win32, 778–781
DCOM (distributed COM) objects, 54, 309–311
creating remote objects, 309–310
.NET remoting, 310
Type.GetTypeFromCLSID method, 309
Type.GetTypeFromProgID method, 309
debugging, into COM components, 315–319
DECIMAL data type, 148–149
Declare statement
customizing, 795
PInvoke, 773–775
Declare statement (PInvoke)
changing string behavior, 797–799
function names, 796
DeclaredOnly flag, 1220
default COM interface implementations, 657
IDispatch, 659–665
IUnknown, 657–659
default interfaces, defining classes in IDL files, 704–707
default values, 1061
language limitations of COM interfaces, 994–995, 998
definitions (.NET), 628
C#
addImport and addRule parameters, 994
C# IHTMLStyleSheet interface, 1035–1036
IHTMLStyleSheet interface, 996–998
IPersist and IPersistStream Interfaces, 985–987, 1000–1001
IRunningAppCollection, 976–979
NetMeeting Coclass interface, 1009, 1016–1018
COM
interfaces, 628–629
manually defining, 958–959
HTML Object Library, 1003
IDL
IHTMLStyleSheet interface, 988–989
INetMeetingEvents dispinterface and INetMeeting interface, 1007–1008
IPersist and IPersistStream Interfaces, 985
IRunningAppCollection, 975–976
IWMPEffects interface, 964
.NET Framework, 1021
VB .NET
addImport and addRule parameters, 994
DispHTMLStyleSheet interface and the HTMLStyleSheet coclass interface, 1004–1006
IHTMLStyleSheet interface, 991
IRunningAppCollection, 980–981
/delaysign (AXIMP.EXE), 1391
/delaysign (TLBIMP.EXE), 1377
delegates
as function pointers, 811–812
CopyFileEx, 812–815
SetConsoleCtrlHandler, 815–817
.NET callbacks, 204–208
SourceInterfaceName_MethodNameEvent-Handler, 235
System.Runtime.InteropServices namespace, 1345
DeleteSubKey method, 860
deployment, 19–20
assemblies, 532–535
.NET applications, 126–130, 133–137
PIAs, 694–696
XCOPY, 20
zero-impact, 20
Desc property, 644–645
DESCKIND enumeration, 1264
Description property, 1216–1217, 1233
DescriptionAttribute, 359, 585
DESCUNION value type (System.Runtime.InteropServices namespace), 1264
design
COM components for .NET clients, 716–717
array parameters, 717–720
error reporting, 720–728
VARIANT parameters, 720
COM members for .NET clients, 729
passing error information, 731
passing interface pointers to anything, 729
passing type information, 730–731
COM objects for .NET clients
IProvideClassInfo, 734
naming guidelines, 734–735
performance, 735–738
resource management, 731–733
threading, 733
guidelines for exposing .NET events as COM connection points, 608–611
DestroyStructure method (Marshal class), 1299
DetachSink method, 239
device software, 14
DevTagAction class, 635, 643–645
DevTagRecognizer class, 635, 643–644
diagnotics, PInvoke signatures, 778
dialog boxes, Implement Interface, 748
digital signing. See signing
digitSpacing field, 1147
DINPUT8STRING-CONSTANTS class, 356
DINPUT8STRING-CONSTANTS module, 357
DirectMusicPerformance interface, 283–285
directories, System32, 25
DirectX, 1106
Advanced Version of E-mail Attack, 1171–1172
compiling, 1172
DirectX namespace, 1183, 1193–1194
E-mail Attack. See E-mail Attack
files
heartland.sty, 284
heartland2.sgt, 284
Layer class. See Layer class
.NET components, 1106
Screen class. See Screen class
type library errors, 294
COM callbacks running on threads, 287–289
callbacks on separate threads, 283–286
Web site, 1106
DirectX 7 for Visual Basic Type Library, 284
DirectX for VB, 1106
DirectX namespace, 1111, 1118, 1135, 1138, 1143, 1146, 1183, 1193–1194
dispatch identifiers. See DISPIDs
DispatchWrapper class (System.Runtime.InteropServices namespace), 1264–1265
DispatchWrapper wrapper, 115
DispHTMLStyleSheet interface, 1004–1006
DispIdAttribute (System.Runtime.InteropServices namespace), 574–578, 601, 651, 1265–1266
DISPIDs (dispatch identifiers), 173, 366, 370
converting, 173–174
DISPID NEWENUM -4, 175–176
DISPID Value 0, 174–175
DispIdAttribute, 574–578
dispinterfaces (COM interfaces), 982–984
Display class, 206
DisplayPropertyPage method, 1201, 1220–1221
Dispose method, 69, 1121, 1131, 1134–1136, 1151–1152, 1155–1156, 1167, 1171
DISPPARAMS value type (System.Runtime.InteropServices namespace), 1266
distributed COM. See DCOM
“DLL Hell”, 16
defined, 17
.NET Framework solution to, 17–18
side-by-side components, 18–19
version policies, 19
DLL/COM redirection, 17
dlldatax.c file, 292
DllGetClassObject method, 392
DllImportAttribute (System.Runtime.InteropServices namespace), 772, 1266–1267
choosing DLL locations dynamically, 863–865
choosing DLL names dynamically, 863–865
customizing, 795
DllImportAttribute (PInvoke)
ExactSpelling, 799
functio names, 796
GetLastError parameter, 800–801
PreserveSig parameter, 803–807
SetLastError parameter, 800–801
string behavior, 797–799
DllImportAttribute pseudo-custom attribute, 776–777
DLLs
assembly names, 502
choosing locations dynamically, 863–865
choosing names dynamically, 863–865
Office.dll, 301
PInvoke signatures, 1432–1433
SHELL32.DLL, 1470–1471
PowerPoint.dll, 301
static entry points, 772
DUMPBIN.EXE, 772
Platform Invocation Services. See PInvoke
do-it-yourself marshaling, 248
BSTR types, 249
C# unsafe code versus System.Runtime.Interop-Services APIs, 250–254
obtaining value type addresses, 254–255
obtaining value type sizes, 255–258
manipulating IntPtr types, 258
by-reference null value types, 264–265
C-style array fields, 262–264
null pointers, 259
SAFEARRAYs, 273–275
struct, 258–262
metadata signatures, 249
System.IntPtr data type, 248–250
DownloadBegin interface, 239
Draw method, 1147–1149
DrawAt method, 1136, 1139–1140, 1143–1144, 1146
DrawSurface method, 1112, 1139
dual interfaces (COM interfaces), 58, 975–979, 981
DUMPBIN.EXE, static entry points, 772
DWebBrowserEvents interface, 226
DWebBrowserEvents2 interface, 226
DX7VB.DLL, 284
dxSurface method, 1136
dynamic assemblies
creating
ConvertTypeLibTo-Assembly method, 1042–1044
ImporterEventKind enumeration, 1044
ITypeLibImporterNotifySink interface, 1044
ResolveRef method, 1045–1046
setting asmFileName to string, 1043
TypeLibImporterFlags enumeration, 1043–1044
saving, 1048–1050
dynamic type libraries
creating, 1050–1055
saving, 1055
E-mail Attack (DirectX application), 1106
Advanced Version, 1171–1172
compiling, 1172
DirectX namespace, 1183, 1193–1194
AnimatedEnvelopePicture class, 1143–1146
AnimatedPicture class, 1139
fields, 1140
methods, 1140–1143
properties, 1140
Character class
fields, 1157
private fields, 1158
EmailAttackForm class, 1166–1168, 1171
enumerations, 1120
Envelope class, 1162
public fields, 1162
FrontLayer class, 1154
Game class, 1111, 1119–1121, 1131–1133, 1166
private fields, 1121
properties, 1121
public fields, 1120
GroundLayer class, 1153
IntroScreen class, 1156–1157
Layer class, 1150
fields, 1150
methods, 1150–1152
NumberPicture class, 1146
private fields, 1147
Picture class, 1133–1134
properties, 1136
programmer’s perspective, 1108–1109
compiling, 1111
picture management, 1111
source files, 1109–1111
Screen class, 1155–1156
Sound class, 1133–1136
user’s perspective, 1107
Util class, 1112
public fields, 1112
effects. See visualizations
ELEMDESC value type (System.Runtime.InteropServices namespace), 1267
E-mailAttack class, 1178, 1182
E-mailAttackForm class, 1166–1171
E-mailAttackForm method, 1167
encapsulation, 209
EnterFullScreen event, 1217
entry points
calling conventions, 799–800
exact spelling setting, 799
FunctionName, 796
FunctionNameW, 796
static, 772
callbacks, 810–821
choosing DLL locations dynamically, 863–865
choosing DLL names dynamically, 863–865
customizing structures, 829–847
DUMPBIN.EXE, 772
passing structures, 821–829
Platform Invocation Services. See PInvoke
variable-length structures, 847–849
EntryPoint parameter, 1266
EntryPoint property, 36, 40, 43
EnumConnectionPoints method (IConnectionPoint-Container interface), 216
EnumerableToDispatch-Marshaler class, 1370
enumerations
AssemblyRegistrationFlags, 1056–1057, 1096
ClassInterfaceType, 556–560
ComInterfaceType, 578–579
E-mail Attack, 1120
ExporterEventKind, 1052–1055, 1068
InstallationFlags, 1099
InstallationFlags enumeration, 1060–1061
IWMPEffects interface, 1204–1208
MessageTypes, 1068
names, 707–709
REGKIND, 1068
System.Runtime.InteropServices namespace
AssemblyRegistration-Flags, 1254
CALLCONV, 1255
CallingConvention, 1255–1256
CharSet, 1256
ClassInterfaceType, 1257
ComInterfaceType, 1260
ComMemberType, 1261
DESCKIND, 1264
ExporterEventKind, 1268–1269
FUNCFLAGS, 1272
FUNCKIND, 1273
GCHandleType, 1277
IDispatchImplType, 1283
IDLFLAG, 1283
IMPLTYPEFLAGS, 1283
ImporterEventKind, 1284
INVOKEKIND, 1287
LayoutKind, 1290
LIBFLAGS, 1291
PARAMFLAG, 1347
SYSKIND, 1354
TYPEFLAGS, 1355
TYPEKIND, 1355
TypeLibExporterFlags, 1357
TypeLibFuncFlags, 1358
TypeLibImporterFlags, 1358
TypeLibTypeFlags, 1359
TypeLibVarFlags, 1359
UnmanagedType, 1367–1368
VarEnum, 1369–1370
VARFLAGS, 1370
System.Threading.ApartmentState, 280
TagTypes, 643–644
TypeLibExporterFlags, 1051
TypeLibImporterFlags, 1043–1044
UnmanagedType, 337–338, 542–545, 549–552
usage guidelines, 514–516
VarEnum, 337–338
Verbs, 643
enumerators
COM collections, 114
exposing to COM, 524–527
EnumeratorToEnumVariantMarshaler class, 1371
Envelope class, 1162
public fields, 1162
Envelope method, 1162
EnvelopeGrid field, 1120
EnvelopePicture field, 1120
envelopes (E-mail Attack game). See Game class
EnvelopeUnderneath property, 1162
envelopeX field, 1158
envelopeY field, 1158
Environment class, 1171
Equals method, 743
ErrorCode, 722
errors. See also troubleshooting
assembly content modifications, 328
creating COM objects, 101
handling
COM compared to .NET Framework, 66–68
interface implementation, 112–114
Win32 APIs, 800–807
MarshalAsAttribute, 552–553
reporting, 720–721
HRESULTs, 721–722
setting information, 722–723
setting information in Visual Basic 6, 723–724
setting information in Visual C++, 725–728
returned error codes/messages
unmanaged C++, 404–407
Visual Basic 6, 403–404
type libraries, 294
ErrorWrapper class (System.Runtime.InteropServices namespace), 1267–1268
ErrorWrapper wrapper, 115
ERROR_REFTOINVALID-ASSEMBLY value, 1052, 1268
ERROR_REFTOINVALIDTYPELIB value, 1044, 1284
event handling
ActiveX
events, 240–245
importer transformations, 235–240
connectable objects, 229–235
hookup, 603–604
Internet Explorer
.NET events, 224–227
raw connection points, 219–222
lazy connection point initialization, 227–229
Phone class, 597
type library importer transformations, 222–227, 235–240
EventClassAttribute, 585
EventNameEventArgs class, 609
events, 592
Activated, 625
ActiveX, 240–245
adding for source interfaces, 186
CallerId, 592–593
Closing, 622–623
COM
connectable objects, 229–235
handling in managed code, 218–222
lazy connection point initialization, 227–229
type library importer transformations, 222–227
EnterFullScreen, 1217
ExitFullScreen, 1217
exposing as COM connection points
Windows Forms, 611–614, 620–625
with CLR, 598–611
without CLR, 592–597
handling. See event handling
InputLanguageChanging, 622–623
manually defining, 1003–1009, 1016–1017, 1019
members, 229–232
.NET Framework
callbacks, 208–214
handling, 488–489
NOTIF_TYPE-CONVERTED, 1052
OnCallerId, 596
OnRing, 596
QueryAccessibilityHelp, 623
Ring, 592–593
sinks, 623–625
type library transformations, 446–447
WebBrowser control, 241–245
WindowResize, 226
EventTrackingEnabled-Attribute, 585
ExactSpelling (entry point name), 799, 1266
ExampleAttribute, 354
/exapp (REGSVCS.EXE), 1395
EXCEPINFO value type (System.Runtime.InteropServices namespace), 1268
ExceptionClassAttribute, 585
exceptions
COMException, 728
defining new exceptions, 520–522
HRESULTs
error information, 404
HRESULT to, 1400, 1406–1407, 1413
to HRESULT transformations, 1416–1417, 1423, 1429
InvalidCastException, 289–299
InvalidOperationException, 403
.NET methods called back from COM, 286
properties, 722
returned error codes/messages
unmanaged C++, 404–407
Visual Basic 6, 403–404
System.Runtime.Interop-Services namespace
COMException, 1259–1260
ExternalException, 1271
InvalidComObject-Exception, 1286
InvalidOleVariantTypeException, 1286–1287
MarshalDirective-Exception, 1344–1345
SafeArrayRank-Mismatch-Exception, 1352
SafeArrayTypeMismatchException, 1352–1353
SEHException, 1353
TypeLoadException, 313, 392, 403
user-defined, 521–523
Win32 errors, 803–807
ExitFullScreen event, 1217
ExpandoToDispatchEx-Marshaler class, 1371–1372
ExpectExistingTypeLib value, 1061
explicit members, 655–656
Explicit value, 1290
exported type libraries, 428
Exporter class, 1083–1084, 1086–1092
Exporter tab (Interactive Interop Tool), 1083–1084, 1086–1092
ExporterEventKind enumeration (System.Runtime.InteropServices namespace), 1052–1055, 1068, 1268–1269
exporters (type library), 394–397
COM-Callable Wrappers. See CCWs
generating type libraries, 395
REGASM.EXE, 395
Register for COM Interop option, 395
TLBEXP.EXE, 395–396
TypeLibConverter class, 395
MarshalAsAttribute C# signatures, 900–901
exportOpenButton_Click method, 1100
ExtensibleClassFactory class (System.Runtime.InteropServices namespace), 1269–1271
ExtensibleClassFactory.RegisterObjectCreation-Callback method, 314
ExternalException (System.Runtime.InteropServices namespace), 1271
/extlb (REGSVCS.EXE), 1395
extraLifeSound field, 1121
FACILITY_URT (HRESULTs), 393
FAILED method, 347
failure HRESULTs, 579–580, 721
ErrorCode, 722
setting error information, 722–723
setting error information in Visual Basic 6, 723
FastCall value, CallingConvention enumeration, 1255
/fc (REGSVCS.EXE), 1395
FieldOffsetAttribute (System.Runtime.InteropServices namespace), 832–833, 1271–1272
fields
AnimatedPicture class, 1140
audioTitle, 1217
channelCount, 1217
Character class, 1157–1158
Layer class, 1150
private
Character class, 1158
Game class, 1121
NumberPicture class, 1147
public
Envelope class, 1162
Game class, 1120
type library transformations, 444–446
usage guidelines, versus properties, 510–511
Util class, 1112
File Signing Tool. See SignCode.exe
filenames, DLLs, 690
files
DirectX
heartland.sty, 284
heartland2.sgt, 284
dlldatax.c, 292
FILETIME value type (System.Runtime.Interop-Services namespace), 1272
FillRect method, 271
Finalize method, 743
FindOrCreateTargetApplication value, 1061
fixed-length arrays, 157–158
flags
DeclaredOnly, 1220
hasTransparentColor, 1138
ImporterEventKind enumeration, 1044
TypeLibImporterFlags enumeration, 1043
FontMarshaler class, custom marshaling, 365, 914–918
.NET Windows Form consumer, 918–920
Visual Basic 6 .NET form, 921–923
fonts, custom marshaling, 914
FontMarshaler class, 914–918
.NET Windows Form consumer, 918–920
Visual Basic 6 .NET form, 921–923
format specifiers, GUIDs, 570
formatted classes, customizing structures, 839–844
forms
ComFriendlyForm, 623
Visual Basic 6, FontMarshaler custom marshaler, 921–923
Windows Forms
exposing events to COM, 611–614, 620–625
FontMarshaler custom marshaler, 918–920
Interactive Interop Tool, 1100–1101
frames field, 1140
framesInRow field, 1140
framesSinceDeath field, 1158
frameWidth field, 1140
Framework Services Installation Utility. See REGSVCS.EXE
Free method (GCHandle value type), 1275
Free string value, 276
free-threaded components, 277
free-threaded marshaler. FTM, 282
FreeBSTR method (Marshal class), 1299–1300
FreeCoTaskMem method (Marshal class), 1300
FreeHGlobal method (Marshal class), 1300
frequency, 1199
FromGlobalAccessCache method (Runtime-Environment class), 1351
front buffer surfaces, 1118
FrontLayer class, 1154
FTM (free-threaded marshaler), 282
fully qualified names, C#, 61–62
FUNCDESC value type (System.Runtime.InteropServices namespace), 1272
FUNCFLAGS enumeration (System.Runtime.InteropServices namespace), 1272
FUNCKIND enumeration (System.Runtime.InteropServices namespace), 1273
FunctionName entry point, 796
FunctionNameW entry point, 796
functions
GetLastError, 800
GetWindowsDirectory, 784–788
Microsoft.VisualBasic.Left, 788
PInvoke
case-sensitivity, 774
names, 796
PInvoke signatures, 1432–1433
SHELL32.DLL, 1470–1471
pointers, 810–811
delegates as, 811–817
invoking unmanaged pointers in managed code, 818–821
QueryPerformanceCounter, 774
QueryPerformance-Frequency, 774–777
registration, 570–574
SetConsoleCtrlHandler, delegates as, 815–817
SetVolumeLabel, 783–784
shutdown, MSCOREE.DLL, 492–493
unregistration, 569–570
Win32
GetConsoleScreen-BufferInfo, 821–829
GetLastError, 800
GAC (global assembly cache), 24–25, 63
compared to System32 directory, 25
compared to Windows Registry, 64
installing assemblies, 392, 649–650
Game class, 1111, 1119–1121, 1131–1133, 1154, 1166
private fields, 1121
properties, 1121
public fields, 1120
Game method, 1121
Game.Render method, 1171
GameStates enumeration, E-mail Attack, 1120
garbage collection
GC.Collect, 301–302
Marshal.ReleaseComObject, 299–304
PowerPoint, 301–304
Garbage Collector, premature collecting, 852–853, 856, 859–862
GC.Collect, 301–302
GCHandle value type (System.Runtime.InteropServices namespace), 1273–1275
conversion operators, GCHandle/IntPtr, 1276–1277
methods
AddrOfPinnedObject, 1275
Alloc, 1275
Free, 1275
properties
IsAllocated, 1275
Target, 1276
GCHandle/IntPtr conversion operator, GCHandle value type, 1276–1277
GCHandleType enumeration (System.Runtime.InteropServices namespace), 1277
GDI32.DLL, PInvoke signatures, 1433, 1442
GenerateGuidForType method (Marshal class), 1301
GenerateProgIdForType method (Marshal class), 1301
get accessors, 442
GetActiveObject method (Marshal class), 1301
getBonusSound field, 1121
GetCapabilities method, 1200
GetClassID method, 654
GetComInterfaceForObject method (Marshal class), 1302
GetComObjectData method (Marshal class), 1303
GetComSlotForMethodInfo method (Marshal class), 1303
GetConsoleScreenBuffer-Info function, 821–829
GetCurrentPreset method, 1201
GetCustomAttributes, 1220
GetDisplayNameForAssembly method, 1067
GetEndComSlot method (Marshal class), 1303
GetEnumerator method, 440, 524–527
GetExceptionCode method (Marshal class), 1303–1304
GetExceptionPointers method (Marshal class), 1304
GetExportedTypes method, 1097
GetFrequency method, 1225
GetHashCode method, 743
GetHINSTANCE method (Marshal class), 1304
GetHRForException method (Marshal class), 1304–1305
GetHRForLastWin32Error method (Marshal class), 1305
GetIDispatchForObject method (Marshal class), 1305–1306
GetIDsOfNames method, 662
GetInstance method, 897–898
GetITypeInfoForType method (Marshal class), 1306
GetIUnknownForObject method (Marshal class), 1306–1307
GetLastError function, 800
GetLastWin32Error method (Marshal class), 1307
GetManagedCategoryGuid method, 1057, 1349
GetManagedThunkFor-UnmanagedMethodPtr method (Marshal class), 1307
GetMethodInfoForCom-Slot method (Marshal class), 1308
GetNativeDataSize method, 897, 1282
GetNativeVariantForObject method (Marshal class), 1308–1309
GetObjectAttribute method
calling, 260
.NET signature, 260
GetObjectForIUnknown method (Marshal class), 1309
GetObjectForNativeVariant method (Marshal class), 272, 1309
GetObjectsForNative-Variants method (Marshal class), 1310
GetPresetCount method, 1201
GetPresetTitle method, 1201, 1220, 1225
GetPrimaryInterop-Assembly method, 1047–1048, 1357
GetPrivateProfileSection-Names API, 789–791
GetProgIdForType method (RegistrationServices class), 1057, 1350
GetRecordInfoFromType-Info method, 271
GetRegistrableTypesIn-Assembly method, 1057, 1350
GetRuntimeDirectory method (RuntimeEnvironment class), 1351
method, 729
.NET signature, 729
GetStartComSlot method (Marshal class), 1310–1311
GetSystemVersion method (RuntimeEnvironment class), 1352
GetThreadFromFiberCookie method (Marshal class), 1311
GetTitle method, 1201
GetType method, 511–512
GetTypeCode method, 118
GetTypedObjectForI-Unknown method (Marshal class), 1311
GetTypeForITypeInfo method (Marshal class), 1311–1312
GetTypeInfo method, 663
GetTypeInfoName method (Marshal class), 1312
GetTypeLibGuid method, 1067, 1312
GetTypeLibGuidFor-Assembly method (Marshal class), 1312
GetTypeLibLcid method, 1067, 1313
GetTypeLibName method, 1067, 1313
GetUnderlyingObject method (ICustomAdapater interface), 909
GetUnmanagedThunkForManagedMethodPtr method (Marshal class), 1313–1314
GetWindowsDirectory function, 784–788
Global Assembly Cache Utility. See gacutil.exe
GlobalMultiUse setting (instancing), 634
GlobalSingleUse setting (instancing), 633
GoFullscreen method, 1201, 1222
Graphics property, 622
GroundLayer class, methods, 1153
GuidAttribute, 331, 427, 574, 1278
GuidAttribute custom attribute, 963
GUIDs
COM Interoperability, 529
format specifiers, 570
GuidAttribute, 574
names, 60–61
HandleRef instance, 862
HandleRef value type (System.Runtime.InteropServices namespace), 1278–1280
HasAttachment field, 1162
HashCode property, 502
Hashtable key
IComparer interface implementation, 764–766
IHashCodeProvider interface implementation, 764–766
HasPropertyPage method, 1232
hasTransparentColor flag, 1138
hasTransparentColor method, 1136
HDC parameter, 1218
heartland.sty file, 284
heartland2.sgt file, 284
Height property, 1136, 1139–1140, 1143
Hello, World program
C#, 36
C++, 43
Visual Basic .NET, 39–40
/help (AXIMP.EXE), 1393
/help (REGASM.EXE), 1390
/help (REGSVCS.EXE), 1396
/help (TLBEXP.EXE), 1384
/help (TLBIMP.EXE), 1381
HelpLink string, 723
helpstring
assemblies, 427
type libraries, 382
hiding HRESULTs, 162–164
highScore field, 1121
HighScore property, 1121, 1132
HKEY_CLASSES_ROOT registry key, 62
hosts, CLR, 460–468
HResult property, 520
caused by .NET exceptions, error information, 404
COM interface implementation, 656
defining, 520
to exception transformations, 1400, 1406–1407, 1413
exceptions to transformations, 1416–1417, 1423, 1429
exposing success, 342–348
FACILITY_URT, 393
ErrorCode, 722
setting error information, 722–723
hiding, 162–164
IDispatch implementations, 664–665
.NET interface implementation, 758
.NET method transformations, 434–436
registering assemblies, 393
HTML Object Library (Microsoft), 234, 1003
HTMLDocument coclass, 234
HTMLDocument interface, 235
HTMLStyleSheet class, 1003
HTMLStyleSheet coclass, 1004–1006, 1023
IAmVisibleToAll interface, 479
IAssemblyCache interface, 1040
IChatRoomDisplay interface, 215–216
ICollection interface, 746
IComparer interface, implementation to use COM objects as Hashtable key, 764–766
IConnectionPointContainer interface
implementation, 675–676
methods, 216
ICorRuntimeHost interface, 460
ICreateErrorInfo interface, 727–728
ICreateTypeInfo interface, 1068
ICreateTypeLib interface, 1068
ICustomAdapter interface (System.Runtime.InteropServices namespace), 1280–1281
GetUnderlyingObject method, 909
implementation, 909
ICustomFactory interface (System.Runtime.InteropServices namespace), 1281
ICustomMarshaler interface (System.Runtime.InteropServices namespace), 896–898,1281-1282
IDASite interface, 731
IDE (Integrated Development Environment), 25
IDebuggerInfo interface, 461
IDictionary interface, 746
IDispatch (COM interfaces), 54–55, 58,103, 146–147, 654, 659
CLR, 659–665
writing, 665–672
IDispatch.Invoke method, 608
IDispatchEx interface, 152–153, 678–679
IDispatchImplAttribute (System.Runtime.InteropServices namespace), 660–661, 1282
IDispatchImplType enumeration (System.Runtime.InteropServices namespace), 1283
IDisposable interface, 732, 750–759, 1131
IDisposable.Dispose method, 493, 1135
IDL (Interface Definition Language), 54
coclasses
IDL representation of .NET classes, 451–453
representation of .NET classes, 451
representation of .NET classes, 450–453
COM data type conversions, 143–144
combining types, 145–151
complex types, 152–162
of an event, 447
of fields exported as properties, 445
of methods with parameter arrays, 441
of properties, 443
custom attributes, 371–372
definitions
IHTMLStyleSheet interface, 988–989
INetMeetingEvents dispinterface and INetMeeting interface, 1007–1008
IPersist and IPersistStream Interfaces, 985
IRunningAppCollection, 975–976
IWMPEffects interface, 964
IDispatch (COM interface), 54–55
IUnknown (COM interface), 54
.NET View and COM View
of the same methods, 435
of the same methods by-value and by-reference parameters, 437
of the same overloaded methods, 439
optional parameters, 104–105
representation of the AddressLists dispinterface, 982
type libraries, 697–698
ActiveX controls, 712
constants, 709–710
constructs, 710
defining classes, 702–707
naming enums, 707–709
referencingexternal types, 698–702
registering type libraries, 711
IDLDESC value type (System.Runtime.InteropServices namespace), 1283
IDLFLAG enumeration (System.Runtime.InteropServices namespace), 1283
IEnumerator interface, 524, 746
IEnumVARIANT interface, 152–153, 524–525, 678
IErrorInfo interface, 409–414, 723–725, 731
IFont interface, 910–912
IFormattable interface, 761–764
IFormEvents methods, 623
IGCHost interface, 460
IHashCodeProvider interface, 764–766
IHTMLStyleSheet interface
C# definition, 996–998, 1035–1036
IDL definition, 988–989
VB .NET definition, 991
IIDs, versioning, 531–532
IISIntrinsicsAttribute, 585
IL (Intermediate Language), 21
IL Assembler syntax
metadata listing, 967–971
structure definitions, 1020
IL Assembler. See ILASM; ILASM.EXE
IL Disassembler. See ILDASM; ILDASM.EXE
ILASM.EXE (IL Assembler), 45, 324
adding methods to modules, 372–373
assembly content modifications, 324–328
changing data types, 340–342
custom attributes, 351–366, 370–372
custom marshalers, 248, 364–366
errors, 328
exposing success HRESULTs, 342–348
key option, 327
malicious edits, 327
managed resources, 326
output file names, 328
SAFEARRAYs, 348–351
unmanaged resources, 326
ApplicationEventsSinkHelper class constructor, 332
changing data types, 340–342
custom attributes, 351–358
data types, 332–333
exposing HRESULTs, 342–348
input files, 331
MarshalAsAttribute, 334–340
nested types, 334
passing parameters, 334
SAFEARRAYs, 348–351
ILDASM.EXE (IL Disassembler), 45, 307, 324, 512, 653
assembly content modifications, 324–327
changing data types, 340–342
malicious edits, 327
managed resources, 326
unmanaged resources, 326
opening PIAs, 695
IMainMenu interface, 507
IManagedObject interface, 658
IMarshal interface, 672–673
Implement Interface dialog box, 651–652, 748
IMPLTYPEFLAGS enumeration (System.Runtime.InteropServices namespace), 1283
import directive, referencing external types, 698–702
ImportedFromTypeLib-Attribute, 331, 1284
Importer class, 1069–1083
Importer tab (Interactive Interop Tool), 1069–1083
importer transformations (type library)
exposing connection pointers, 222–227, 235–240
IntPtr types. See IntPtr types
Importer.cs, 1070–1083
ImporterEventKind enumeration (System.Runtime.InteropServices namespace), 1044, 1068, 1284
importers, type library, 84, 1049–1050
Interop Assembly. See Interop Assembly
transformations, 86
importlib directive, 698–702
Imports statement (Visual Basic .NET), 38
in, [out] parameter, method conversions, 167–169
InAttribute (System.Runtime.InteropServices namespace), 1284–1285
customizing data flow, 553–554
export behavor, 438
marking array parameters, 792–794
INetMeeting interface, 1007–1008
INetMeetingEvents dispinterface, 1007–1008
INetMeetingEvents_EventProvider class, 1017
infectSound field, 1121
infrastructure, 14
inheritance
COM
classes, 311–315
interface implementation, 654–656
.NET interfaces, 743–747, 984–985, 987
Initialize method, 227, 1112, 1118
InitializeComponent method, 239
inproc servers, 63
input files (ILASM.EXE), 331
InputLanguageChanging event, 622–623
InputLanguageChanging method, 622
Install method, 1099
Install value, 1061
InstallAssembly method, 1060, 1099
installation
assemblies
GAC, 392
in GAC, 649–650
COM+ objects, 309
serviced components, 1059–1061
InstallationFlags enumeration, 1060–1061, 1099
installFlags parameter, 1060
instances
creating
CreateObject method, 99–101
error detection, 101
new operator, 99
HandleRef, 862
ManualResetEvent, 289
RegistryKey, 856
System.Collections.Array-List, 463
System.Collections.SortedList, 461
System._ComObject, 232
VARIANTs, 117–118
instantiating objects, 229–235
Integrated Development Environment. See IDE
Interactive Interop Tool, 1062, 1064
COM+ tab, 1097–1100
compared to SDK, 1062–1063
Exporter tab, 1083–1092
Importer tab, 1069–1083
MainForm class, 1100–1101
MiscTypes.cs, 1064–1068
Register tab, 1092–1097
structure, 1063
Interface Definition Language. See IDL
Interface value, 834
InterfaceIsDual value (ComInterfaceType enumeration), 1260
InterfaceIsIDispatch value (ComInterfaceType enumeration), 1260
InterfaceIsIUnknown value (ComInterfaceType enumeration), 1260
InterfaceName_MemberName method, 663
InterfaceQueuing-Attribute, 585
interfaces
Advise, methods, 216
AppDomain, 488–489
ChatRoomDisplay, 204
CLR-specific, 658
coclasses, 1003–1009, 1016–1019
converting .NET interfaces to, 447–449
custom attributes, 963–964
customizations, 998–1003
default implementations, 657–677
definitions, 628–629
Dispatch, 70
error handling, 112–114
explicit interface members, 655–656
HRESULTs, 656
IAmVisibleToAll, 479
IAssemblyCache, 1040
IConnectionPointContainer, 675–676
ICorRuntimeHost, 460
ICreateErrorInfo, 727–728
IDebuggerInfo, 461
IDispatch, 54–55, 58, 146–147, 654, 659–672
IDispatchEx, 152–153
IEnumVARIANT, 152–153
IGCHost, 460
IMarshal, 672–673
Implement Interface option, 651–652
implementation, 112–114
IObjectSafety, 676–677
IPersist, 654–656
IPersistStream, 654–656
IPhoneEventHookup, 596
IPhoneEvents, 596–597
IProvideClassInfo, 296, 673–674, 705–706, 734
IRecordInfo, 271
ISmartTagAction, 635–636, 643–646, 654
ISmartTagRecognizer, 635–636, 643–646, 654
ISupportErrorInfo, 674, 725–726
IUnknown, 54, 57, 68–70, 146–147, 654, 657–659
IUnknown-Only interfaces, 964–974
IValidator, 461
language limitations, 988–995, 998
manually defining, 962–963
method signatures, 652
MultiPurposeObject, 705
names, 500
.NET types, 678–679
non-public, 967
Office XP smart tags, 634–636, 643–650, 653–656
parameterized properties, 653–654
private members, 653
selecting members, 651
SetErrorInfo, 728
versioning, 65–66
Visual Studio .NET shortcuts, 650–652
COM callbacks, source, 215–216, 226
converting, 177–179
default, defining classes in IDL files, 704–707
DirectMusicPerformance, 283, 285
DownloadBegin, 239
DWebBrowserEvents, 226
HTMLDocument, 235
IChatRoomDisplay, 215–216
ICollection, 746
IComparer, 764–766
IConnectionPointContainer, methods, 216
ICreateTypeInfo, 1068
ICreateTypeLib, 1068
ICustomAdapter
GetUnderlyingObject method, 909
implementation, 909
ICustomMarshaler, 896–898
IDictionary, 746
IDispatch, 103
IDispoable interface, 750–759, 1131
IEnumerable, 746
IEnumerator, 524
IEnumVARIANT, 524–525
IErrorInfo, 409–414, 723–725, 731
IFont, 910–912
IFormattable, 761–764
IHashCodeProvider, 764–766
IMainMenu, 507
IServicedComponent, 507
ISuportErrorInfo, 726–727
IToolClient, 1068
ITypeLibConverter, 1042
IVSSDatabase, 102
IWin32Window, 1221
enumerations, 1204–1208
methods, 1200–1201
Render method, 1199–1200
structs, 1204–1208
Vizualization class, 1208–1223
Microsoft Direct Animation, IDASite, 731
.NET Framework, 740
callbacks, 202–204
class interfaces, 741–743
COM, 678–679
converting to COM interfaces, 447–449
disabling marshaling, 580–582
HRESULTs, 758
IComparer implementation, 764–766
IDispatchEx, 678–679
IDisposable, 732
IEnumVARIANT, 678
IErrorInfo, 731
IHashCodeProvider implementation, 764–766
inheritance, 743–747
InterfaceTypeAttribute, 578
IReflect, 665–672
ITypeInfo, 678
names, 503–504
System.IConvertible, 652
Visual Basic 6, 397–399, 759–764
Visual C++, 747–759
Object class, 439–440
PowerPoint.EApplication, 366
QueryInterface, failures, 290–295
source, defining classes in IDL files, 703–704
SourceInterfaceName_Event, 222
SourceInterfaceName_EventProvider, 222
SourceInterfaceName_MethodNameEvent-Handler, 222
SourceInterfaceName_SinkHelper, 222
System.Collections.IEnumerable, 740
System.Runtime.Interop-Services namespace
custom marshaling, 1252
ICustomAdapter, 1280–1281
ICustomFactory, 1281
ICustomMarshaler, 1281–1282
IRegistrationServices, 1287
ITypeLibConverter, 1287–1288
ITypeLibExporterNameProvider, 1288
ITypeLibExporterNotifySink, 1289
ITypeLibImporterNotifySink, 1289
UCOMIBindCtx, 1360
UCOMIConnectionPoint, 1360
UCOMIConnectionPointContainer, 1360
UCOMIEnum-ConnectionPoints, 1360
UCOMIEnum-Connections, 1361
UCOMIEnumMoniker, 1361
UCOMIEnumString, 1361
UCOMIEnumVARIANT, 1361–1362
UCOMIMoniker, 1362–1363
UCOMIPersistFile, 1363
UCOMIRunningObjectTable, 1363
UCOMIStream, 1364
UCOMITypeComp, 1364–1365
UCOMITypeInfo, 1365
UCOMITypeLib, 1366
System.Runtime.InteropServices.ITypeLibExporter-NameProvider, 1054–1055
C# method, 1054
C++ method, 1054
Visual Basic .NET method, 1054
TypeInfo, 59
Unadvise, methods, 216
usage guidelines
versus classes, 506–508
versus custom attributes, 508–510
InterfaceTypeAttribute, 578–579, 601, 1285
InterfaceTypeAttribute custom attribute, 964
Intermediate Language. See IL
internal IDispatch CLR implementation, 660–665
InternalImpl value (IDispatchImplType enumeration), 1283
Internet Explorer, handling events
.NET events, 224–227
raw connection points, 219–222
InternetExplorer coclass, 218–222, 231
InternetExplorer.Document property, 234
Interop API, 52
Interop Assembly, 84–86. See also assemblies; Interop Marshaler
ActiveX control conversions, 196–198
adding methods to modules, 372–373
assembling/reassembling, 326–327
class conversions, 179
coclasses, 180–182
RCW class, 182–186
content modifications, 324–328
changing data types, 340–342
custom attributes, 351–366, 370–372
custom marshalers, 248, 364–366
errors, 328
exposing success HRESULTs, 342–348
key option, 327
malicious edits, 327
managed resources, 326
output file names, 328
SAFEARRAYs, 348–351
unmanaged resources, 326
creating, 85
data type conversions, 143–144
combining types, 145–151
complex types, 152–162
DISPIDs conversions, 173–174
DISPID NEWENUM -4, 175–176
DISPID Value 0, 174–175
enumeration conversions, 193–194
GetPrimaryInteropAssembly method, 1047–1048
helpstrings, 427
ILDASM.EXE, 653
interface conversions, 177–179
method conversions, 162
by-value versus by-reference, 164–167
hiding HRESULTs, 162–164
in, [out] parameter, 167–169
[in] versus [out], 167–169
parameter arrays, 169–171
module conversions, 187–188
Primary, 86–90
property conversions, 171–173
registering, 297
signatures, 344
structure conversions, 189–191
type library conversion, 141–143
typedef conversions, 194–196
union conversions, 191–192
Interop Marshaler, 96–98. See also Interop Assembly
do-it-yourself marshaling, 248
BSTR types, 249
C# unsafe code versus System.Runtime.InteropServices APIs, 250–258
manipulating IntPtr types, 258–267, 270–275
metadata signatures, 249
System.IntPtr data type, 248–250
marshaling strings. See strings
without custom marshaling, 880
interoperability
core COM tools. See TLBIMP.EXE; TLBEXP.EXE; REGASM.EXE
extended COM tools. See AXIMP.EXE; REGSVCS.EXE
IntPtr parameter, 340–341
IntPtr types
defining string parameters as, 789–791
initializing to null, 259
manipulating, 258
by-reference null value types, 264–265
C-style array fields, 262–264
SAFEARRAYs, 273–275
struct, 258–262
IntroScreen class, 1156–1157
InvalidCastException exception, troubleshooting, 289–290
casting to RCW types, 295–299
QueryInterface failure, 290–295
InvalidComObject-Exception (System.Runtime.InteropServices namespace), 1286
invalidMoveSound field, 1121
InvalidOleVariantType-Exception (System.Runtime.InteropServices namespace), 1286–1287
InvalidOperationException, 403, 477–482, 562–565
INVOKEKIND enumeration (System.Runtime.InteropServices namespace), 1287
InvokeVerb method, 645–646
[in] parameter, method conversions, 167–169
IObjectSafety interface, implementation, 676–677
IPersist interface, C# definition, 985
customizations, 986–987
explicit interface members, 655–656
IDL definition, 985
inheritance, 654–655
IPersistStream interface
C# definition, 985–987
explicit interface members, 655–656
IDL definition, 985
inheritance, 654–655
IPhoneEventHookup interface, 596
IPhoneEvents interface, 596–597
IProvideClassInfo interface, 296, 673–674, 705–706, 734
IRecordInfo interface, 271
IReflect interface
IDispatch interface implementation, 665–672
members, 665–666
parameters, 671
IRegistrationServices interface (System.Runtime.InteropServices namespace), 1287
IRunningAppCollection dual COM interface, 975–976
definition in C#, 976–979
definition in VB .NET, 980–981
IsAllocated property (GCHandle value type), 1275
IsComObject method (Marshal class), 1314
IsDying field, 1158
ISearch interface, 360–361, 363
IServicedComponent interface, 507
IsInfected field, 1162
ISmartTagAction interface, 635–636, 643–646, 654
IsmartTagRecognizer interface, 635–636, 643–646, 654
ISmartTagRecognizer.get_Name method, 654
ISmartTagRecognizer.Recognize method, 635
IsPhoneNumber method, 381
IsTimeToMove method, 1112, 1118
IStream, 881
IStream interface,
by-reference null value types, 264–265
IsTypeVisibleFromCom method (Marshal class), 1314
ISupportErrorInfo interface, 674, 725–727
IsVisible field, 1162
isVisible parameter, 504
IsVisible property, 504
IToolClient interface, 1068
ITreeNode.isVisible property, 504
ITypeInfo interface, 59, 152–153, 678, 730
ITypeInfo.Invoke method, 582
ITypeLibConverter interface (System.Runtime.InteropServices namespace),1042, 1287–1288
ITypeLibExporterName-Provider interface (System.Runtime.InteropServices namespace), 1288
ITypeLibExporterNotifySink interface (System.Runtime.InteropServices namespace), 1289
ITypeLibExporterNotify-Sink.ReportEvent method, 1052
ITypeLibImporterNotify-Sink interface, 1044, 1051–1055, 1289
IUnknown (COM interfaces), 54, 57, 68, 70, 146–147, 654
IDL, 54
implementation, 657
non-reflexive implementation, 292–293
QueryInterface, 658–659
IUnknown-Only interfaces (COM interfaces), 964–974
IUnknown.AddRef method, 109
IUnknown.AddRef object, 68
IUnknown.Release method, 109
IValidator interface, 461
IVSSDatabase interface, 102
IWin32Window interface, 1221
IWMPEffects interface, 1199, 1202–1204
defining in C#, 971–973
defining in VB .NET, 974
enumerations, 1204–1208
IDL definition, 964
methods, 1200–1201
Render method, 1199–1200
structs, 1204–1208
translation to C#, 965–967, 1002
Visualization class, 1208–1223
jagged arrays, 518–519
JIT (just-in-time compiler), 21
JScript, StringValidator class, 388–390
JUMP to .NET, 51
just-in-time compiler. See JIT
JustInTimeActivation-Attribute, 585
Kernel32 class, 1167
KERNEL32.DLL
functions, 774–797
PInvoke signatures, 1442, 1461
key option (ILASM.EXE), 327
/keycontainer (AXIMP.EXE), 1391
/keycontainer (TLBIMP.EXE), 1377–1378
/keyfile (AXIMP.EXE), 1392
/keyfile (TLBIMP.EXE), 1378
keyPair parameter (Con-vertTypeLibTo-Assembly method), 1046, 1357
KeywordAttribute, 509
KeywordAttributes assembly, 30
keywords
Alias, customizing PInvoke function names, 796
names, 500
language limitations, COM interfaces, 988–995, 998
languages, 33–34
C++. See C++
managed, 15
Visual Basic .NET. See Visual Basic .NET
late binding, 91
COM components, 119–120
.NET members, 119
unmanaged C++, 404–407
fields, 1150
methods, 1150–1152
Layer method, 1150
layers field, 1121
LayoutKind enumeration (System.Runtime.InteropServices namespace), 1290
StructLayoutAttribute, 554, 829–830
LCIDConversion, 583
LCIDConversionAttribute (System.Runtime.InteropServices namespace), 582, 1290–1291
LCIDs (Local Identifier), 529
assemblies, 427
methods, 582–583
LDIC (Locate Identifier), 426
leftAligned field, 1147
let accessors, 442
LIBFLAGS enumeration (System.Runtime.InteropServices namespace), 1291
LIBIDs (Library Identifier), 426–427, 529
library identifiers. See LIBIDs
lifetimes, 68–69
link demands, 306
listings
AnimatedEnvelopePicture.cs., 1144, 1146
AnimatedPicture.cs., 26–28
C# definition of IHTMLStyleSheet interface, 1035–1036
C# definition of IMarshal, 672–673
C# definition of NetMeeting Coclass interface, 1009, 1016–1018
C# defintion of IHTMLStyleSheet interface, 996, 998
C# Non-Static Extern Members feature, 1029, 1031
C# representation of enumerations and enumeration parameters, 454, 457
C# representation of two interfaces related by inheritance, 448–449
C# source code demonstrating how to put ExampleAttribute on different elements, 36–38
C++ definition of ISupportErrorInfo, 674
C++ source code demonstrating how to put the ExampleAttribute on different elements, 44–45
Character.cs., 1158, 1161–1162
ChessBoard.cls., 765–766
ColorfulConsole Class Wraps Win32 APIs for Printing in Color, 822–829
ColorfulVisualization.cs, 1231–1235
COM Class Implementing Several Interfaces, 183–184
COM View and .NET View of an event, 446
COM View and .NET View of fields exported as properties, 444–446
COM View and the .NET View of a Method that Doesn’t Return an HRESULT, 163
COM View and the .NET View of a Method with a Parameter Array, 170
COM View and the .NET View of Methods with In-Only and Out-Only By-Reference Parameters, 168
COM View and .NET View of Methods with Parameter Arrays, 441
COM view and the .NET View of Parameters, 165
COM View and .NET View of Properties, 442–444
COM View and the .NET View of the Same Fixed-Length Arrays, 157
COM View and the .NET View of the Same Methods with a Variety of String Parameters, 149
COM View and the .NET View of the Same Methods with By-Value and By-Reference Parameters, 164
COM View and the .NET View of the Same Methods with DECIMAL and CURRENCY Parameters, 148
COM View and the .NET View of the Same Methods with SCODE and HRESULT Parameters, 151
COM View and the .NET View of the Same Methods with VARIANT, IUnknown*, and IDispatch* Parameters, 146
COM View and the .NET View of the Same Simple Methods, 162
ComPlusInstaller.cs., 1098–1100
CopyFileEx Function Calls Back into Managed Code, 812–815
ComStream.cs., 883–889
Custom attributes written in C#, 29–30
CustomCCW Adapter Class, 932–943
CustomRCW Adapter Class, 924–932
Custom Marshaler Written in C++, 907–909
Custom Registration Required for Plugging Components into Windows Media Player, 572–574
D3DCOLORAUX from Listing 7.9, 373
DancingCatVisualization.cs, 1238, 1243
defining IWMPEffects Interface in C#, 971, 973
defining IWMPEffects Interface in VB .NET, 974
defining source interface, 602–603
DispHTMLStyleSheet interface, 1004–1006
DISPIDs for the EApplication Interface, 366, 370
Disposing an Object on its Last Release, 948–952
Dynamic PInvoke, 863–865
EmailAttack.cs., 1168, 1171, 1178, 1182
Ensuring that all PowerPoint RCWs are Collected, 303–304
Enums.cs., 1120
Exported Methods for the Seven Events, 488–489
Exporting an Assembly Containing a COM-Visible Type, 564–565
Exposing .NET events to COM without CLR, 594–597
Exposing Different Default Members than ToString to COM Clients, 575–578
Extracting Type Library Attributes, 1047–1048
FileWriter.cpp., 752–753, 755–759
FileWriter.h., 751–752, 754–755
Form1.cs., 128–137
FormattableClass.cls., 761, 763–764
FrontLayer.cs., 1154
GroundLayer.cs., 1153
Handling Variable-Length Structures Using Multiple Definitions, 847–849
Hooking Up Event Handlers to Objects, 233–235
Hosting the CLR and Using .NET Objects in Visual Basic 6 COM Clients, 461–463
Hosting the CLR and Using .NET Objects in Unmanaged Visual C++ COM Clients, 463–468