You are on page 1of 436

?

CD-ROM


I.
1



-




Windows SDK
Microsoft Visual Basic VBX
OLE!

Automation
?
ActiveX

- Smile
?
2 ActiveX OLE:
COM
IUnknown


REFIID, IID, GUID CLSID
HRESULT SCODE

IClassFactory
-
Automation IDispatch
,
Automation IDispatch
Automation

GetTypeInfoCount GetTypeInfo


ActiveX
ActiveX



ActiveX
Drag-and-drop
OLE ActiveX

www.books-shop.com

ActiveX
IDataObject
IRunningObjectTable
ActiveX
3 COM-
Automation


-


ActiveX


OCX 96



OCX 96
ActiveX
4 Microsoft ActiveX


C++
MFC
?
: CFirstApp
: CFirstCtrl
: CFirstPropPage
OCX 96 ActiveX MFC
Runtime- MFC
First

ActiveX Template Library (ATL)
ActiveX BaseCtl
ActiveX Java Visual J++
,
II. ActiveX
5






www.books-shop.com



6 :

( MFC)
PX-

( MFC)
7
ActiveX
MFC
HRESULT
HRESULT

, MFC
8


Request-
Before-
After-
Do-


, MFC Visual C++


First
MFC
9
?
MFC C++
ActiveX

First
MF
10





ActiveX




11
?


,

www.books-shop.com


MFC
,
12 ColeControl ColePropertyPage
ColeControl
Automation ,
Automation
,
, ActiveX
OCX 96 ActiveX ColeControl
ColePropertyPage
III. ActiveX
13 ActiveX Internet
ActiveX Web-
Web-


Web-
, Web
ActiveX Control Pad HTML Layout Control
14
Children




15
ActiveX


16

ActiveX
MFC



License
Web-
LPK-
LPK-
17 ISimpleFrameSite
ISimpleFrameSite
18 VBX Windows
VBX
OLE ControlWizard
VBX
,

VBM-

www.books-shop.com

,
Visual Basic API

Windows
Children
19 16/32- -

-
32- 16-

Unicode, ANSI MCBS



API
Windows

COM-
20 ActiveX



IPropertyNotifySink




IV.
Visual C++, MFC ATL: COM-
MFC
MFC
MFC
MFC

CWinApp
CWnd






COM, ActiveX OLE

ActiveX
COM-
ODBC
Visual C++ MFC
AppWizard
ClassWizard

AutoPro3
ActiveX Template Library (ATL)
COM

www.books-shop.com

www.books-shop.com


:
1.
2.

, .
Internet, World Wide Web ( ) .

-,
-, -.
,
Internet, ,
. ,
Internet
,
1984 P6-200 , 8088
4 .
.
, Internet Microsoft,
Internet Microsoft.
!
-
. ActiveX
, (COM). ,

. Web ,
. ,
, OLE,
ActiveX- .
, , ,
, .
:
1.

2.

, .
.

. ,
. OLE Controls Inside Out (Microsoft Press, 1995)
OLE MFC,
ActiveX Template Library (ATL),
ActiveX,
ActiveX.
, .
, ,
.

ActiveX
. ,
ActiveX,
. ,
.
, ActiveX

. C C++
! ,
ActiveX Microsoft Internet

www.books-shop.com

Explorer HTML-,
, ActiveX COM.
? ,
,
, , .

, ,
. ,
:

COM ,
.
ActiveX , COM , Internet
.
HTML,
ActiveX
,
.
ActiveX
. ,
.

. !
,
,
Microsoft Corporation

www.books-shop.com


, ,
. , - , .
,
. ,
, .
,
, .
Microsoft , ,
,
.
.

, . (Mark Daymond),
Microsoft ( ,
), -
. , , (Bill Champion),
, , . [
, - .]
, Microsoft.
(Lisa Theobald). ,
, -
(
, ).
(Mark Young), ,
. ,
,
. (Eric Stroo),
Microsoft Press, .
Microsoft, ,
(Dave Massy), (Victor Stone), (Jim Springfield),
(Christian Beaumont), (Jan Falkin), (John Elsbree), (Ian Ellison-Taylor), (Mike Blaszack), (Dean McCrory),
(nat Brown), (Charlie Kindel) (Gary Burd). (Eric Lang)
(Denis Gilbert)
, .
. ,
[ ],
.
, (Khan Busby)(, !)
, - . ,
.
, - .
, ,
.

%RRNVVKRS

piracy@books-shop.com


. ,
, .
, , ,
. ,
,
.
,
, .
ActiveX Template Library (ATL) 2.0 ,
Java. ,
, ATL 2.0 .
, ,
! , .
Microsoft Consulting Service (MCS) .

Microsoft Visual C++.

, 3.0.


Windows,
, Microsoft Visual
Basic, VBX. OLE
ActiveX. VBX
Visual Basic,
( 1). Visual Basic 1991
, VBX . VBX ( ActiveX),
,
. Visual
Basic, ( ) 16- .
Microsoft Visual C++ ,
VBX.
. , VBX, . .
, . , VBX,
32- -Intel . ?
VBX 32-
,
. ,
, -
32- .

.
, ,
. , .
ActiveX , VBX,
16-, 32- ( ,
). , .
ActiveX.
. ,
COM,
COM, ActiveX OLE ( ,
(Kraig Brockschmidt) Inside OLE, (Microsoft Press, 1996).
1 ,
,
. ,

www.books-shop.com

( !) ActiveX . 2
COM , . 3
COM, COM ActiveX
ActiveX. ActiveX
ActiveX, ,
2 3.
4
Microsoft ActiveX.
Visual C++ Microsoft Foundation Classes (MFC),
. ,
, 5. 6
, (, )
. 7
, ActiveX
VBX. 8
, . 9
. 10
. 5 10,
ActiveX, 10.
11 , ActiveX,
(property pages). 12 MFC,
, 13 Internet
World Wide Web. 14 , .
15 ,
( , ,
). 16 ,
COM,
17 , () ,
, - Windows. 18
, , VBX
ActiveX ActiveX,
Windows. 19 16- 32-
, . , 20
,
, .
.
Microsoft Visual C++ MFC.
,
.
KnowledgeBase (thread) COM.

?
ActiveX ;
COM, . ,
ActiveX , .<>
, ActiveX
C++. ,
ActiveX MFC,
C++.
Microsoft ActiveX Template Library (ATL). ATL
2.0, , Microsoft Press,
ActiveX, ,
, COM C++. ,
Java.
,
.
, - (
Microsoft Internet Explorer Visual Basic)

www.books-shop.com

ActiveX . MFC Visual C++ ,


. ActiveX MFC
Visual C++, .
COM ActiveX
, .
-, ActiveX,
C++,

,
, , .
,
.
,
ActiveX , ,
, .


ActiveX,
.
C++ Microsoft Windows SDK MFC 3.0
( MFC 3.0 Visual C++ 2.0).
MFC ( ),
.
COM ActiveX , .
. , ,
32- C++, MFC 4.0
. Visual C++ 4.2 Microsoft
Windows 95 Microsoft Windows NT 4.0 ( Intel Pentium).
Test Container, Visual C++,
Internet Explorer 3.0 4.0, Visual Basic 4.0 Visual C++ 4.2.
( ) Windows 95
Toshiba, Tecra 720CDT
48 ! Microsoft Word Windows 95,
- Word 97.
,
C++ , ,
. , , ,
.
32 Visual C++ 4.x Windows 95 Windows NT.

CD-ROM
CD-ROM make-
ActiveX Visual ++ 4.2.
. ,
. , , ActiveX
SDK Internet Explorer 3.0.
CD-ROM , - CD-ROM
. Windows 95 Windows NT
Setup. , ,
CD-ROM ( ).
SETUP.EXE CD-ROM.
Setup .

www.books-shop.com

, . -
,
.
, ,
. ,
( ,
):
void CmyClass::MemberFunction(LPCSTR lpszTitle, short nLength)

if (nLength == 0)
{
return;
}
for (int i = 0; i < nLength; i++)
{
if (lpszTitle[i] == A)
{
MsgBox("This string contains an A!");
break;
}
}

, ,
. ( ,
, )
. ,
, .
,
Microsoft. .
, MFC ATL , C
, , - (
).


Visual C++, (,
4.2), (, 4.x). .
, Windows 3.x 16- Windows (, 3.1
Windows for Workgroups). Win32, ,
Windows 95 OEM-, Windows NT
3.51 . Windows NT 4.0 Windows NT 3.51.
Win32s , ,
COM ActiveX.
, ,
.
, , ( ) . ,
.
:
ActiveX , ,
. , . :
, COM, , ?
, DLL-, - ?
. , Windows
Windows, ActiveX
Automation. Automation
,

www.books-shop.com

PostMessage SendMessage, .
10 .
,
ActiveX (
OCX 96). ,
, , , ActiveX
, Windows.
OCX 96
OLE (. 2 3).
,
ActiveX ,
. Microsoft
ActiveX. .
, , ActiveX ? ,
, 20,
ActiveX , IUnknown.
, .

www.books-shop.com

.
, , . ,
- , ,
.
, ,
, .
:
, .
(componentware).

Microsoft Visual Basic, VBX. , VBX ,
ActiveX
Visual Basic. Java, , ,
ActiveX ( OLE).
,
ActiveX C++
, Microsoft Foundation Classes (MFC).

1.1
:
, .
,
. .
, ,
, .
Microsoft, Office
(, Microsoft Word Microsoft Excel) (,
) !

1.2


. .
: -
? ,
.
,
. ( ,
C++) : ,
(, stdio C),
(, ).
,
(, printf) ,
.
-.

www.books-shop.com

,
. ,
. printf. ,
- , ,
-
. .
, printf? . ,
,
.
,
,
, .

1.3
( )
. ,
, .
, (
, ). -
.
, , .
,
( , ). :

.
(
!).
( . ).,

,
. , ,
: , ,
(. 1-1). HurtHuman (
, ).
HurtHuman.
HurtHuman, -
, , .
, .

. 1-1.
,
.
, (
), -. ,
, , . ,
HurtHuman ( HurtHuman
, , ).

www.books-shop.com

,
.
HurtHuman . ?
;
. ,
, . -
, ,
.
, ,
.

1.4 -
,
- , .
,
, . ,
,
. , ,
.
,
, . .
, ( ),
(
).
C++, , , .
. Java
, . Java C++ ,
Java C++.
Java.
C++:

class Insect
{
public:
virtual void HurtHuman(void);
};
class Wasp : public Insect
{
void HurtHuman(void);
}
Wasp *aWasp = new Wasp;
Insect *anInsect = aWasp;
anInsect -> HurtHuman();
, Insect Wasp, Wasp
Insect. HurtHuman. Wasp
aWasp. , Insect
Wasp. , C++ , anInsect
Insect, Wasp!
Insect::HurtHuman , HurtHuman
C++ Insect Wasp::HurtHuman.
.
, , ,
( ) .
, (, C++)
.

www.books-shop.com

1.5

, ,
. , C++ ,
.
,
.
,
. -
(
).
, C++ (
), , ,
,
. , ,
MFC-
. ,
. , C++
C++
. .
C++,
. ,
, . ,
COM- Microsoft . Microsoft ,
, C++, Java, Visual Basic ,
COM,
. .
, ,
, .
,
. ,
,
-
.

, ,
, , . , ,
.

1.5.1
-
(). ,
,
, .
,
,
. :
(, ),

www.books-shop.com

( ), (
) . . ,

, .
. ,
,
, .
,
. . ,
: , ,
.
, .
,
,
.
, , , .
, . ,
.
,
- , .
, , ,
(
). ,
, : ,
, ,
. ,
, ,
, , !
:
, ,
, .
?

1.5.2

, , , ,
,
. ,
.
Microsoft Windows ( ),
. ,
, ,
, .

1.6
,
, , .
? ,
. , ,
.
,
.
,
. .

1.7 Windows SDK


%RRNVVKRS

piracy@books-shop.com

(custom control)
, Windows-
.
Dialog Editor (
, Microsoft Windows Software Development Kit, SDK)

Windows. :
, (
, C C++),
. ,
(, ).
(, MUSCROLL
Windows 3.x SDK),
.

1.8 Microsoft Visual Basic VBX


Visual Basic ,
.
, .
Visual Basic ,
Visual Basic, , , VBX
( , ). VBX
DLL- Windows, (DLL,
, ,
).
Visual Basic 3.0 Control
Development Kit (CDK), VBX C.
Visual Basic, VBX, VBX-
. VBX- .
Visual Basic,
,
.
. ,
. , .
(, ), (,
). VBX ,

,
. ,
.
Windows SDK (, )
runtime-, VBX
.
Visual Basic VBX
VBX 3.0, .

, .
,
, .
VBX
, SDK, ,
Microsoft Windows. VBX Visual
Basic: ,
-, . .
VBX Microsoft -,
. VBX

, . ,
, Visual Basic, VBX

www.books-shop.com

. ,
75 VBX.
VBX , Visual Basic
, VBX.
VBX , .
, 16- VBX Microsoft Visual C++
. , Visual
Basic, VBX runtime-.
VBX
,
. , Byte 1994 , ,
- , VBX
. , VBX ,
.
VBX . -, VBX Visual Basic, ,
, . , ( VBX Visual
Basic 1.0 3.0 , ). , VBX Intel
80x86, 16- . 32-
, Intel. VBX
, .

1.9 OLE!
Microsoft VBX-
32- , .
Microsoft ,
OLE. 2 3, OLE .
OLE .
, ! , , OLE

.
.

: ,
, , .
( ,

, ).
Microsoft , OLE
,
16-, 32- .
OLE VBX
1993 1994 . Microsoft, .

, Visual Basic ,
. Microsoft OLE
. ,
. ,
OLE, Microsoft Access 2.0, 1994 .
, Access
Visual Basic 4.0 Visual FoxPro 3.0, 1995 .
1995 Visual C++ 4.0,

www.books-shop.com

OLE, .
OLE.
OLE 1996 ,
, OCX
96. OLE ActiveX ( , X !),
Microsoft Internet Explorer. , COM,
OLE ActiveX ( COM, ,
), Microsoft ActiveX
, Visual Basic Java
.

1.10
ActiveX .
, ActiveX
. ,
,
ActiveX (containment) ,

. ,
.
,
, ActiveX .

1.11 Automation
ActiveX
VBX, .
Automation, OLE Automation.
/
. ,
ActiveX , . ,
ActiveX ,
( )
, .
ActiveX . , ActiveX
, VBX.
, VBX. ActiveX ,
VBX ActiveX. ,
ActiveX
.
OLE Controls Developers Kit (OLE CDK), Visual C++ 2.0
. 1996 Microsoft ActiveX.
ActiveX
.
ActiveX :
,
.
, .
, Microsoft 1996 ,
ActiveX C++, .
, .
Microsoft Office ActiveX,
.
modus operandi,

www.books-shop.com

. ,
, , . 3 16
, ActiveX .
- ,
.
Internet (, World Wide Web). ActiveX
Web.
, , .
, , OCX 96
ActiveX , ,
ActiveX.
ActiveX ,
.
, - ActiveX .
,
. -
, .
, ActiveX ,
.
( ).

1.12 ?
, Java , Sun
Microsystems, Internet web-.
, Java ActiveX.
( Microsoft ). , Java,
ActiveX .
. ,
Java ActiveX (
, , ),
.
, ?
ActiveX - .
,
,
. OLE OCX
ActiveX.

1.13 ActiveX
Smile. ,
, .
, ActiveX C++
. MFC 4.0
, Visual C++ ++.
ActiveX (
), MFC,
C++ , C++.

1.14
Microsoft
Windows 95 Windows NT 4.x, ,
Visual C++. , Visual C++ 4.x.
Windows,
, .
Visual C++ 4.0, ,
OLE ActiveX.

www.books-shop.com

1.15 - Smile
ActiveX, (Eric
Lang) Microsoft Systems Journal. ,
(, )!
,
, .
\CODE\CHAP01\SMILE CD-ROM.
:
1.
2.
3.
4.
5.
6.
7.
8.
9.

File|Open Workspace SMILE.MDP.


Build|Rebuild All ,
.
Tools OLE Control Test Container.
Test Container Edit|Insert OLE Control
Smile Control.
Smile, Test Container.
, .
Test Container View|Event Log.
,
.
View|Properties.
, .
.
Edit|Properties|Smile Control Object.
,
Sad Test Containers Properties ( 0
FALSE, 1 TRUE).
.

! .

1.16 ?
ActiveX Test
Container. ,
, . 2 COM
ActiveX; . 3
COM, ,
, . , ?
:

, 2
3.
,
, 2 3 .
COM ActiveX,
, 2, 3.
MFC,
.

www.books-shop.com

ActiveX OLE:

1 , ActiveX .
.
ActiveX OLE. ,
(Kraig Brockschmidt) Inside OLE Microsoft Press
. ,
, .
, ActiveX.
ActiveX OLE ,
ActiveX, .
,
.

, ActiveX OLE ,
ActiveX
. , ,
, 2 3 .

1996 Microsoft ,
ActiveX. OLE,
, OLE
ActiveX. OLE
ActiveX.
(, OLE).
OLE, ActiveX,
, .

, (, Automation
ActiveX OLE), ,
, 3 .

2.1 COM
, ActiveX OLE, ,
COM. COM ,
. , COM-,
. ActiveX OLE
, COM .
COM ( , ActiveX OLE) ,
() (. 2-1). ActiveX OLE

www.books-shop.com

; .

, , C, . COM-
,
COM-. COM-
. , .

. 2-1. ( ActiveX)
, ActiveX OLE
. , ActiveX OLE
,
. , OLE Microsoft Excel
Microsoft Word. 2 3 , ActiveX
.
, ActiveX, .

Automation


. Automation
. Automation
ActiveX.

OLE

OLE, , , dragand-drop .

ActiveX

( Doc-.) OLE;
,
,
. ,
, .

ActiveX

,
. ActiveX
ActiveX, (
).
Automation , .

ActiveX

(
Automation).

ActiveX
Schedule+

Automation .

DCOM

ActiveX

,
.

OLE DB

,
.

ActiveX

, Visual Basic
Scripting Edition JavaScript.

OLE ( ActiveX) ,
,
- ActiveX. ActiveX ,
,
OLE.
. 2-2, ActiveX .
,
:

www.books-shop.com

ActiveX ,
,
.
ActiveX .
C++ (, Microsoft Foundation Classes, MFC)
. ActiveX
C++ Microsoft Windows.
(, Microsoft Visual Basic Java)
( ) ActiveX -
C C++. ,
ActiveX.

. 2-2. ActiveX

2.2 IUnknown
COM- IUnknown. COM I,
. , ,
MyInterface, IMyInterface. IUnknown :
AddRef, Release QueryInterface. COM-
IUnknown. C++
( , , ),
IUnknown. IUnknown :

class IUnknown
{
public:
virtual ULONG AddRef(void) = 0;

www.books-shop.com

virtual ULONG Release(void) = 0;


virtual HRESULT QueryInterface(REFIID riid,
LPVOID FAR *ppv) = 0;
};
. , IUnknown
.
, ,
.
, ,
- . ,
, C++ ( v-).
,
. V-
, . C
v- ; ,
. ,
C++ ( C, ,
C++). , Java ,
Visual Basic .
IUnknown COM-. AddRef
Release
COM-. QueryInterface ,
COM- , (,
). QueryInterface .
IUnknown
IMyInterface, IUnknown::QueryInterface.
, IUnknown::QueryInterface
IUnknown , .

QueryInterface
, ,
QueryInterface. ,
ActiveX .

.
, QueryInterface:

IUnknown QueryInterface,
, ,
IUnknown (. 2-3). ,
,
, QueryInterface IUnknown
. , IUnknown
IUnknown, ,
IUnknown.
QueryInterface , ,
. ,
.

,
. ,
,
. , .
, ,
, .
- , .

, .

www.books-shop.com

. 2-3. QueryInterface
QueryInterface , .
REFIID ( )
COM, . REFIID
, .
.
, REFIID , .

2.3
,
AddRef .
.
, Release.
. ,
. ,
C++;
. ,
,
. ,
.
, . ,
(,
C++),
. AddRef Release
IUnknown . MFC
- . , ,
Release
0.
. , ,
.
(DLL), .
DLL- , COM .
,
. , Java ,
. , Java Microsoft
QueryInterface .
, ;
NULL ,
.
IUnknown::QueryInterface
. QueryInterface
, ,
AddRef. ,
Release.

%RRNVVKRS

piracy@books-shop.com

OLE 2
Programmers Reference, Volume One (Microsoft Press). ,
,
. ,
, AddRef ,

. !
,
. ,
( , ), , ,
. Release
, 0,
(deadlock). , ,
, . ,
, .

2.4
ActiveX ,

, ,
. .
, (registry),
.
, .
, .
ActiveX, ,
. ,
, : CanMakeCoffee,
, , .
ActiveX
.

2.5 REFIID, IID, GUID CLSID


:
? . 57,
IUnknown REFIID (
, IID),
. REFIID C++ ( C)
IID. , , IID. IID
COM, GUID. GUID
- ,
. , GUID,
, GUID, - .
GUID , -,
(. GUID UUID).

GUID UUID
, OSF DCE RPC (,
Open Systems
Foundation!), GUID UUID, - .
, . GUID :

struct GUID
{
DWORD Data1;
WORD Data2;
WORD Data3;

www.books-shop.com

BYTE Data4[8];
}
, , GUID 16 . GUID
COM CoCreateGuid. GUID ,
GuidGen, Win32 SDK Microsoft Visual C++ 2.0 ,
AppWizard Visual C++. : , GUID,
, !
OLE, (Tony Williams),
GUID : CoCreateGuid
( )
( ) ,
. . OSF
DCE.
,
; ,

.
GUID 16- ,
32
, {37D341A5-6B82-101B-A4E3-08002B291EED}.
, GUID,
, .

, COM- IID.
, CLSID, ()
ActiveX, .
1, COM , , ,
CLSID. , CLSID
.

DCOM, ,
COM ,
. ,
, -
. DCOM ( COM).
Microsoft ,
, .
,
COM, OLE ActiveX ( , ,
). 1996 Microsoft
DCOM Windows NT 4.0. DCOM
ActiveX (
,
), DCOM
.
, . ,
RPC- (, RPC
) ,
DCE ( ) RPC.
RPC- , . RPC . ,
. , ,
RPC-.
,
.

www.books-shop.com

, .
,
.
. , COM
, DCOM .
, Microsoft.
, ,
. ; ,
,
. ,
(IDL),
.
, Microsoft
Windows. , Microsoft Excel Microsoft Word
, Excel Word ( ,
).
,
COM, .
( )
, .
( ), ,
, COM
RPC, LRPC (
). .
, (
,
inproc-, DLL-). .

. , ,
. ,
IDL RPC- RPC-,
.
.

2.6 HRESULT SCODE


, (
COM ActiveX) .
HRESULT (
, IUnknown::AddRef IUnknown::Release). HRESULT
, 32- ,
: (16 ), ,
, ( ). HRESULT,
, WINERROR.H. ,
HRESULT ,
SCODE. Windows NT 3.5 32 OLE, Microsoft SCODE HRESULT
. , SCODE
, HRESULT. SCODE HRESULT.
ActiveX HRESULT. GetScode
HRESULT SCODE, . ResultFromScode
(, HRESULT SCODE
; ). SUCCEEDED FAILED
HRESULT , .
MAKE_HRESULT HRESULT.
, HRESULT,
. HRESULT,

www.books-shop.com

, ActiveX;
OLECTL.H.

2.7
:
? . , Visual Basic,
:

Dim MyIP As Object


Set MyIP = CreateObject("MyApp.MyClass.1")
,
IDispatch (IDispatch
,
). IDispatch
Automation, ActiveX.

(
). Visual Basic Automation
( ).
.

, Visual Basic, COM-


. ,
C C++:
1.
2.

(Visual Basic) Object MyIP.


(Visual Basic) MyApp.MyClass.1 HKEY_
CLASSES_ROOT. , ,
CLSID.
3. (Visual Basic) CoCreateInstance CLSID IID
IDispatch ({00020400-0000-0000-C000-000000000046}, !).
4. (COM) CoGetClassObject CLSID IID
IClassFactory. ,
DLL- .
5. () CoRegisterClassObject COM ,
.
6. (COM) IClassFactory::CreateInstance IID, CoCreateInstance.
, IDispatch
.
7. (COM) IClassFactory::Release,
IClassFactory .
8. (Visual Basic) IDispatch
MyIP.

CoCreateInstance CoGetClassObject COM (


Co). , .
, IClassFactory.

2.8
,
, , ,
COM ActiveX. ; ,

www.books-shop.com

HKEY_CLASSES_ROOT, COM ActiveX.


HKEY_LOCAL_MACHINE\SOFTWARE\
Classes.
COM- ,
. (, Microsoft Excel)

. , COM- DLL- (
ActiveX), .
HKEY_CLASSES_ROOT ,
CLSID / DLL-,
(. 2-4). CLSID HKEY_CLASSES_ROOT
CLSID . Interface IID
( COM, ).
, CLSID HKEY_ CLASSES_ROOT\CLSID\{...}
ActiveX ActiveX ,
.

. 2-4.
Visual Basic
. CLSID COM API CoCreateInstance
IID , IDispatch.
CoCreateInstance CoGetClassObject, DLL-
, ,
. IClassFactory ( )
.
, :
, COM, ,
COM . CoGetClassObject
.
COM DLL, , HKEY_CLASSES_ROOT\CLSID\
{-} LocalServer32, LocalServer, InprocServer32
InprocServer. LocalServer ,
InprocServer DLL-. ,
. , 32- DLL-,

www.books-shop.com

InprocServer32.
( ).
DLL- , ,
(, ,
COM , DLL-)
, ,
.
, ,
. , COM
DLL- , ,
EXE-. 32- (, Windows 95) 16-
16-, 32- ; 32- .
,
. ,
, Win32 16- DLL- 32 , 16-
32- . 16-
32- , IDispatch.

2.9 IClassFactory
IClassFactory COM-.
. CoGetClassObject,
IClassFactory ,
. ( )
- , ,
, , .
C++. ?
?
,

,
.
IUnknown IClassFactory CreateInstance
LockServer:

class IClassFactory : public IUnknown


{public:
HRESULT CreateInstance(LPUNKNOWN pUnkOuter,
REFIID iid,
LPVOID *ppvObj);
HRESULT LockServer(BOOL fLock);
};
CreateInstance COM new C++
, ,
. CreateInstance .
IID, Visual Basic IID
IDispatch. ,
.
, CreateInstance ,
(, - ),
.
.
LockServer
. ,
, .
DLL-
. ,

www.books-shop.com

, . ,
LockServer .
, . -,
. -,
. ,
. LockServer ,
, . ,
,
, LockServer.

IClassFactory2
ActiveX IClassFactory:
IClassFactory2. , , IClassFactory2
( 16).
IClassFactory2 .
ActiveX ,
. IClassFactory
, , IClassFactory2.

2.10 -
1 -
. ,

. , ,
, ,
. runtime-
, COM .
.
, ,
. ,
( IClassFactory2
ActiveX).
COM . ,
.
, ,
. , ,
.
. ,
- .
,
QueryInterface ? ,
, ,
, .
,
, (,
IDispatch).
: ,
IUnknown, () IUnknown
. ,
IUnknown IUnknown.
IUnknown, .
, IUnknown.
IClassFactory:: CreateInstance.
NULL, . ,
CreateInstance ;
IUnknown
IUnknown (
IUnknown).

www.books-shop.com

IUnknown
. ( ),
IUnknown.
, ,
.
,
. ,
, .
, .
, , ,
. ,
.

2.11 Automation IDispatch


Automation. ,
ActiveX. Automation
(, Visual Basic)
( Microsoft Visual Basic !),
Java, C C++.
Automation . Automation
ActiveX, . Automation
, ActiveX COM,

. , Automation,
3, , ,
.

2.12 ,
Automation ,
, . :

, ,
.
Automation
.

. , ,
.
,
.
Automation
, Automation.

, ,
, , .
,
, (, ).
,
. .
Automation
(,
). ,
. ,
, ,
Automation. , , ,
, . . ,
, -

www.books-shop.com

, .
.
Automation ,
, , .
Automation IDispatch,
, Visual Basic.
Automation ,
IDispatch, .
.
Automation ,
. ,
ActiveX, .

2.13 Automation IDispatch


, IDispatch,
Automation. IDispatch
( , ).
Invoke.
IUnknown, IDispatch : GetIDsOfNames, GetTypeInfo,
GetTypeInfoCount Invoke. Visual Basic
Automation :

MsgBox MyIP.SomeProperty
, IDispatch
MyIP, SomeProperty. Visual Basic
. :
1.
2.
3.

(Visual Basic) MyIP::GetIDsOfNames dispid


( ) SomeProperty.
(Visual Basic) MyIP::Invoke dispid SomeProperty.
(Visual Basic) , ;
Visual Basic , ,
Invoke.

IDispatch::GetIDsOfNames
Automation IDispatch. ,
. Automation ,
, ,
.
:
, , . .
, ,
runtime-. ,

,
, . Visual Basic 3.0
,
, , . Automation
.
( v-).
(dispid)
,
Automation ,
IDispatch (
, dispid) . ,
Automation
dispid. dispid,

www.books-shop.com

Automation, IDispatch GetIDsOfNames.


GetIDsOfNames dispid
.
GetIDsOfNames , , dispid
. Automation,
DISP_E_UNKNOWNNAME, ,
, dispid DISPID_UNKNOWN (1).
?
, .
Automation
, .
, . Automation
,
. MyMethod
, ,
:

If MyIP.MyMethod (1, "Hello") = False Then


Automation , ( 1),
( Hello). ,
dispid , IDispatch::Invoke .
( Visual Basic):

If MyIP.MyOtherMethod (String := "Hello") = False Then


, MyOtherMethod ,
Automation , MyOtherMethod
String. , dispid String
Invoke.

dispid, IDispatch::Invoke Automation.
, ( ) .
, ,
( ,
). Automation
.
IDispatch::Invoke Automation.
:

dispid .
.
, ( ).
EXCEPINFO.

. Invoke
DISP_E_EXCEPTION, , ActiveX .
Automation ActiveX,
- .
( , ),
( ). EXCEPINFO
.
(, , ,
);
,
; , , HRESULT,
On Error Goto Visual Basic. Automation
Visual Basic,
EXCEPINFO .
, runtime ActiveX.
%RRNVVKRS

piracy@books-shop.com

, Invoke,
VARIANT. (union C)
, IDispatch (, , ).
, .
VARIANT Invoke
, ,
.

2.14 Automation
IDispatch
. ,
Visual Basic, . ,
IDispatch::Invoke ,
. ? ,
VARIANT,
.
,
( Automation).
IDispatch::Invoke .
Automation
.
IDispatch Automation, .
Automation ( ,
). IDispatch
, IDispatch
.
.
,
( ) IDispatch, . ,
,
Automation.
v-,
v- .
,
IDispatch
, v-. . 2-5
.
IDispatch::Invoke ,
, EXCEPINFO.
, ,
IDispatch::Invoke,
. , EXCEPINFO Invoke,
Automation ,
(
9).

www.books-shop.com

. 2-5.

2.15
.
( ) ,
, dispid ,
, .
.
-
(ODL), MkTypeLib. ,
Microsoft ODL , COM, MIDL
( Microsoft). MIDL, Win32 SDK
Windows NT 4.0 , ODL
( MIDL ).
MkTypeLib .
Automation,
,
(, Microsoft Excel).
ClassWizard Microsoft
Visual C++,
- ( RPC-),
Automation.
, Automation
ClassWizard, Visual C++,
,
. ,
.
Visual C++
, -.
Visual Basic. ,
Visual Basic .
( ) Dim x As Object:

Dim x As Object
Set x = CreateObject("MyObject.1")
x.SomeProperty = 3
.
: , MyObject.1
SomeProperty 3.
, runtime-. :
dispid SomeProperty (
IDispatch::GetIDsOfNames), .
, MyObject.1
.

www.books-shop.com

Visual Basic 4.0 ,


,
, CMyInterface:

Dim x As New CMyInterface


x.SomeProperty = 3
,
CMyInterface SomeProperty.
New Visual Basic, (
CoCreateInstance, ),
, SomeProperty. ,
CMyInterface , Visual
Basic v-.
Automation,
, .
(IDispatch )
.
( ActiveX).
TypeLib HKEY_CLASSES_ROOT ,
GUID . , ,
.
, CLSID AutoProg (. )
:

HKEY_CLASSES_ROOT\CLSID\{AEE97356-B614-11CD-92B408002B291EED}\TypeLib = {4D9FFA38-B732-11CD-92B4-08002B291EED}
,
. ActiveX
.
ActiveX. ActiveX SDK (
CD-ROM), , Automation MIDL.
COM-. ,
ITypeLib ITypeInfo , ICreateTypeLib
ICreateTypeInfo .
MIDL MkTypeLib IDL ODL .

2.16 GetTypeInfoCount GetTypeInfo


, , IDispatch
.
GetTypeInfoCount GetTypeInfo. GetTypeInfoCount
IDispatch, GetTypeInfo ITypeInfo
.
Automation IDL/ODL
, .
Automation Win32 SDK Windows NT 3.51,
Windows 95 , Visual C++ 4.2
. .
Automation , . ,
Visual Basic 4.0 , OLE .
Visual Basic Automation ,
Visual C++ - Microsoft Office.

2.17

www.books-shop.com

, ,
.
. , ,
, .
( ),
?
(persistent),
. .
,
.
( ),
, .
, !

(serialization),
() .
. MS-DOS Win32
, .
, .
(
!).
, ,
.
.
- .
, Windows NT,
. (COM)
,
,
. ActiveX - (storages),
(streams). ( )
,
MS-DOS ( Win32).
IStorage IStream.
IPersistStorage
ActiveX IPersistStream, .
ILockBytes ( , )
, .
,
, ( ).
: Microsoft Word
Microsoft Excel, Word ,
Excel .
,
, IStorage Excel
. , Excel
, .
, OLE
. ,
OleSave. OleSave
IPersistStream ; IStorage,
; , , ,
.
, ,
.

. IStream IStorage

www.books-shop.com

( ),
.

2.18
COM ,
. , ,
, ,
.

. , IStorage::Commit,
IStorage::Revert.
.
,
. ,
.
, .
, , !
, IStream Commit Revert,
OLE .

2.19 ActiveX
ActiveX .
, , ,
. ,
IPersistStorage,
. ActiveX
,
.
IPersistStream .
IPersistStreamInit.
.
, , , IPersistStreamInit
ActiveX 3.
,
, .
IPersistPropertyBag, , ,
.
.
World Wide Web Internet ,
, . ,
, .
, , ,
. Internet- ,

9600, 14 400 ( ) 28 800 .
(, , ), ,
( , . .)
.
, , , -
Web-.
, ,
.
, 28
800 , Microsoft , (datapath),
.
, .
, URL,
.

www.books-shop.com

, ( )
. .
( Web-
) (thread)
. , ,
, .
, .
(, )
.
,
, !
, ,
, URL-.
, .

2.20 ActiveX
OLE
, , , .
Microsoft Word,
Microsoft Excel.
? ,
. ,
, ,
(
). ,
. OLE ActiveX
.

2.21
ActiveX, ,
, ActiveX (
OLE) ,
. , Excel Word
Word.
OLE Excel, ,
,
. ActiveX ,
.
- (Excel) (Word).
-.
, ,
-. ,
.
(
, ,
ActiveX).
ActiveX
ActiveX, ActiveX OLE.
OLE - ,
OLE . ,
ActiveX, ActiveX
. ActiveX,
ActiveX. 1995

OLE 2.0 ,
, . .

www.books-shop.com

. ,
, .
1995 Microsoft Office 95,
Office Binder. ActiveX
(, Doc- ). Binder (
) .
, ,
Doc- Word, Excel, PowerPoint
Office. ?
,
. , Binder
. Word, Excel . .
. ,
Office.
, Binder :
, , Binder -.
, . -,
( , ),
Binder. -, Binder
, . ,
Help ; Binder,
-. , Binder Section,
, Binder.
. .
, Binder ,
. ,
Web ,
. , Web-,
Word. , Word .
, Word
, . ,
, Word
ActiveX / . , Word?
, Microsoft (
!), ,
Word.
, .
, , Web.
. , Word
Excel , Word Excel.
Next Previous , ,

, Web- ( )
Windows Explorer.
, HTML, Web ,
ActiveX.
.
.

(container)

, (, Microsoft Word).

,
ActiveX , Binder.

(object
application)

, , ;
.

www.books-shop.com

ActiveX

, ,
ActiveX,
.

(embedding)

,
(, , );
, .
Excel Word,
.

(linking)

,
; ,
.
,
.

(compound
document)

, /
, .
;
, . .

2.22
. , , Excel
Word, . , , ?
, , , Word
. Word
Excel. Excel
.
-.
Word, Excel ,
Excel . ,
, ,
. ,
ActiveX, .
, (presentation data).
.
Windows ( ),
.
, ,
(object handler). DLL-,
, -,
.


OLE , .
.
OLE , InprocHandler / InprocHandler32
HKEY_ CLASSES_ROOT\CLSID\{...}. ,
. ,
DLL- ( ),
. , ,
, ( )
.

, , Excel. ,
,
,
. ,
. Word, OLE, Excel.

www.books-shop.com

Word .
, Excel ,
. Excel /Embedding (,
, Excel ).
Excel .
, , .
, ,
, , , ,
. Excel. Excel
Word ,
, Word.
Word Excel , .
Word , Excel
Word,
.
Excel, . , Excel
UI- ( UI ). UI , ,
. ,
ActiveX.
, ,
.
( ).
,
( Edit), UI- .
,
. OLE
. .
, ,
.
OLE , , ,
Word Excel. , ,
.
OLE ActiveX .
ActiveX .
,
. ,
. ,
, .
, !


ActiveX, , ( DLL) . ,
. , ActiveX OLE,
. , ActiveX,
(, ) .

2.23

.
. ,
.
, OLE
, .

www.books-shop.com

,
, ,
, . ,
.

2.24 ActiveX
ActiveX.
, ,
-. ,
, ,
/ .
, Word
, Word, c
. , , Web
( ).

2.25 Drag-and-drop
ActiveX
, Excel Word.
: OLE? , drag-and-drop OLE,
File Manager Microsoft Windows 3.1.
File Manager ,
(drop target). WM_DROPFILES.
drag-and-drop ,
. ,
drag-and-drop , ,
, drag-and-drop
. , drag-and-drop
. OLE , Microsoft
drag-and-drop OLE.
Drag-and-drop OLE ,
. ,
(cut-and-paste), ,
. Clipboard ,
, drag-and-drop OLE
, File Manager. Drag-and-drop

ActiveX.
drag-and-drop OLE . ,
,
IDropSource IDataObject (
). ,
IDropTarget IDataObject.
IDropSource, IUnknown, :
QueryContinueDrag GiveFeedback. QueryContinueDrag ,
- , .
GiveFeedback , -
. IDropSource ,
- , ?
, API DoDragDrop.
IDataObject IDropSource ,
, .
, ,
RegisterDragDrop -.
IDrop Target. IDropTarget
. DragEnter, DragOver DragLeave
-.
%RRNVVKRS

piracy@books-shop.com

, IDropTarget::Drop .
IDataObject .

2.26 OLE ActiveX


, OLE ActiveX,
IOle. OLE IOleAdviseHolder, IOleCache,
IOleCache2, IOleCacheControl, IOleClientSite, IOleContainer, IOleInPlaceActiveObject,
IOleInPlaceFrame, IOleInPlace Object, IOleInPlaceSite, IOleInPlaceUIWindow, IOleItemContainer,
IOleLink, IOleObject IOleWindow! ActiveX
IOleCommand Target, IOleDocumentSite, IOleDocument, IOleDocumentView, IPrint
IContinueCallback. , ( !)
IDataObject, .
.
OLE ActiveX : /
, .
,
.
. ,
- ( ,
).
: (, ,
), Clipboard, .
,
, .
Insert Object,
- (, Microsoft Office
Word, Excel, Access . .). ? , ,
OLE .

. OLE ? ,
, ,
OLE. OLE
HKEY_CLASSES_ROOT\CLSID\{...} Insertable.
, ,
OLE
Insert Object.

.
1996
Insertable . ,

. , , CLSID Insertable,
, . ,
, , Insertable.

,
, CoCreateInstance. OLE
API OleCreate, .
OleCreate.
CoCreateInstance , CLSID (
Insert Object) REFIID (
IOleObject).
IUnknown, .
OLE ,
, IStorage ,

www.books-shop.com

. , OleCreate
IOleClientSite, IOleObject::SetClientSite
. , ?
,
.
- ,
.
. :
- IOleObject
, . .
?
. , , .
,

IOleClient. ,
IAdviseSink, .
, ,
IOleObject, IDataObject, IOleCache, IPersistStorage IViewObject.
?
OLE. , IViewObject (
) , OLE
OLE32.DLL.
:

IOleObject

.
.

IDataObject

(
).

IViewObject

IDataObject,
, . IViewObject HDC
( ),
. , IViewObject ,
DLL
,
OLE!

.
IPersistStorage IPersistStorage ,
IStorage.
IOleCache

OLE. ,
( )
, .

OLE ,
. ,

:
IOleInPlacexxx. , IOleInPlaceActiveObject::TranslateAccelerator,
,
-. ,
, . ,
ActiveX, ,
IOleInPlaceActiveObject .
ActiveX
,
ActiveX

www.books-shop.com

. , ActiveX
, .
Word , , . .
, .


.
( ),
(
IOleCommandTarget
) ,
.
Automation.
.

IOleDocumentSite

. ,
ActivateMe,
.
,
. , ActiveX
,
, .

IContinueCallback

,
, .
,
,
.

ActiveX, .

IOleDocument

ActiveX
.
, ,
.
,
,
,

,
.

IOleDocumentView

,
,
.
- ,

, UI-
.

IPrint

()

.
Print
IcontinueCallback , ,
.

IOleCommandTarget


.
( ),

( ) ,
.
Automation.

www.books-shop.com


.
IEnumOleDocumentViews

OLE, ,
ActiveX.

2.27 ActiveX
,
ActiveX OLE, .
, , .
ActiveX,
, , Automation.
IDataObject; , .

2.28 IDataObject
IDataObject OLE,
, UDT. ,
. ,
, Clipboard,
IDataObject,
.
.
IDataObject , Clipboard,

. IDataObject
: FORMATETC STGMEDIUM. , FORMATETC (
), , IDataObject. ,
Clipboard ,
IDataObject FORMATETC.
Clipboard, FORMATETC
- ( ) .
, ( ), (
), .
,
( ), , IStorage, IStream, .
, STGMEDIUM,
. , (
FORMATETC); (
, IStream);
IUnknown. NULL,
( IUnknown::Release).
IDataObject, .

GetData
GetDataHere

.
.
GetData, ,
, .

QueryGetData , GetData FORMATETC.


, IDataObject
EnumFormatEtc .
IEnumFormatEtc.
DAdvise

-,
.
IAdvise Sink.

www.books-shop.com

,
, IDataAdviseHolder.
IMoniker
, OLE, ( ,
!). OLE 1993
Microsoft , (
). , ,
-. .
ActiveX , IMoniker
, .
, RegisterActiveObject
, Automation. , ,
, Automation
.
, ActiveX
. .
,
.
. OLE 2.0 :


.
;
.
,
.
,
.
.

, IMoniker,
(binding). , .
, IMoniker::BindToObject , ,
, . IMoniker::BindToStorage
, . Load
.
: , OLE,
. , OLE.
!
. , ,
URL. , URL
,
,
. , Microsoft
. , ,
URL-.
, , ,

, IBindStatusCallback. ,
( ),
. , OnStartBinding
, OnObjectAvailable , ,
OnStopBinding . GetPriority
. ,
,
. ? Web-

www.books-shop.com

. , (
, ) ,
(, BLOB-.
( ),
,
. , ,
() ; ,
, . ,
(,
Web-
).
.
OnStartBinding, ,
IBinding.
, .
, ActiveX
. , IPersistMoniker.
( IPersistxxx),
.
, IAsyncMoniker.
( IUnknown), ,
. QueryInterface
IAsyncMoniker. ,
, .
, URL-
? ,
. , URL-
URL ( ).
URL .
CreateURLMoniker , URL-.
FORMATETC ,
MIME , CF_MIME_POSTSCRIPT, RegisterMediaTypes
.
, URL-
, HTTP-.
QueryInterface IBindStatusCallback, .
, :
IAuthentificate IHttpNegotiate.

2.29 IRunningObjectTable
, ROT,
,
. OLE,
, , .
API GetRunningObjectTable IRunningObjectTable,
, ,
, IEnumMoniker.
ROT. ,
IUnknown .
Microsoft Visual C++ IRotView,
ROT.

2.30 ActiveX

www.books-shop.com

ActiveX OLE,
.
ActiveX , ,
3
4.
, ?, 3.

www.books-shop.com

COM-

ActiveX COM,
.
, Automation (
ActiveX!), ,
.
ActiveX , OLE COM
.
COM OLE -
DLL- COM OLE.
, OLE ,
, DLL-,
.

Microsoft Foundation Classes (MFC), Microsoft Visual Basic 5.0,


Microsoft Visual J++ ,
4,
, ActiveX.
, ,
, .
, 4.
,
.

Unicode

8-
IBM PC ANSI. ,
, ,
(, ,
, ).
, ,
(
Microsoft Windows)
() .

MCBS ( , multi-byte
character set).
Unicode
.
Unicode , .
Unicode 16 ,
MCBS ( Unicode
),
65,536 .

www.books-shop.com

Microsoft.
Unicode
. , 32 127
ASCII-.
, . .
:
Unicode, ?
Microsoft Windows NT
Unicode. ,
Unicode, ASCII- ANSI-
Unicode.
, . . Unicode.
32- COM Unicode.
, ,
Win32 API (, ,
Windows 95) ANSI.
COM Unicode. -,
. 96, ActiveX API
Unicode.
Win32; .
,
Unicode ( ActiveX
API), Unicode,
32- Windows NT,
.
?
, , , 32- COM
Unicode ASCII-.

, ANSI
Unicode ActiveX. Windows 95
Unicode
API, Unicode
. , Unicode-
Windows NT, ,
. :
Unicode
, Windows NT.
ANSI Unicode-
Windows NT.
Unicode- Microsoft Visual C++
:
1.

2.

,
char char* WCHAR.H
, TCHAR LPTSTR ( CString MFC
Unicode, MFC 3.0 ,
CString ).

, ANSI Unicode.
,
,
ANSI Unicode. ,
:

_T("String")
3.

_MBCS
_DBCS _UNICODE.

www.books-shop.com

4.
5.

wWinMainCRTStartup.
.

, Unicode,
16- Visual C++ 1.51 .
,
16- . 16- Windows- 16 , Windows NT,
Unicode.
,
,
Automation,
.

3.1 Automation
,
, . ,
C++,
Automation C++.
, Salary, Payraise. Salary
, ; Payraise
Salary. -
!

Visual Basic. ,
Visual Basic for Applications:

Sub TestObj()
Dim x As Object
Set x = CreateObject("AutoProg.Cauto.2")
x.Salary = 1234
MsgBox x.Salary
x.Payraise 1
Msgbox x.Salary
Set x = Nothing
End Sub
, Salary
1234, ( ,
). Payraise 1,
(
). ,

Set x = Nothing
Visual Basic Release
IDispatch . ,
AddRef CreateObject.
0.
(
) v- (
).
Visual Basic, :

Sub TestObj()
Dim x As New CAuto
x.Salary = 1234

%RRNVVKRS

piracy@books-shop.com

MsgBox x.Salary
x.Payraise 1
MsgBox x.Salary
End Sub

Dim x As New CAuto


Dim x As Object
Set x = CreateObject("AutoProg.Cauto.2")
, x CAuto.
, CAuto ,
Visual Basic
, . , Visual Basic
, ,
v-, IDispatch.
, Visual Basic
IDispatch::Invoke
!
, . MFC
, ,
Windows, runtime- C.
EXE- (release)
9 . C++ (,
ActiveX Template Library Microsoft),
.
, , OLE Controls Inside Out,
,
. ,

API .
,
Automation. ,
!
,
(
),
, (ODL-) ,
. ,
,
, -
. , .

3.2
Automation
Microsoft Foundation Classes ( MFC),
Windows,
- ActiveX, MFC.
, ,
(IClassFactory IAuto).
, ActiveX API,
IDispatch
.

www.books-shop.com

,
.

MFC (
ActiveX MFC, A),
,
Windows. (Jeff Prosise) Programming
Windows 95 with MFC (David Kruglinski) Inside Visual
C++ MFC.
, CWinApp ,
(, Windows
), CFrameWnd
. InitInstance ExitInstance ,
CWinApp (CAutoProg),
,
.
InitInstance .
,
, -
( ,
- ). ExitInstance ,
C++.
, (
), Visual++ 4.x.
16-
( 16 ). , 32,
Win32 , C++
( ).
, MFC TRY, CATCH END_CATCH
C++ try catch.
,
.
Automation,
AutoProg, 3-1.
AutoProg 3-2.

make- AutoProg
\CODE\ CHAP03\ AUTOPROG CD-ROM.

3-1. AutoProg, AUTOPROG.H

class CAutoDisp : public IDispatch


{
public:
STDMETHOD (QueryInterface)(REFIID riid, void **ppv);
STDMETHOD_ (ULONG, AddRef)(void);
STDMETHOD_ (ULONG, Release)(void);
STDMETHOD (GetTypeInfoCount)(UINT *pctinfo);

www.books-shop.com

STDMETHOD
STDMETHOD
*rgszNames,

(GetTypeInfo)(UINT itinfo,
LCID lcid,
ITypeInfo **pptinfo);
(GetIDsOfNames)(REFIID riid, LPOLESTR
UINT cNames, LCID

lcid,
STDMETHOD

STDMETHOD
STDMETHOD
STDMETHOD

DISPID *rgdispid);
(Invoke)(DISPID dispidMember, REFIID riid,
LCID lcid, WORD wFlags,
DISPPARAMS *pdispparams,
VARIANT *pvarResult,
EXCEPINFO *pexcepinfo,
UINT *puArgErr);
(put_Salary)(long lSalary);
(get_Salary)(long *lSalary);
(Payraise)(long lSalaryIncrement);

CAutoDisp() {m_ulRefs = 0; m_lSalary = 0;}


private: ULONG m_ulRefs;
long m_lSalary;
};
class CAutoCF : public IClassFactory
{
public:
STDMETHOD (QueryInterface)(REFIID riid, void **ppv);
STDMETHOD_ (ULONG, AddRef)(void);
STDMETHOD_ (ULONG, Release)(void);
STDMETHOD (CreateInstance)(IUnknown *punkOuter,
REFIID riid, void **ppv);
STDMETHOD (LockServer)(BOOL fLock);
CAutoCF() {m_ulRefs = 1; m_pAuto = 0;}
~CAutoCF();
private:
ULONG
m_ulRefs;
CAutoDisp *m_pAuto;
};
class CAutoProg : public CWinApp
{
public:
DWORD m_dwAutoCF;
DWORD m_dwRegObj;
LPTYPEINFO GetTypeInfo(void) const {return m_ptinfo;}
protected:
virtual BOOL InitInstance(void);
virtual int ExitInstance(void);
BOOL CreateClassFactory(void);
BOOL RegisterTypeLibrary(void);
private:
BOOL
m_fOleInitSuccess;
CAutoCF
*m_pAutoCF;
LPTYPEINFO m_ptinfo;
};
3-2. AutoProg, AUTOPROG.CPP

//AEE97356-B614-11CD-92B4-08002B291EED - CAuto
//4D9FFA39-B732-11CD-92B4-08002B291EED - IAuto
#include

www.books-shop.com

#include
#include
#include "autoprog.h"
CAutoProg theProg;
DEFINE_GUID(CLSID_CAuto, 0xAEE97356, 0xB614, 0x11CD, 0x92,
0xB4,
0x08, 0x00, 0x2B, 0x29, 0x1E,
0xED);
DEFINE_GUID(IID_IAuto, 0x4D9FFA39, 0xB732, 0x11CD, 0x92, 0xB4,
0x08, 0x00, 0x2B, 0x29, 0x1E,
0xED);
BOOL CAutoProg::InitInstance(void)
{
// OLE
m_fOleInitSuccess = TRUE;
HRESULT hRes = OleInitialize(NULL);
if (FAILED(hRes))
{
m_fOleInitSuccess = FALSE;
return FALSE;
}
//
m_ptinfo = 0;
if (RegisterTypeLibrary() == FALSE)
{
return FALSE;
}
//
if (CreateClassFactory() == FALSE)
{
return FALSE;
}
//
m_pMainWnd = new CFrameWnd;
((CFrameWnd *)m_pMainWnd) -> Create(NULL, _T("AutoProg
Server"));
m_pMainWnd -> ShowWindow(SW_SHOWMINNOACTIVE);
m_pMainWnd -> UpdateWindow();
return TRUE;
}
int CAutoProg::ExitInstance(void)
{
delete m_pMainWnd; // ,
//

if (m_ptinfo)
{
//
m_ptinfo -> Release();
}
if (m_fOleInitSuccess)
{
OleUninitialize();
}
return 0;

BOOL CAutoProg::CreateClassFactory(void)
{
m_pAutoCF = 0;
BOOL bResult = TRUE;

www.books-shop.com

try
{
m_pAutoCF = new CAutoCF;
}
catch (CMemoryException *e)
{
bResult = FALSE;
e -> Delete();
}
if (FAILED(CoRegisterClassObject(CLSID_CAuto,
m_pAutoCF,
CLSCTX_LOCAL_SERVER,
REGCLS_SINGLEUSE,
&m_dwAutoCF)))
{
bResult = FALSE;
}
m_pAutoCF -> Release();
return bResult;
}
BOOL CAutoProg::RegisterTypeLibrary(void)
{
BOOL bSuccess = FALSE;
char strPathName[_MAX_PATH];
LPTYPELIB ptlib = NULL;
::GetModuleFileName(m_hInstance, strPathName, _MAX_PATH);
//
// TLB :-)
strPathName[::lstrlen(strPathName) - 3] = \0;
::lstrcat(strPathName, "TLB");
// Unicode
LPWSTR wszPath = new WCHAR[_MAX_PATH];
if (MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED,
(LPCSTR)strPathName, -1, wszPath, _MAX_PATH) != 0)
{
if (SUCCEEDED(LoadTypeLib(wszPath, &ptlib)))
{
//
if (SUCCEEDED(RegisterTypeLib(ptlib, wszPath,
NULL)))
{
bSuccess = TRUE;
}
//
//
ptlib -> GetTypeInfoOfGuid(IID_IAuto, &m_ptinfo);
ptlib -> Release();
}
}
delete [] wszPath;
return bSuccess;
}
////////////////////////////////////
//
CAutoCF::~CAutoCF(void)
{

www.books-shop.com

CoRevokeClassObject(theProg.m_dwAutoCF);
}
STDMETHODIMP_ (ULONG)CAutoCF::AddRef(void)
{
return ++m_ulRefs;
}
STDMETHODIMP_ (ULONG)CAutoCF::Release(void)
{
if (m_ulRefs == 0)
{
delete this;
}
return m_ulRefs;
}
STDMETHODIMP CAutoCF::QueryInterface(REFIID riid, void **ppv)
{
if (riid == IID_IUnknown || riid == IID_IClassFactory)
{
AddRef();
*ppv = this;
return S_OK;
}
return E_NOINTERFACE;
}
STDMETHODIMP CAutoCF::CreateInstance(IUnknown *, REFIID riid,
void **ppv)
{
// ? -
if (m_pAuto == 0)
{
try
{
m_pAuto = new CAutoDisp;
}
catch (CMemoryException *e)
{
e -> Delete();
return E_OUTOFMEMORY;
}
}
return m_pAuto -> QueryInterface(riid, ppv);
}
STDMETHODIMP CAutoCF::LockServer(BOOL)
{
return S_OK;
}
//////////////////
// IDispatch
STDMETHODIMP CAutoDisp::QueryInterface(REFIID riid, void
**ppv)
{
if (riid == IID_IAuto ||
riid == IID_IUnknown ||
riid == IID_IDispatch)
{
*ppv = this;
AddRef();
return S_OK;

www.books-shop.com

}
return E_NOINTERFACE;

STDMETHODIMP_ (ULONG)CAutoDisp::AddRef(void)
{
return ++m_ulRefs;
}
STDMETHODIMP_ (ULONG)CAutoDisp::Release(void)
{
if (m_ulRefs == 0)
{
theProg.m_pMainWnd -> PostMessage(WM_CLOSE);
delete this;
}
return m_ulRefs;
}
STDMETHODIMP CAutoDisp::GetTypeInfoCount(UINT *pctinfo)
{
*pctinfo = 1;
return NO_ERROR;
}
STDMETHODIMP CAutoDisp::GetTypeInfo(UINT itinfo,
LCID, ITypeInfo **pptinfo)
{
*pptinfo = NULL;

if (itinfo)
{
return DISP_E_BADINDEX;
}
theProg.GetTypeInfo() -> AddRef();
*pptinfo = theProg.GetTypeInfo();
return NOERROR;
STDMETHODIMP CAutoDisp::GetIDsOfNames(REFIID,
*rgszNames,

LPOLESTR
UINT cNames,
LCID, DISPID

*rgdispid)
{
return DispGetIDsOfNames(theProg.GetTypeInfo(),
rgszNames, cNames,
rgdispid);
}
STDMETHODIMP CAutoDisp::Invoke(DISPID dispidMember,
REFIID, LCID, WORD
wFlags,
DISPPARAMS
*pdispparams,
VARIANT *pvarResult,
EXCEPINFO *pexcepinfo,
UINT *puArgErr)
{
return DispInvoke(this, theProg.GetTypeInfo(),
dispidMember,
wFlags, pdispparams, pvarResult,
pexcepinfo, puArgErr);

www.books-shop.com

}
STDMETHODIMP CAutoDisp::put_Salary(long lSalary)
{
m_lSalary = lSalary;
return NO_ERROR;
}
STDMETHODIMP CAutoDisp::get_Salary(long *lSalary)
{
*lSalary = m_lSalary;
return NO_ERROR;
}
STDMETHODIMP CAutoDisp::Payraise(long lSalaryIncrement)
{
m_lSalary += lSalaryIncrement;
return NO_ERROR;
}

Automation. .
. ,
: CAutoProg, CutoCF CAutoDisp. CAutoProg
, CWinApp. ,
CAutoProg
CreateClassFactory (
, . 107) RegisterTypeLibrary (
,
). CAutoCF
IClassFactory Automation,
IClassFactory. ,
IClassFactory.
OLE: STDMETHOD
STDMETHOD_. (
pascal Win16 stdcall Win32),
, HRESULT (
, ActiveX OLE API), ,

. ,

STDMETHOD (QueryInterface)(REFIID riid, void **ppv);


QueryInterface,
HRESULT , REFIID void **,

STDMETHOD_ (ULONG, AddRef)(void);


AddRef, ULONG
( - )
.
, COM ActiveX.
CAutoCF ,
, m_ulRefs m_pAuto.

( , 1),
, .

3.3

CAutoDisp.
IDispatch

www.books-shop.com

IDispatch.
IUnknown IDispatch, ,

Salary, Payraise. ,
Salary ( ,
), put_Salary,
get_Salary.

, .
Payraise , Payraise.
, m_ulRefs,
, m_lSalary, Salary.
, ,
0.
, , ,
. ,
, ,
(
Visual Basic):

value = x.Salary
, ,
, IDispatch,
HRESULT.
,
. ,

retval.
,
HRESULT DISP_E_EXCEPTION.
(
),
.

3.3.1

IDispatch ( Invoke)
, .
,
dispid.
, dispid,
v- .
dispid ,

.
dispid 0, DISPID_VALUE .
( !) dispid,
.
. dispid
Salary, .
,
, :

MsgBox x,

www.books-shop.com

MsgBox x.Salary.

IDispatch ,
, .

3.4

DEFINE_GUID, .
GUID .
DEFINE_GUID , ,
INITGUID.H, (
).
CLSID_CAuto GUID {AEE97356-B61411CD-92B4-08002B291EED}. ,
IID_IAuto, {4D9FFA39-B732-11CD-92B4-08002B291EED}.
GUID GuidGen. GUID
(clipboard) ,
3.2, DEFINE_GUID.
, GUID , ,
,
( -
GUID
).
CLSID_CAuto (CLSID)
Automation, IID_IAuto (IID)
.
CAutoProg::InitInstance .
OLE OleInitialize.
,
IMalloc. IMalloc OLE,
16- OLE ( )
. NULL,
: , , OLE.
32- OLE Windows NT 3.5 ,
OleInitialize COM- CoInitialize
NULL. ,
IMalloc, COM.
,
. ,
(hooks),
- ,
, .
OLE ,
. , m_fOleInitSuccess
TRUE FALSE ,
OLE.
OleInitialize OleUninitialize ( ExitInstance).
InitInstance RegisterTypeLibrary,
, m_ptinfo, 0.
RegisterTypeLibrary ,
ITypeInfo .
,
. CreateClassFactory,
TRUE
. ,
(icon).

%RRNVVKRS

piracy@books-shop.com

3.5
RegisterTypeLibrary ,
,
. ,
.
,
Win32 API GetModuleFileName
EXE TLB. ,
EXE (, ,
). API 32 COM, ,
Unicode, Unicode
Win32 API MultiByteToWideChar.
API LoadTypeLib, , ,

ITypeLib. RegisterTypeLib,

\HKEY_CLASSES_ROOT\TypeLib . ,

ITypeInfo , ITypeLib::
GetTypeInfoOfGuid IID_IAuto
m_ptinfo.
, .
.

3.6
CAutoProg::CreateClassFactory
CAutoCF new,
C++ (try-catch) ,
,
CreateClassFactory FALSE. CAutoCF
,
m_pAutoCF, CoRegisterClassObject ,
COM CLSID_CAuto.
, CoRegisterClassObject: CLSCTX_LOCAL_SERVER
, ,
REGCLS_SINGLEUSE ,
.
REGCLS_MULTIPLEUSE.

(TRUE) (FALSE).
CAutoCF CoRevokeClassObject ,
CoRegisterClassobject.
CoRevokeClassObject ,
,
( ,
).
CAutoCF::AddRef, CAutoCF::Release CautoCF::QueryInterface
. Release
, QueryInterface AddRef
,
IUnknown IClassFactory.
E_NOINTERFACE. CAutoCF::CreateInstance ,
(
); CAutoDisp.
C++;
, , .
QueryInterface , -

www.books-shop.com

. ,
CreateInstance , ; -

CreateInstance. , .
, , NULL
, IUnknown
. .


CreateInstance (
), . C++:
,

. ,
.

LockServer . -
, ,
(S_OK).
. ,
, !
E_NOTIMPL, , .
. ,
LockServer.
, ,
COM (, !) . -

, ,
.

3.7
Automation, IUnknown
,
CAutoDisp. , ,
C++ ,
.
IDispatch,
Automation API, CreateStdDispatch. ,
, ,
.
. ,
,
IDispatch, .
, (
), , , . ,
.

,
, IDispatch
IUnknown.
,
, .
, NO_ERROR.
,

www.books-shop.com

,
.
put_Salary
m_lSalary, . get_Salary
,
. ,
, ,
HRESULT. Payraise

Salary .
. ,
IDispatch, API
IDispatch . ,
Salary IDispatch ( )
get_Salary. ? IDispatch (
IUnknown) ,
API. GetTypeInfoCount
1 NO_ERROR. 1
, , 1
0, ,
. ?
-
, .
, LCID
IDispatch::
GetTypeInfo .
LCID (,
), .
,
(,
),
,
. , World Wide Web
, , .

, .
COM , ,
.
, , .
,
LCID ,
ITypeInfo. ,
RegisterTypeLibrary ,
.

LCID.
GetIDsOfnames. ,
dispid. ,
,
, Invoke
.
DispGetIDsOfNames .
IDispatch Invoke. Invoke

Automation.
,
(

www.books-shop.com

), Invoke DispInvoke.
, ? ,
LCID.
, ,
,
.
IUnknown
CAutoDisp. ,
. QueryInterface ,
IAuto, IUnknown IDispatch.
,
(IAuto),
if.
, , C++
, OR .
CAutoDisp::Release ,
, .
. Visual C++
4.0 .
MFC ( ,
AppWizard!). AUTOPROG.CPP
.
, - .
( -,
)
,
!

3.8 -
, .
, :

HKEY_CLASSES_ROOT\AutoProg.CAuto.2 = AutoProg Server


HKEY_CLASSES_ROOT\AutoProg.CAuto.2\CLSID =
{AEE97356-B614-11CD-92B4-08002B291EED}
HKEY_CLASSES_ROOT\CLSID\{AEE97356-B614-11CD92B4-08002B291EED} = AutoProg Server
HKEY_CLASSES_ROOT\CLSID\{AEE97356-B614-11CD-92B408002B291EED}\ProgID = AutoProg.CAuto.2
HKEY_CLASSES_ROOT\CLSID\{AEE97356-B614-11CD-92B408002B291EED}\LocalServer32 =
C:\Controls\Chap03\AutoProg\WinDebug\AutoProg.Exe /Automation
, ProgID AutoProg.CAuto.2
AutoProgServer.
, , CLSID
.
HKEY_CLASSES_ROOT\CLSID. CLSID
, , ,
. ProgID,
.
32- EXE- (LocalServer32);
,

www.books-shop.com

, , ).
,
, .

.
REG
, REGEDIT
,
.
,
.


ActiveX, ,
.

,
, Visual Basic.
1234,
1235.

Set x = Nothing
( ,
).
CD-ROM
Visual Basic,
Automation.
; Early/VTable
Binding ( / v-), Late
Binding ( ).

Dim x As New CAuto



, v-,
,
.
:

Dim x As Object
Set x = CreateObject ("AutoProg.CAuto.2")
Visual C++
IDispatch ,
,
Visual C++ Visual Basic
Visual Basic. ,
,
. ,

www.books-shop.com

, Invoke ),
,
.
,
v-,
IDispatch ,
.
,
(Bruce McKinney), Microsoft Press, (Glenn
Hackney), Visual Basic,
, v-
Visual Basic,

Dim x As New CAuto

Dim x As CAuto
Set x = New CAuto
, Visual Basic, x -
, , Nothing (
). ? Visual Basic
(
) ,
x. Visual Basic x, ,
.
, Automation C++ ,
.
IDispatch.
Automation, ,
Visual Basic
. ,
. ,
, .
,
, ,
. .
. , ,
.
,
Automation.
, ,
,
GetObject Visual Basic.
RegisterActiveObject , IDispatch
.
RevokeActiveObject.
( )
(ROT) ,
.

3.9

, IDL (
), ODL, MIDL, MkTypeLib.
IDL

www.books-shop.com

ODL MkTypeLib. ,
MIDL, MkTypeLib ( ,
MIDL).

, ODL,
AutoProg. ODL-
:

[ uuid (4D9FFA38-B732-11CD-92B4-08002B291EED), version(2.0),


helpstring("AutoProg Automation Server") ]library AutoProg
{
importlib("stdole32.tlb");
// AutoProg
[ uuid(4D9FFA39-B732-11CD-92B4-08002B291EED),
helpstring("Automation interface for AutoProg Server"),
oleautomation, dual ]
interface IAuto : IDispatch
{
[propput, id(0), helpstring("Sets the current
salary")]
HRESULT Salary([in] long Salary);
[propget, id(0), helpstring("Returns the current
salary")]
HRESULT Salary([out, retval] long *Salary);
[helpstring("Increases the salary")]
HRESULT Payraise([in] long Increment);
};
//

};

CAuto

[ uuid(AEE97356-B614-11CD-92B4-08002B291EED),
helpstring("AutoProg Server"),
appobject ]
coclass CAuto
{
[default] interface IAuto;
interface IDispatch;
};

,
. AutoProg, 2.0
( 1.0 ),
. ,
.
, GUID ( ODL
UUID), GUID .
GUID,
( ).

, STDOLE32.TLB.
, OLE,
, IUnknown IDispatch.
.
UUID ,
: oleautomation dual.
, Automation.
, HRESULT,
Automation (Automation
, C C++,

www.books-shop.com

, , Visual Basic,
,
C). , dual, ,
, ,
v-, IDispatch.
Visual Basic , CAuto
.
IAuto.
IDispatch :

interface IAuto : IDispatch


,
IDispatch. ,
Salary.
propput dispid 0 (DISPID_VALUE)
id(0).
,
. , ,
HRESULT ( ,
oleautomation dual).
Salary (
put_
Salary )
, Salary
([in]). [in]
( ,
RPC),

. [out],
[in], [in, out],
, ,
. ,
[in, out] .
,
Salary, , ,
propget, , ,
[out], .
dispid 0, ,
. , ,
retval, ,
Automation
. retval ;
.
, Payraise.
, ,
.
dispid, dispid 1 (
dispid 0). , Increment,
.
COM. ODL
(coclass).
GUID, GUID, CLSID
. .
CAuto IAuto (
).
IAuto,
([default]), IDispatch,
. ,

www.books-shop.com

appobject.
,
(
). ,
.
.
MIDL MkTypeLib,
, Ole2vw32 (
OLE 2, OLE 2 Object View),
Visual C++ 2.0 (. 3-1).

,
, .
(
DLL) ( EXE)
Windows. ,

(, ITypeInfo)
.
,
. Windows NT 4.0
, ITypeInfo2.
(
),
. GUID,
.

. 3-1. Ole2vw32
Microsoft Visual C++ 2.0

3.10

AutoProg
,
.
(,

www.books-shop.com

IPersistStorage),
( !).
AutoProg Automation, Store
TEST.AUT. -
MyStream
Salary, Salary = .

make- AutoProg
\CODE\CHAP03\AUTOPRO2 CD-ROM.


: AUTOPROG.H,
Payraise, :

STDMETHOD (Store)(void);
Store.
AUTOPROG.CPP .
:

STDMETHODIMP CAutoDisp::Store()
{
LPSTORAGE lpStg;
HRESULT hRes = StgCreateDocfile(L"C:\\TEST.AUT",
STGM_CREATE | STGM_SHARE_EXCLUSIVE | STGM_READWRITE,
0, &lpStg);
if (FAILED(hRes))
{
MessageBeep(UINT(-1));
}
else
{
LPSTREAM lpStrm;
hRes = lpStg -> CreateStream(L"MyStream",
STGM_CREATE | STGM_SHARE_EXCLUSIVE |
STGM_READWRITE,
0, 0, &lpStrm);
if (FAILED(hRes))
{
MessageBeep(UINT(-1));
}
else
{
char szBuf[32];
::wsprintf(szBuf, "Salary = %ld", m_lSalary);
hRes = lpStrm -> Write(szBuf, ::lstrlen(szBuf),
0);
if (FAILED(hRes))
{
MessageBeep(UINT(-1));
}
lpStrm -> Commit(STGC_DEFAULT);
lpStrm -> Release();
}
lpStg -> Commit(STGC_DEFAULT);
lpStg -> Release();

%RRNVVKRS

piracy@books-shop.com

}
return hRes;

OLE API
StgCreateDocFile (doc- , Microsoft
;
.
).
:

STGM_CREATE
;
STGM_SHARE_EXCLUSIVE ,
;
STGM_READWRITE ,
/.

,
.


- ,
, ,
STGM_SHARE_EXCLUSIVE. , !

,
Unicode,
:

L"String"
IStorage::CreateStream,
MyStream ( COM
Unicode) , StgCreateDocFile.
,
wsprintf IStream::Write.
, ,
IStream, IStorage.
IStream::Commit OLE,
,
.
Visual Basic
Store,
: x.Store

, LocalServer32 AutoProg
.

www.books-shop.com


DfView (DocFile Viewer),
Win32 SDK.

3.11 ActiveX

.
COM-,
IUnknown. , - COM.
, ,
IUnknown, .
OLE, Microsoft
OLE 94.
OLE 96. , Microsoft
ActiveX, , ,
, Internet. ,
, ( 13).

IUnknown,
. ,
COM
, .
,
OLE 94, OLE 96, ActiveX
!

ActiveX COM: .
ActiveX, OLE 94,

Automation, /
. ActiveX EXE-
( ), ,
DLL- (
). , , ,
.
ActiveX ,
COM-, ,
,
. ,
ActiveX .
,
, ActiveX.
, ,

.

(Event)

:
,
. ,
,
,

www.books-shop.com

.
; 8,
.

,
. ,


. ,
(Ambient Property)
, ,
( ,
,
, ).

(Extended
Property)

,
(,
),
, .
.
,
. ,
,
, .
(
) .

.


, ;
,
. , ,

, .
,
; , ActiveX
; ; ; (
) !

,
,

.
4.

3.12
ActiveX
.
Automation,
, ,
. , Microsoft
Visual Basic (, Visual Basic for Applications
Visual Basic Script); Visual C++
C++.

, ,
, Automation.

www.books-shop.com

,
. Visual
Basic. , Visual Basic
ActiveX. , MyControl Visual Basic Object
( , Automation),
TheControl1,
:

MyControl.TheProperty = 12
x% = MyControl.TheProperty

If MyControl.TheMethod = True Then ...

Sub TheControl1_TheEvent (params) ...
ActiveX
,
.
ActiveX ,
.
,
.
,
. , MFC,
, , ,
, .
,
,
.
(, ActiveX Template Library (ATL) Win32
BaseCtl)
.

, : ,
( , )
Automation. ,
:
Automation
,
.
, ActiveX
(,
), ,
. (,
Excel 5.0)
Automation,
,
. ,
. . 32 , ActiveX,
OLE 94.
,
OLE.
ActiveX.

www.books-shop.com

. 3-2. ,
OLE 94

3.13
,
,
.
,
.
,
. , ,
. ,
, , ,
, !
,
.


ActiveX
; 5, .
,
, ,
,
. ,
,
.

dispid. ,
dispid, . , ,
BackColor;
dispid: 701 (,
).
,
. ,
701
DISPID_AMBIENT_BACKCOLOR OLECTL.H. ,
,
dispid. -
,
, - .
,
, (
).
,
. -
,

www.books-shop.com


.

, , ,
. ,
,
.
, ,
-.

, . UserMode
(DISPID_ AMBIENT_USERMODE) ,
,
Visual Basic.
-
- .
, TRUE (
) FALSE ( ). UIDead
(DISPID_AMBIENT_UIDEAD) ,
,
. ,
,
UIDead TRUE
, .
.
, ShowGrabHandles< Show
Hatching, .
UI- (
),
(
, ).
, Visual Basic,
,
. , UI-
ShowGrabHandles
(DISPID_AMBIENT_SHOWGRABHANDLES) ,
. , UI-
( ,
, ),
.
, , ,
ShowHatching
(DISPID_AMBIENT_SHOWHATCHING).
?
, Automation.

Automation ( : , !).
,
; ,

. Automation
, QueryInterface
IID_DISPATCH.
IDispatch::Invoke dispid,
. ,
DISP_E_MEMBERNOTFOUND.

3.14

www.books-shop.com

COM,
. ,
, ,
.

. , .
, ,

.
Automation,
,
Automation , .
,

IDispatch::Invoke (
IDispatch).
Automation ,
, Automation
(sink).
, ,
, .
ODL-
; ,
.
. , IHexocxEvents
, IHexocx
.
:

[ uuid(37D341A5-6B82-101B-A4E3-08002B291EED),
helpstring("Hexocx Control")]
coclass Hexocx
{
[default] interface IHexocx;
interface IDispatch;
[default, source] interface IHexocxEvents;};
Hexocx
Automation: IHexocx,
IDispatch, IHexocxEvents. IHexocx ,
IHexocxEvents . default ,
,
. ,
IHexocx Automation, IHexocxEvents
.
( ,
?) (, IHexocxPowerUser).
default,
IID.
: Automation
? QueryInterface
IDispatch ,
IDispatch
. , IID
. ActiveX ,
COM ,
, ,
: ,
. (connection
point).

www.books-shop.com

3.15
ActiveX
COM .
,
,
.
Automation ,
source. , .
,
Automation
.

, COM,
ActiveX. , (
), , COM. 4 AutoProg, .


IConnectionPoint.
, IConnectionPointContainer,
, ,
(
IID ,
).


,
,
.
IConnectionPointContainer,
:

HRESULT EnumConnectionPoints(IEnumConnectionPoints **ppEnum)


HRESULT FindConnectionPoint(REFIID iid, IConnectionPoint
**ppCP)
EnumConnectionPoints
IEnumConnectionPoints. IEnumxxx, xxx
, COM
. IEnumxxx : Next,
Skip, Reset Clone. ,
. Automation
, IEnumVARIANT,
Automation. ,
, VARIANT:
,
. VARIANT
(union),
, IDispatch. ,
IEnumVARIANT, Visual Basic
For Each...Next.
- ,
.
FindConnectionPoint

www.books-shop.com

,
. , ,
IMyInterface,
IID_MYINTERFACE. ,
, .
,
. FindConnectionPoint
,
, .
IDispatch,
COM-, FindConnectionPoint
IID_DISPATCH, IID ,
IDispatch. , ,
,
Hexocx , IID
IHexocxEvents, IID_DISPATCH. , :
IDispatch ,
. ,
.
IonnectionPoint :

HRESULT GetConnectionInterface(IID *pIID);


HRESULT GetConnectionPointContainer(IConnectionPointContainer
**ppCPC);
HRESULT Advise(IUnknown *pUnkSink, DWORD *pdwCookie);
HRESULT Unadvise(DWORD dwCookie);
HRESULT EnumConnections(IEnumConnections **ppEnum);
GetConnectionInterface IID ,
. GetConnectionPointContainer

IConnectionPointContainer,
. Advise , (
),
. : ,
,
QueryInterface. Advise
pdwCookie ,
(handle) .
Advise 0. Unadvise ,
.
EnumConnections :
. ,

.
,
, ,
. , ,
,
.
:
IProvideClassInfo IProvideClassInfo2.
. IProvideClassInfo
:

HRESULT GetClassInfo(ITypeInfo **ppTI);


ITypeInfo,
. ITypeInfo
,

www.books-shop.com

Hexocx IHexocx IHexocxEvents.


-,
,
, .
, IProvideClassInfo2,
IID . ,
GetClassInfo, GetGUID,
GUID, :

HRESULT GetGUID (DWORD dwGuidKind, GUID *pGUID);


dwGuidKind ,

GUID.
GUIDKIND_DEFAULT_SOURCE_DISP_IID,
Automation (
GUIDKIND,
IProvideClassInfo2::GetGUID). IProvideClassInfo2
IProvideClassInfo
.
ActiveX
,
, .
. 3-3 ,
,
.
.
, ,
IDispatch , , .
Advise .
, ,
. ,
ActiveX, ,
.
,
.
, . , Visual Basic
Sub,
.
, .

ActiveX, Error.
, -
, .
,
, , ,
Automation .
, Error. Error
ActiveX, Automation,
,
.
Basic-
OnError,
.

%RRNVVKRS

piracy@books-shop.com

. 3-3.

3.16
Visual Basic,
ActiveX, ,
(,
),
,
. ,
.
, ,
.
,
.
,
.

,
.
,
. , , ,
, , . .

ActiveX .
ActiveX , .
ActiveX , (
) . , ,
,
,
. ,
, ,
, ,
. . ( )
Visual Basic,
(
, -
).
ActiveX .
,
, .
,
, .

www.books-shop.com

,
,
. , ,
IPropertyNotifySink.
,
,
.
, ,
.
.
IDL/ODL .
ODL- (,
),
. , Bindable, ,
. RequestEdit
,
IPropertyNotifySink::OnRequestEdit.
, ,
, RequestEdit Bindable.

(MIDL MkTypeLib).
DisplayBind
Bindable. ,

. ,
,
.
DefaultBind
Bindable; ,
, ,
.
.
.

IPropertyNotifySink
IPropertyNotifySink :

HRESULT OnChanged(DISPID dispid);


HRESULT OnREquestEdit(DISPID dispid);
OnChanged
. dispid
. , .
OnRequestEdit
. S_OK,
; S_FALSE
. ,
OnRequestEdit ,
. ,
,
, ,
, ,
.
OnChanged
,
, .
,
.

www.books-shop.com

,
.
,
OnChanged .
OnChanged dispid,
DISPID_UNKNOWN (1). ,

, .
IPropertyNotifySink (
Visual Basic) . Visual Basic
,
. ,
.
,
( ). Visual Basic
,
. ,
, ,

IPropertyNotifySink::OnChanged. Visual Basic

.

3.17
ActiveX
, ,
.
(, )
. , IOleControl,
, , IOleControlSite, .
IOleControl :

HRESULT
HRESULT
HRESULT
HRESULT

GetControlInfo(CONTROLINFO *pCI);
OnMnemonic(MSG *pMsg);
OnAmbientPropertyChange(DISPID dispid);
FreezeEvents(BOOL bFreeze);

GetControlInfo CONTROLINFO,
,
.
( ) OnMnemonic,

. OnAmbientPropertyChange
.
, dispid
. ,
DISPID_UNKNOWN (1),
.
FreezeEvents
. FreezeEvents :
TRUE ,
FALSE .
0, .
,
;
. .
IOleControlSite :

www.books-shop.com

HRESULT
HRESULT
HRESULT
HRESULT

OnControlInfoChanged (void);
LockInPlaceActive(BOOL fLock);
GetExtendedControl(IDispatch **ppDis);
TransformCoords(POINTL *lpptlHimetric,
POINTF *lpptfContainer, DWORD flags);
HRESULT TranslateAccelerator(MSG *lpMsg, DWORD grfModifiers);
HRESULT OnFocus(BOOL fGotFocus);
HRESULT ShowPropertyFrame(void);
OnControlInfoChanged TranslateAccelerator

. LockInPlaceActive
,
.
,
- .

, . GetExtendedControl
Automation,
,
.
(
). TransformCoords . 139.
OnFocus ,
.
, UI-
, .
, ShowPropertyFrame, ,

.

3.18

.
()
. , ActiveX
-,
(labels),
. Windows
,
().

, . ActiveX

. : ?
,
, ( )
IOleControl::GetControlInfo.

. (,
), IOleControlSite::OnControlInfoChanged.
,
IOleControl::GetControlInfo .
, ,
GetControlInfo, , ,
Enter Esc UI- .
, UI , ,
( Enter
).

www.books-shop.com

,
. ,
Ctrl+Enter,
Ctrl+ , .
,
IOleControl::OnMnemonic. ,
.
, ,
.
, OLEMISC_ACTSLIKEBUTTON (.
).
, , ,
,
.
DisplayAsDefaultButton ,
,
. Enter
; ,
Enter.
.
Enter -,
IOleControl::OnMnemonic .
(Cancel button),

. Esc
.
, (radio buttons)
, .
, ;

,
. , ,
, -
-
.
OLEMISC_ACTSLIKEBUTTON,

, Value
ExclusiveBool ( ).
OLE,
Value. ,
.
, (check boxes),
: , ( ).
OLE
OLE_TRISTATE,
. ,
,
Value .

3.19

,
OLE 94.
, ,
, ,

www.books-shop.com

.
OLE_COLOR ,
. ,
BackColor OLE_COLOR. ,
API OleTranslateColor, OLE_COLOR
COLORREF (COLORREF
Win32).
. ,
:
, c
.

3.20

ActiveX.
,
IFont .
IFont (
,
IFontDisp).

IFont

IsEqual

,
ActiveX,
( ,

Windows).

Clone
SetRatio

ActiveX,

.
.

AddRefHfont


Windows (HFONT),
( . ).

ReleaseHfont

HFONT,
( . ).

Windows TEXTMETRIC
QueryTextMetrics
.
SetHDC


(DC), ,
DC
(, ).

,
Automation, .
, (
hFont). , IFontDisp,
IDispatch
.
IFont,
IFont
, IFontDisp. IFontDisp
,
IDispatch. IFont ,
,
Automation.

www.books-shop.com


,
Windows .
, ,
,
Windows. ActiveX
. Windows ,
,
.
, Windows HFONT,

HFONT. ,

HFONT .
.
, AddRefHfont
ReleaseHfont IFont HFONT,
,
. , ,
,
.
IPersistStream,
IPersistPropertyBag IDataObject,
(IPersistStream), (
IPersistPropertyBag IDataObject).

.
OLE API OleCreateFontIndirect,
.
FONTDESC IFont .
ActiveX
, .
,
. ,
?
.
IPropertyNotifySink,
.
.

Name

, Times New Roman.


BSTR.

Size

.
CURRENCY ,
.
,
.

Bold

, .
, ,
Weight
Windows. 550,
.
TRUE, 700,
FALSE 400. .
Weight.

Italic

, .

www.books-shop.com

Underline
Strikethrough

, .
, .

Weight


0 1000,
400 () 700 (). .
Bold.

Charset

ANSI, Unicode OEM.

hFont

Windows.

3.21

.
(bitmap),
(icon),
Visual Basic. , ,
IPictureDisp IPicture;
, IFontDisp IFont. IPicture (
,
Automation) .

IPicture
Render

,
PictureChanged ,
Windows - .
SaveAsFile

get_CurDC

, SelectPicture,
Windows,

.
,

.

SelectPicture


,
, GDI
. . Get_CurDC.

,
IPictureDisp.

Handle

Windows GDI.

hPal

,
.

Type

,
, .

Width

OLE_XSIZE_HI-METRIC
(. ).

Height

OLE_YSIZE_HI-METRIC
(. ).

www.books-shop.com


( ) , ,
,
.
KeepOriginalFormat
,
.

.
,
-
IPropertyNotifySink.
OLE API.
OleCreatePictureIndirect
, .
OleLoadPicture
, .

3.22
, Width Height
OLE_XSIZE_HIMETRIC
OLE_YSIZE_HIMETRIC. ,
. ActiveX
,
, -
. ,
, .
,
. ,
,
. ,
Mouse Down ( ),
, , . ,
,
. ,
,
, ,
, OLE.

. ,
,
. ,
1234, 1234,
- ,
. ,
ActiveX ,

.
, ?
,

. IOleControlSite TransformCoords,
. ,
,

OLE .

, ScaleUnits.

www.books-shop.com

3.23
,
, IPersistStorage.

IStorage.
,
IPersistStorage, , .
ActiveX ActiveX
IStream. ,
OLE IPersistStream
, IPersistStream
InitNew IPersistStorage.
,
. InitNew
, , :


.

,

.

, IPersistStreamInit,
.
,
.

. ,
,
.
,
OLEMISC_SETCLIENTSITEFIRST (
). ,
ActiveX,
IPersistStreamInit. , ,
,
IPersistStorage.

OLEMISC_SETCLIENTSITEFIRST ,
SetClientSite.
, ,
, ,
.
, SetClientSite InitNew
Load.
IPersistStream IPersistStreamInit ,
InitNew.
IPersistStreamInit IPersistStream,

IPersistStream. InitNew ,
.

3.24
Microsoft Visual Basic , Visual Basic
, ( )
.
, . ,
, Visual Basic

%RRNVVKRS

piracy@books-shop.com

(, FRX).
Visual Basic
ActiveX?

3.25

( )
, ActiveX
. !
ActiveX ,

. OLE,
(property set).
, OLE 2 Programmers Reference,
Volume 1, ,
ActiveX
.
, ,
( dispid!) .
, ActiveX,
,
. ,
Automation VARIANT,
BLOB ( BLOB
,
).

. ,
, ,
,

. , ,
, Save
IPersistStream IPersistStorage, ,
. , ,
,
Load IPersistStream IPersistStorage.
,
.

IDataObject.

3.25.1

Visual Basic
, ,
.
,
, .
IPropertyBag,
, IPersistPropertyBag,
.
, IErrorLog. :
(property bag)
IPropertyBag.

www.books-shop.com

. IPersistPropertyBag

VARIANT. ,
(,
), EXCEPINFO
IErrorLog.
, .

.
IPersistPropertyBag, IPersist
:

HRESULT InitNew();
HRESULT Load(IPropertyBag *pPropBag, IErrorLog *pErrorLog);
HRESULT Save(IPropertyBag *pPropBag, BOOL fClearDirty,
BOOL fSaveAllProperties);
InitNew IPersistStreamInit::InitNew;
,
, . Load

,
. Save
fSaveAllProperties TRUE,
, FALSE,
,
.
,
.
, fClearDirty ,
.
IPropertyBag, IUnknown
:

HRESULT Read(LPCOLESTR pszPropName, VARIANT *pVar,


IErrorLog *pErrorLog);
HRESULT Write(LPCOLESTR pszPropName, VARIANT *pVar);
IErrorLog, IUnknown
:

HRESULT AddError(LPCOLESTR pszPropName, LPEXCEPINFO


pExcepInfo);
, (
,
),
IPersistPropertyBag::Save,
IPropertyBag.
, .
IPropertyBag::Write,
,
. ,
, ,
IPersistPropertyBag::Load
IPropertyBag IErrorLog.

www.books-shop.com

,

.
IErrorLog::AddError .
Automation EXCEPINFO.
, .

.
ActiveX
, Internet
13, ActiveX Internet.

3.26
,
. COM
CLSID MiscStatus.
(, ,
), (),
COM.
( ),
MiscStatus.
,
(, MiscStatus
DVASPECT_ICON 4). ,
, ,
MiscStatus.
, IOleObject::
GetMiscStatus .
, ,
, .
COM, ActiveX
. COM
:

OLEMISC_INSIDEOUT ,
(
UI-).
OLEMISC_ACTIVATEWHENVISIBLE ,
, ,
UI-.

,
ActiveX.


,

(, -).
OLEMISC_INVISIBLEATRUNTIME

,

.
OLEMISC_ALWAYSRUN

www.books-shop.com

.
ActiveX
,
.

OLEMISC_ACTSLIKEBUTTON

,
.
,
,

.

OLEMISC_ACTSLIKELABEL

Windows
(
static) ,
.
ActiveX
,
.


, .

OLEMISC_NOUIACTIVATE

,

,
,
Automation
. ,


, OLEMISC_
INSIDEOUT.

OLEMISC_ALIGNABLE

,

. ,

. ,
,
,

.

OLEMISC_IMEMODE

Windows,

MCBS (,
Windows),

(input method editors, IME).
,
. ,
IME,

IMEMode.

OLEMISC_SIMPLEFRAME

,
ActiveX
(
,

, . .).

,

.
,
ISimple Frame Site
,

www.books-shop.com


.
OLE


( OleLoad)

IPersistStorage::InitNew.
ActiveX
OLEMISC_SETCLIENTSITEFIRST


(,
)
.

.
OLE, ActiveX
MiscStatus, . ,
,
.
OLE, , ,
, ,
.

3.27

ActiveX ,

. , Visual Basic
.
,
ActiveX.
,
- (
, ).

, .
ActiveX
. ,
,
(. 11).
,
. ,

, .
:
(property frame),
.

.
. 3-4.

www.books-shop.com

. 3-4. ,


. ,
,
.
COM- CLSID
.
, .
,
. COM IPropertyPage,
, . .
, ,
IPropertyPageSite.
, ,
IspecifyPropertyPages, GetPages.
CLSID ,
, , CoCreateInstance.
Runtime- ActiveX
,
OleCreatePropertyFrame. Microsoft Windows 95 Windows
.
, ,
.
,
(, Visual Basic), ,
, .
,
, . ,


. , BackColor
ForeColor, Visual Basic ,

( ). ,
,

. ,

www.books-shop.com

,
, .

3.28

.
,

.
,
, .
,
Automation.
( ),
,
IPerPropertyBrowsing.
,
,
. ,
IPropertyPage2,
IPropertyPage EditProperty,
.
,
.

,
, . ,
, (verb) OLE
Properties,
.
,
.

3.29
(. 16),
, COM
ActiveX. - ,

.
!
, , ,
.

. , .
, ActiveX
,
.
:

.
.
.

(
)
( ).
,

www.books-shop.com

, .

.
ActiveX ,
,
. ,
. ,

,
.
COM
IClassFactory2. IClassFactory
( )
,
(GetLicInfo),
(RequestLicKey)
,
(CreateInstanceLic). GetLicInfo
LICINFO, :

.
, ,
.
, ,
.


, . ,
, IClassFactory2,
, ,
. , ,
IClassFactory. ,
- OLE (, OleCreateInstance
OleCreate), IClassFactory,
IClassFactory2. ,
.
, IClassFactory2 RequestLicKey,
,
. ?
, ,
ActiveX.
, (, , )
,
, .
,
,
.

. ControlWizard,
Visual C++, MFC ,
, .

3.30
COM- ,
. COM
, DLL-,
.
. ActiveX,

www.books-shop.com

DLL-, ,
, -. ,
,
.
ActiveX
DLL-, ,
.
( ) COM-.
, DLL-,
, COM- .
DllRegisterServer.
DllUnregisterServer,
DLL .
, DLL- ,
, DLL-

. ActiveX
,
. :
StringFieldInfo OLESelfRegister.
(
), DLL- . ,
DLL- COM
DllGetClassObject,
CoCreateInstance IID_CLASSFACTORY.
,
. ,
,
/REGISTER /UNREGISTER
.
, ActiveX
OCX.

.

3.31
ActiveX, COM-,
.
OLE-.
.
Insertable, Control, DefaultIcon ToolboxBitmap.
HKEY_CLASSES_ROOT\CLSID\{}.
Insertable Control
. ,
. Insertable ,
Insert Object,
. OLE Insert
Object ( , )
,
Insertable. .
Insertable , ;
, Insert
Object. Insertable
, ,
, ,
.

www.books-shop.com

Insertable ,
, ,
.
Control ,
ActiveX.
. ,
ActiveX,

. ,
ActiveX, ,
.
ActiveX Insertable, Control.
, ,
ActiveX,
(
Insertable
!).
,
,
.
.
Control , Insertable .
Insertable
, Control .
,
.
OLE DefaultIcon.
, ,
. DefaultIcon
DLL-, ,
.
Windows API ExtractIcon.
, ,
ActiveX: ToolboxBitmap32 ( ToolboxBitmap
16- ).
(, Visual Basic)
. ,
Windows ,
.
, 1516 .
, DefaultIcon
DLL-
.

3.32
ActiveX COM
,
. ,
. , ,
.
, COM,
.
: .
,
.

%RRNVVKRS

piracy@books-shop.com

, , .
, ,
, ,
.

. COM
, ,
.
, /
.
(,
), CLSID,

COM OLE API CoSetTreatAsClass OleSetAutoConvert.
CLSID
.
, OLE

, ,
, . ,

IStorage, COM
, .
, ActiveX . ,
, .
, ,

Automation , .
,
.
,
: IHexocx
IHexocxEvents.
Automation .
, .
IHexocx.
, ActiveX
IStorage.
(IStreamInit)
OLE IData
Object.
,
, ,
.
! ,
,
. :
(binary compatibility),
(source compatibility) .
,
,
,
, .
,

www.books-shop.com

-, -
, . .
.
Visual Basic,
1.0 . 1.1,
.
, .
,
,
.

.

.
CLSID, (
IID, , dispid, . .)
, IID. , ,
CLSID.
,
. , Automation
,
. , Automation
, dispid . ,
- ,
,
v- (
, ,
).
QueryInterface IID
,
.
,
Advise
QueryInterface IID.
IID,
, IID. ,
IID , Query
Interface IID.
,
,
.
, CLSID ( ,
),
.

- .

.

,
, 10, .

www.books-shop.com

3.33 OCX 96
OLE 94
VBX. , ,
32 , .
. ,
,
. OLE,

OLE c . ,
, (
), (
) . ,
,
,
.

(, !).
,
OLE .
Microsoft
.
OLE,
.
,
Microsoft;
,
.
OLE ,
OCX 96. ,
. ,
, .
( ,
OLE ),
.
MFC,
OLE (
OLE CDK), Visual Basic,

Visual Basic.
MFC MFC
4.0 ,
. Visual Basic
,
,
. Win32
BaseCtl C++ ,
MFC.

. , OCX 96.

3.34
( ,
Visual C++ ControlWizard)
. , ,
,
.

www.books-shop.com

. ,
,
.
,
.
, ,
.
,
. ,
drag-and-drop
. ,
. OCX 96
IPointerInactive,
:

IPointerInactive : IUnknown
{
HRESULT GetActivationPolicy(DWORD *pPolicy);
HRESULT OnInactiveMouseMove(LPRECT lprcBounds, LONG x,
LONG y,
DWORD grfKeyState);
HRESULT OnInactiveSetCursor(LPRECT lprcBounds, LONG x,
LONG y,
DWORD dwMouseMsg, BOOL
fSetAlways);
}
,
.
, IPointerInactive
.
WM_SETCURSOR WM_MOUSEMOVE,
,
.
, .
,
IPointerInactive? ,
OCX 96, ,
, ?
COM

OLEMISC_ACTIVATEWHENVISIBLE /
IPointerInactive ( QueryInterface).
, (,

) IPointerInactive,
.
,
,
, .
, ,
OLEMISC_ACTIVATEWHENVISIBLE,
. ,
OLEMISC_IGNOREACTIVATEWHENVISIBLE,
.
, OCX 96,
, . ,
!
. ,
, ,

www.books-shop.com

, OCX 96,
IPointerInactive::GetActivationPolicy
.
, .
,
,
( ,
). -
.
:

POINTERINACTIVE_ACTIVATEONENTRY

,


,
.

,

OLE 94.

,


.


,

GetActivationPolicy
.

; .
.


,
,
,
.

,
POINTERINACTIVE_DEACTIVATEONLEAVE
.
,

,
(

).
POINTERINACTIVE_ACTIVATEONDRAG

dragand-drop .
Drag-and-drop
.

IPointerInactive::OnInactiveSetCursor
WM_SETCURSOR, ,
,
.

, IPointerInactive

www.books-shop.com

, HIMETRIC.
, Windows
.

lprcBounds ,
x y
( ).
dwMouseMsg lParam
WM_SETCURSOR.
,
, .
, fSetAlways, TRUE,
, . FALSE,
,
. , S_OK,
S_FALSE.
OnInactiveSetCursor ,
WM_MOUSEMOVE
.
, ,
x y . , grfGetKeyState,
(, Ctrl Shift)
.

3.35 Drag-and-drop
drag-and-drop OLE , (,
) IDropTarget.
,
. ,
. OCX
96 drag-and-drop
.
:

IDropTarget::DragOver
IDropTarget::DragEnter ,
, QueryInterface
IPointerInactive . QueryInterface
, ,
.
,
GetActivationPolicy.

POINTERINACTIVE_ACTIVATEONDRAG,
.
IDropTarget
, drag-and-drop
.

DragEnter DragOver,
pdwEffect DROPEFFECT_NONE.
OLE , drag-and-drop ,
IDropTarget::DragLeave
IDropTarget::DragEnter.
,
UI- , UI-
.
, UI-
IDropTarget::DragEnter (

www.books-shop.com


).
, ,
, drag-and-drop.

,
,
. .

3.36


, (
, ,

, UI).
.
, (
Windows ). ,
,
. , ,
,
, .
, ,
( ).
, ,
,
. OCX 96,
, ,
,
( ,
).
OCX 96
,
. ,
,
.
,
IUnknown, v-
v ,
v-.
,
,
.
,
,
.

, .

www.books-shop.com

,

OLE
UI-. ,
.

IOleInPlaceObjectWindowless ( IOleInPlaceObject)
IOleInPlaceSiteWindowless ( IOleInPlaceSiteEx, ,
, IOleInPlaceSite
OCX 96 ).
,
, QueryInterface
IOleInPlaceSiteWindowless. ,
, ,
CanWindowlessActivate .
QueryInterface
( S_FALSE), ,
OCX 94. ,
,
, ,
.
, ? ,
IOleInPlaceActiveObject::GetWindow,
, .
S_FALSE, ,
. OLE ,

IOleInPlaceSite::OnInPlaceActivateEx,
S_FALSE. ,
,
IOleInPlaceSiteEx::OnInPlaceActivateEx,
.
ACTIVATE_WINDOWLESS,
.
,
. ,
, .

3.37

, .
OnWindowMessage
IOleInPlaceObjectWindowless, .
Win32 API SendMessage,
,
Win32 LRESULT
COM HRESULT.
,
, DefWindowProc,

.
OnDefWindowMessage IOleInPlaceSiteWindowless.
, SetCapture
IOleInPlaceSiteWindowless (,
,
IOIPSW). TRUE, ,
( ),

www.books-shop.com

FALSE, .
,
,
. ,
, IOIPSW::GetCapture
S_OK .
:
, ?
,
OCX 96. (
, ,
, ),
,
, , ,
WM_HELP WM_CANCELMODE. ,
Win32 API SetFocus,
HWND,
. IOIPSW::SetFocus
.
,
FALSE. , Win32 API
HWND, NULL,
. ,
, IOIPSW::GetFocus; S_OK,
.
- ,
S_FALSE
IOleInPlaceActiveObjectWindowless::OnWindowMessage,
.
DefWindowProc.

, OLE, ,
IOleInPlaceActiveObject::TranslateAccelerator.
, WM_COMMAND
. ,
, . ,

. ,
( ,
),

TranslateAccelerator.

3.38
,
IViewObject::Draw,
, , .
, ,
,
, IViewObject::Draw.

, .
lprcBounds Draw,
, NULL.
,
. , ,
: dwAspect

www.books-shop.com

Draw DVASPECT_CONTENT,
DVASPECT_OPAQUE DVASPECT_TRANSPARENT (
).
hdcDraw,
(HDC),
. ,
(,
WM_PAINT). , ,
MM_TEXT,

.
IViewObject::Draw lprcBounds NULL
, ,
, ,
E_INVALIDARG.

3.39 drag-and-drop
drag-and-drop ,
,
.
, , , ,
.
IDropTarget,
( ,
) (
QueryInterface
E_NOINTERFACE IID_IDropTarget).
IDropTarget,
OLE. , DragEnter
DragOver ,
,
IOleInPlaceObjectWindowless::GetDropTarget,
IDropTarget (
E_NOTIMPL, drag-and-drop).

.
,
DragEnter
pdwEffect DragEnter DragOver.
, DragLeave
IDropTarget ,
drag-and-drop .
.
S_FALSE DragEnter
, ,
IDataObject drag-and-drop.
.
,
(. ;
GetActivationPolicy
), ,
,
GetDropTarget ,
drag-and-drop.
.

3.39.1

%RRNVVKRS

piracy@books-shop.com


,
,
WM_PAINT
- ,
. , .
Win32 API,
(, GetDC
),
IOleInPlaceSiteWindowless.
:

HRESULT
HRESULT
HRESULT
HRESULT
HRESULT

GetDC(LPRECT lpRect, DWORD dwFlags, HDC *phdc);


ReleaseDC(HDC hdc);
InvalidateRect(LPCRECT lprc, BOOL fErase);
InvalidateRgn(HRGN hrgn, BOOL fErase);
ScrollRect(int dx, int dy, PLCRECT lprcScroll,
LPCRECT lprcClip);
HRESULT AdjustRect(LPRECTL lprc);
,
Win32 API. GetDC
, ReleaseDC .
GetDC . , lpRect,
, (NULL
), -.
,
(clipping region),
- .
, dwFlags, GetDC,
. 0 ,
, .

(, ),
OLEDC_NODRAW. OLEDC_PAINTBKGND,

, ,
(. ).
OLEDC_OFFSCREEN ,
(memory device context),
.
,
, .
Windows,
, IOIPSW::GetDC,
IOIPSW::ReleaseDC.

( ),
IOIPSW::InvalidateRect IOIPSW::InvalidateRgn.
IAdviseSinkEx (. ),

HIMETRIC, IOIPSW .
fErase,
(TRUE) (FALSE) .
(scrolling) IOIPSW,
Windows API - ,
- ,
.

www.books-shop.com

,
.

IOIPSW::ScrollRect . ,

, ,
(clipping)
.
, .
ScrollRect :

lprcScroll
( ); NULL
.
lprcClip (NULL
lprcScroll).
dx dy , x y.

, (),
, . ,

. AdjustRect


. S_OK, ,
S_FALSE,
- .

3.40
OCX 96
.
, ,
OCX 96. OCX 96
, .
( )
,
,
.
,
,
.
,
.

3.41
IViewObject::Draw
,
.
GDI ( Windows,
) , ,
.
,
. ,
,
. .
, ,
/
.

www.books-shop.com

OCX 96 IViewObject::Draw (
!)
GDI .
IViewObject::Draw pvAspect,
, OLE
NULL.
DVASPECTINFO, :
.
DVASPECTINFOFLAG_CANOPTIMIZE.
DVASPECTINFO, IViewObject::Draw,
, ,
. ,
,
, . . ,
(,
), .
, GDI ,
. ,
GDI, ,
. , GDI
(
).

3.42
, , . .
, ,

.
? ,
.
OLE, , ,
, .

.
OCX 96, ,
, ,
.
IOleInPlaceSiteEx, IOleInPlaceSite.
IOleInPlaceSite,
: OnInPlaceActivateEx, OnInPlaceDeactivateEx RequestUIActivate.
.
, TRUE,
, FALSE
.
,

, z- (
) . .
NULL
IOleInPlaceSite::InInPlaceActivate,
.
.
, OnInPlaceDeactivateEx, .
, ,
(FALSE) (TRUE) .

www.books-shop.com

, RequestUIActivate,
UI-.
, S_FALSE
OnUIDeactivate.

3.43
,
,
, .
, ,
,
. , ,
z-, .
, ,
.
Windows

.

, .
,
,
.
. ,

. ,
Windows ( , ).
, ? OCX 96
, ,
.

. , ,
OCX 96,
.
,
,
(,
).
,
. ,

.
,
.
,
,
.
OCX 96 : (DVASPECT_OPAQUE)
,
(DVASPECT_TRANSPARENT)
. -
( DVASPECT_CONTENT,
), ,
,
IViewObjectEx::GetViewStatus. ,
,
, ,

www.books-shop.com

,
.

DVASPECT_OPAQUE,
DVASPECT_TRANSPARENT.
OLE ,
,
,
.
.
IViewObject2::GetExtent
.
GetRect, IViewObject,
, .
DVASPECT_CONTENT .
DVASPECT_OPAQUE ,

,
.
. HRESULT
DV_E_DVASPECT.
,
.
DVASPECT_TRANSPARENT,
( ,

). ,
.
,
IViewObjectEx::GetViewStatus,
,
.
,
.
,
GetViewStatus, IAdviseSink,
IAdviseSinkEx.
OnViewStatusChange,
. , IAdviseSinkEx,
, , QueryInterface
, IViewObject::SetAdvise.
,
IAdviseSink.
, , IViewObjectEx,
.

3.44
(
), .

,
. ,
,
. /
(
) .

, OCX 96 IViewObjectEx.
,

www.books-shop.com

(,
,
),
IViewObject::QueryHitPoint, ,
, .
. , ,
,
,
,
. , ,
,
, . ,
, ,
.
.
,
, .
,
HIMETRIC,
.
, IViewObjectEx,
DVASPECT_CONTENT QueryHitPoint
.
, E_FAIL,

DVASPECT_CONTENT.
IViewObjectEx , QueryHitRect,
, (
)
.
DVASPECT_CONTENT, ,
E_FAIL
DVASPECT_CONTENT. QueryHitPoint
QueryHitRect .

3.45 OCX 96
, ,
OCX 96
.
.

3.45.1
,
, , .
,
,
.
IPersistxxx:Load IPersistxxx::InitNew.
, ,
IQuickActivate. ,
QACONTAINER
, (IOleClientSite, IAdviseSink,
IPropertyNotifySink
), .
QACONTAINER
DWORD,
(, ForeColor
OLE_COLOR colorFore).

www.books-shop.com

,
QACONTAINER NULL,
QueryInterface.
,
, .
, ( ,
-, )
QACONTROL .
IViewObjectEx
(cookies) .
IQuickActivate ,
SetContentExtent GetContentExtent,
.

3.45.2
OCX 96
(undo) (redo) .
, ,
/,
,
. ,
! , ,
.
( -,
).

3.45.3

,
. ,
(
). ,
: ,
, , ?
OCX 96 IViewObjectEx,
GetNaturalExtent.
,
DVEXTENT_CONTENT DVEXTENT_INTEGRAL.
,
;
, .

, (,
) ,
,
.

3.45.4
, ,

, , ,
. ,
, ( 1/72 ).

www.books-shop.com

HIMETRIC. OCX 96
,
.
, OCX 96, ,
,
.
, , ,
. ,
, OCX 96, ,


( !),
IOleControlSite::TranslateCoordinates .

3.45.5 dispid
OCX 96
.
.

Dispid

MousePointer
;
OCX 96 ,
DISPID_MOUSEPOINTER ( ,
521)
99
(c.
).
MouseIcon
,
DISPID_MOUSEICON (-522)
, DISPID_
MOUSEPOINTER (. ), 99.
DISPID_PICTURE (-523)
DISPID_VALID (-524)

Picture.
, ,
.
.

,
DISPID_AMBIENT_PALETTE

(-726)
Windows.

3.45.6
OCX 96 .
, , ,
.
, , ,

.
,
.
- ,
.
ImmediateBind.

3.46 ActiveX
Microsoft OLE Controls/COM Objects for the Internet (
ActiveX SDK -

www.books-shop.com

) ,
OLE ActiveX.
OLE ActiveX,
ActiveX.
, ,
( )
Internet. OLE
ActiveX. OLE ,
ActiveX!
dispid ,
, (
), ,
. ,
.
, ActiveX,
Internet,
IPersistxxx.
.
IPersistPropertyBag,

HTML- web. , IPersist (
IPersistPropertyBag),
.
(,
),
(. , ).
Internet,


, . ,
, :

IOleObject IObjectVisible (
. ).


( . ).

(. ).
,
IBindHost ( , ).

IBindStatusCallback.


.
ReadyState
OnReadyStateChange .
IPersistPropertyBag,
HTML- PARAM.

, ActiveX
HTML-.
, ,
.
,
;
.
URL (, URL

www.books-shop.com

file://), ,
.
, ,
,
.
,
URL URL-

BindToStorage.
,
.
, - ,
URL,
BSTR. ,
GUID_PathProperty.

MIME.
,
,
IPropertyNotifySink.
GUID_
HasPathProperties,
.
.


( 1996 )
,
ITypeInfo2.
.
GUID ,
ODL/IDL
:

[ propget, custom(GUID_MyCustomAttribute, "Adam") ]


BSTR SpecialProperty(int nIndex);
,
Windows.
SpecialProperty ODL- propget
. GUID GUID_MyCustom
Attribute Adam.

,
IBindHost. ,
IOleObject,
SetClientSite, .
IOleObject,
. ,
IObjectWithSite,
, .
, IOleObject,
IObjectWithSite.
,
IBindHost, ,

%RRNVVKRS

piracy@books-shop.com

IBindHost .
,
QueryInterface IServiceProvider,
IServiceProvider::QueryService ,
IBindHost.
IServiceProvider QueryService IUnknown
QueryInterface, , QueryInterface
(
), QueryService (
).
, Internet ,
13 .
, ,
.
OLE COM,
ActiveX, .
Microsoft ActiveX, C++ (
Win32 BaseCtl, ATL MFC), Visual Basic Java.

Microsoft
ActiveX
, -,
COM OLE . , COM
OLE ActiveX.
, ActiveX.

www.books-shop.com

AutoProg
, .
, ( ,
IUnknown.
, IUnknown, - ).
, DLL-.
, ,
, .
, ,
.

4.1
ActiveX ,
Microsoft.
2 3,
ActiveX .
, , COM, . C++
(, ATL),
,
.
.

ActiveX.

AutoProg, Automation.
AutoProg ,
,
. AutoProg .
,
, .
AutoPro2, 3 .
:

IEnumConnectionPoints .
IEnumConnections .
,
.
COM-,
, IConnectionPoint
, .

\CODE\CHAP04\AUTOPRO3
CD-ROM. :

4.2 IProvideClassInfo
IProvideClassInfo2.

IConnectionPointContainer.
IonnectionPoint.
.
.

www.books-shop.com

4-1 AUTOPROG.H,
AutoProg.
CAutoDisp CAutoCPC .
, ,
. ,
, .
CAutoPCI2, IProvideClassInfo2
( IProvideClassInfo,
IProvideClassInfo2). ,
COM. ,
CAutoDisp.
, CAutoPCI2 Automation (
, IUnknown
Automation). m_pAutoDisp.
CAutoCP, IConnectionPoint.
. ,
CAutoCPC ( ).
m_pCPC m_dwCookie 0. m_dwCookie
( ), ,
. , m_pEvents, ,
( -). ,
GetEventIP, m_pEvents, , NULL
. IDispatch,
, .
, CAutoCPC,
IConnectionPointContainer. , ,
m_AutoCP CAutoCP ,
.
CAutoCPC; CAutoCPC m_AutoCP(this).
CAutoCPC CAutoDisp
m_pAutoDisp. , CAutoCPC (
GetEventIP), ,
GetEventIP .
CAutoDisp,
, .
, CAutoPCI2 ( IProvideClassInfo2) CAutoCPC (
IConnectionPointContainer), m_PCI2 m_CPC .
this CAutoDisp. ,
FireYourEvent,
.
4-1.AUTOPROG.H ,

class CAutoDisp;
class CAutoCPC;class CAutoPCI2 : public IProvideClassInfo2
{
public:
STDMETHOD (QueryInterface)(REFIID riid, void **ppv);
STDMETHOD_ (ULONG, AddRef)(void);
STDMETHOD_ (ULONG, Release)(void);
// IProvideClassInfo
STDMETHOD (GetClassInfo)(LPTYPEINFO *ppTI);
// IProvideClassInfo2
STDMETHOD (GetGUID)(DWORD dwGuidKind, GUID *pGUID);
CAutoPCI2(CAutoDisp *pDisp) { m_pAutoDisp = pDisp; }
private:
CAutoDisp *m_pAutoDisp;
//
};

www.books-shop.com

class CAutoCP : public IConnectionPoint


{
public:
STDMETHOD (QueryInterface)(REFIID riid, void **ppv);
STDMETHOD_ (ULONG, AddRef)(void);
STDMETHOD_ (ULONG, Release)(void);
// IConnectionPoint
STDMETHOD (GetConnectionInterface)(IID *pIID);
STDMETHOD (GetConnectionPointContainer)(
IConnectionPointContainer **ppCPC);
STDMETHOD (Advise)(LPUNKNOWN pUnkSink, DWORD *pdwCookie);
STDMETHOD (Unadvise)(DWORD dwCookie);
STDMETHOD (EnumConnections)(LPENUMCONNECTIONS *ppEnum);
CAutoCP(CAutoCPC *pCPC) { m_pCPC = pCPC; m_dwCookie = 0; }
LPDISPATCH GetEventIP() {
return (LPDISPATCH)(m_dwCookie ? m_pEvents : 0);
}
private:
CAutoCPC *m_pCPC;
LPUNKNOWN m_pEvents;
DWORD
m_dwCookie;
};
class CAutoCPC : public IConnectionPointContainer
{
public:
STDMETHOD (QueryInterface)(REFIID riid, void **ppv);
STDMETHOD_ (ULONG, AddRef)(void);
STDMETHOD_ (ULONG, Release)(void);
// IConnectionPointContainer
STDMETHOD (EnumConnectionPoints)(
LPENUMCONNECTIONPOINTS *ppEnum);
STDMETHOD (FindConnectionPoint)(REFIID iid,
LPCONNECTIONPOINT *ppCP);
CAutoCPC(CAutoDisp *pDisp) : m_AutoCP(this) {
m_pAutoDisp = pDisp;
}
LPDISPATCH GetEventIP() { return m_AutoCP.GetEventIP(); }
private:
CAutoDisp *m_pAutoDisp;
CAutoCP
m_AutoCP;
};
class CAutoDisp : public IDispatch
{
public:
STDMETHOD (QueryInterface)(REFIID riid, void **ppv);
STDMETHOD_ (ULONG, AddRef)(void);
STDMETHOD_ (ULONG, Release)(void);
STDMETHOD (GetTypeInfoCount)(UINT *pctinfo);
STDMETHOD (GetTypeInfo)(UINT itinfo,
LCID lcid,
ITypeInfo **pptinfo);
STDMETHOD (GetIDsOfNames)(REFIID riid,
LPOLESTR *rgszNames,
UINT cNames,
LCID lcid,
DISPID *rgdispid);
STDMETHOD (Invoke)(DISPID dispidMember,
REFIID riid,
LCID lcid,
WORD wFlags,

www.books-shop.com

STDMETHOD
STDMETHOD
STDMETHOD
STDMETHOD

DISPPARAMS *pdispparams,
VARIANT *pvarResult,
EXCEPINFO *pexcepinfo,
UINT *puArgErr);
(put_Salary)(long lSalary);
(get_Salary)(long *lSalary);
(Payraise)(long lSalaryIncrement);
(Store)(void);

CAutoDisp() : m_PCI2(this), m_CPC(this)


{
m_ulRefs = 0;
m_lSalary = 0;
}
private:
void FireYourEvent(void);
ULONG m_ulRefs;
long m_lSalary;
CAutoPCI2 m_PCI2;
CAutoCPC m_CPC;
};
. , IProvideClassInfo2,
. , IUnknown: GetClassInfo
GetGIUD. ITypeInfo,
, .
, ITypeInfo? , , ,
.
2 ,
ITypeInfo .
ITypeInfo .
CAutoProg::RegisterTypeLibrary, ,
.
GetContainingTypeLib ITypeInfo
ITypeLib .
GetTypeInfoOfGuid ,
(CLSID_CAuto) .
, .
, GetGUID, , , GUID
.
GUIDKIND_DEFAULT_SOURCE_DISP_IID. ,
. IID
,
. (
), , IID IID_EAuto (
, COM).
IID S_OK.
IProvideClassInfo2 ,
.
. :

void OurEvent(void)
ODL- AutoPro3 4-2.
dispinterface EAuto (dispinterface IDispatch
). , dispinterface
UUID, IID_EAuto. OurEvent,
. Dispid 1.
, EAuto
.
4-2. AUTOPROG.ODL

www.books-shop.com

// AutoProg
[ uuid(BFA36560-AD71-11CF-ABBC-00AA00BBB4DA),
helpstring("Autoprog server events interface") ]
dispinterface EAuto
{
properties:
methods:
[ id(1) ] void OurEvent();
};
//

CAuto

[ uuid(AEE97356-B614-11CD-92B4-08002B291EED),
helpstring("AutoProg Server"),
appobject ]
coclass CAuto
{
[ default ] interface IAuto;
interface IDispatch;
[ default, source ] dispinterface EAuto;
};
};
4-3 IProvideClassInfo2.
4-3. IProvideClassInfo2 AUTOPROG.CPP

/////////////
// IProvideClassInfo2
STDMETHODIMP CAutoPCI2::QueryInterface(REFIID riid, void **ppv)
{
return m_pAutoDisp -> QueryInterface(riid, ppv);
}
STDMETHODIMP_ (ULONG)CAutoPCI2::AddRef(void)
{
return m_pAutoDisp -> AddRef();
}
STDMETHODIMP_ (ULONG)CAutoPCI2::Release(void)
{
return m_pAutoDisp -> Release();
}
STDMETHODIMP CAutoPCI2::GetClassInfo(LPTYPEINFO *ppTI)
{
LPTYPEINFO pTI = theProg.GetTypeInfo();
if (pTI == 0)
{
return TYPE_E_CANTLOADLIBRARY;
}
LPTYPELIB pTL;
unsigned int nDummy;
HRESULT hRes = pTI -> GetContainingTypeLib(&pTL, &nDummy);
if (hRes == S_OK)
{
hRes = pTL -> GetTypeInfoOfGuid(CLSID_CAuto, ppTI);
}
pTL -> Release();
return hRes;
}
STDMETHODIMP CAutoPCI2::GetGUID(DWORD dwGuidKind, GUID *pGUID)
{
if (dwGuidKind == GUIDKIND_DEFAULT_SOURCE_DISP_IID)

www.books-shop.com

{
*pGUID = IID_EAuto;
return S_OK;
}
return E_INVALIDARG;
}
AddRef, Release QueryInterface
CAutoDisp. , CAutoDisp
.
CAutoDisp CAutoCPC,
, .
CAutoDisp::QueryInterface , IProvideClassInfo
IProvideClassInfo2, ,
.
, . IConnectionPointContainer,
4-4, . IUnknown
, .
- , EnumConnectionPoints
E_NOTIMPL, , .
EnumConnectionPoints ,
COM- (
Inside OLE, Microsoft Press, 1995).
4-4. IConnectionPointContainer

STDMETHODIMP CAutoCPC::EnumConnectionPoints(LPENUMCONNECTIONPOINTS *)
{
return E_NOTIMPL;
}
STDMETHODIMP CAutoCPC::FindConnectionPoint(REFIID iid,
LPCONNECTIONPOINT *ppCP)
{
if (IsEqualGUID(iid, IID_EAuto))
{
return m_AutoCP.QueryInterface(IID_IConnectionPoint,
(void **)ppCP);
}
return CONNECT_E_NOCONNECTION;
}
FindConnectionPoint ,
. IID IID
, , QueryInterface
CAutoCP ( IConnectionPoint) IID IConnectionPoint.
,
IConnectionPoint , ,
IConnectionPointContainer, , IConnectionPoint.
CAutoCPC CAutoCP (m_AutoCP)
, QueryInterface IConnectionPoint.
IConnectionPoint, 45. , IUnknown,
.
4-5. IConnectionPoint AUTOPROG.CPP

/////////////
// IConnectionPoint
STDMETHODIMP CAutoCP::QueryInterface(REFIID riid, void **ppv)
{
if ((riid == IID_IConnectionPoint) || (riid == IID_IUnknown))

www.books-shop.com

{
AddRef();
*ppv = this;
return S_OK;
}
return E_NOINTERFACE;
}
STDMETHODIMP_ (ULONG)CAutoCP::AddRef(void)
{
return m_pCPC -> AddRef();
}
STDMETHODIMP_ (ULONG)CAutoCP::Release(void)
{
return m_pCPC -> Release();
}
STDMETHODIMP CAutoCP::GetConnectionInterface(IID *pIID)
{
*pIID = IID_EAuto;
return S_OK;
}
STDMETHODIMP CAutoCP::GetConnectionPointContainer(
IConnectionPointContainer **ppCPC)
{
return m_pCPC -> QueryInterface(IID_IConnectionPointContainer,
(LPVOID *)ppCPC);
}
STDMETHODIMP CAutoCP::Advise(LPUNKNOWN pUnkSink, DWORD *pdwCookie)
{
if (m_dwCookie)
{
return CONNECT_E_ADVISELIMIT;
}
LPVOID ptr;
if (FAILED(pUnkSink -> QueryInterface(IID_EAuto, &ptr)))
{
return CONNECT_E_CANNOTCONNECT;
}
m_dwCookie = 1;
*pdwCookie = m_dwCookie;
m_pEvents = (LPUNKNOWN)ptr;
return S_OK;
}
STDMETHODIMP CAutoCP::Unadvise(DWORD dwCookie)
{
if (dwCookie != m_dwCookie)
{
return CONNECT_E_NOCONNECTION;
}
m_pEvents -> Release();
m_dwCookie = 0;
return S_OK;
}
STDMETHODIMP CAutoCP::EnumConnections(LPENUMCONNECTIONS *)
{
return E_NOTIMPL;
}

www.books-shop.com

,
QueryInterface,
IID_IConnectionPoint IID_IUnknown. ,
AddRef Release, m_pCPC, , , AddRef Release,
CAutoDisp. CAutoCP CAutoCPC,
, , , .
GetConnectionInterface , IID
. GetConnectionPointContainer
CAutoCPC QueryInterface
IID_IConnectionPointContainer. Advise .
, ,
, m_dwCookie.
0, , HRESULT
CONNECT_E_AdviseLimit. , ,
QueryInterface
. ,
HRESULT CONNECT_E_CANNOTCONNECT.
QueryInterface , m_dwCookie 1
. , QueryInterface
m_pEvents LPUNKNOWN, .
, Unadvise .
,
( , ,
0 1!).
, CONNECT_E_NOCONNECTION.
m_pEvents m_dwCookie 0. ,
EnumConnections. ,
E_NOTIMPL.
, . ,
, Salary 100.
Payraise 4-6.
4-6. Payraise

STDMETHODIMP CAutoDisp::Payraise(long lSalaryIncrement)


{
m_lSalary += lSalaryIncrement;
if ((m_lSalary % 100) == 0)
{
FireYourEvent();
}
return NO_ERROR;
}
CAutoDisp::FireYourEvent. GetEventIP,
, .
0 ( ),
Invoke. Invoke , , , -,
Invoke , . ,
Invoke . , Invoke
dispid , .
, dispid 1. 4-7
FireYourEvent.
4-7. FireYourEvent

void CAutoDisp::FireYourEvent()

www.books-shop.com

{
LPDISPATCH lpEvents;
if (lpEvents = m_CPC.GetEventIP())
{
EXCEPINFO ex;
unsigned int uTmp;
DISPPARAMS dp = { 0, 0, 0, 0 };
lpEvents -> Invoke(1, IID_NULL, LOCALE_SYSTEM_DEFAULT,
DISPATCH_METHOD, &dp, 0, &ex, &uTmp);
}
}
, (
) , COM-
. AutoProg3
ActiveX, COM- .
, ?
HTML ,
Microsoft Internet Explorer, , Visual Basic 5.0. ,
C++, \CODE\CHAP04\TEST
( test).
, (
) REG-, .
test MFC-, AppWizard.
Test . , Create,
CoCreateInstance, IID
IProvideClassInfo2. , Create
, Delete, GetClassInfo, GetGUID Connect Test
. Delete , Release ,
CoCreateInstance. GetClassInfo GetGUID
IProvideClassInfo2,
(, ,
AutoProg!). Connect
EAuto .
, Connect , Disconnect Try It
. Disconnect , Connect. Try It
Payraise AutoProg 100,
.
. , .
, ,
,
, .
AutoProg, Disconnect Delete;
, .

4.3
( ), ,
, ,
? ,
,
.
, . ,
, ( ) :
, .
1994 OLE
Microsoft, : OLE CDK (Control Developers Kit,
), 16- Microsoft Visual C++ 1.5 32- Visual C++
2.0. CDK MFC ,

%RRNVVKRS

piracy@books-shop.com

Visual C++.
Visual C++, CDK Visual C++ 4.0 MFC 4.0.
MFC ,
OCX 96 ActiveX. MFC
4.0, MFC- OLE (
OCX 96 ). , OLE CDK
MFC OLE C++, ( MFC
C++, ),
:

C++.
MFC.
DLL-
(runtime- MFC C).
MFC,
C++.
(, )
.
MFC ,
C++ . ,
MFC ,
.

Microsoft
C++ .
Microsoft :

C++.
C++ ActiveX Template Library (ATL).
C++ ActiveX BaseCtl ( ActiveX SDK ).
C++ MFC.
Visual Basic.
Java.

.
C++ ,
Java Visual Basic.

4.4 C++
, C++ (
C++).

4.5 MFC
Visual C++ MFC 32- ActiveX
Intel-. Visual C++ MFC
:

Runtime- MFC ( runtime- C).


MFC.
.
AppWizard.
.
, ActiveX.

MFC - (wizard),
. File|New
Project Workspace; New Project
Workspace, OLE (OLE
ControlWizard). ,
, , . ,

www.books-shop.com

, First. Create
OLE, (. 4-1),
:

DLL.
runtime-.
.
.

, .
Next, . :

. 4-1. OLE ControlWizard

, ,
( ,
, Edit Names).
, .
, .
, Insert Object (
Insertable
).
About .
, (simple frame)
.
Windows ( ),
.

4.5.1 , .
, OLE ControlWizard, ,
OCX-.
MFC, .
,
( ). Activates
When Visible OLEMISC_ACTIVATEWHENVISIBLE
. ( )
.

www.books-shop.com

ActiveX
, .
,
. Visual
Basic, .
.
, Invisible At Runtime.
,
Insert Object.
Insertable (
), 2 3. OLE ControlWizard Available In
Insert Object Dialog, Insertable
.
, . ,
:
. ActiveX dispid
AboutBox. Has An About Box
.
, , .
ActiveX (,
), ISimpleFrameSite.
: Acts As A Simple Control
( 17 ).
, Visual Basic,
, SDK,
Microsoft Windows, .
, -,
drag-and-drop. OLE ControlWizard ,
- Windows
,
. (combo box)
,
.
Visual C++ 4.2 OLE ControlWizard
Advanced, , OCX 96
ActiveX ( Visual C++
). :

Windowless Activation ( ).
Unclipped Device Context ( ).
Flicker-Free Activation ( ).
Mouse Pointer Notifications When Inactive (
).
Optimized Drawing Code ( ).
Loads Properties Asynchronously ( ).

3,
OCX 96 ActiveX.
Finish . ,
,
OK. Visual C++.
, 32- Visual C++ 4.2
Windows 95 Windows NT 4.0 .

4.5.2 ?

www.books-shop.com

,
, OLE ControlWizard. Make- FIRST.MAK ,
ANSI Unicode.

3, Unicode- Windows NT, 32 ANSI- Win32. Unicode- ,


Windows NT ,
.
README.TXT .
DEF- .

FIRST.RC RESOURCE.H ; FIRST.RC RESOURCE.H,


C++, .
, About , FIRST.ICO.
, ,
Visual Basic. FIRSTCTL.BMP.
,
, -
.
DLL-, MFC,
, CWinApp. MFC
ActiveX, , COleControlModule,
, , CWinApp. ,
COleControlModule, CFirstApp
FIRST.CPP FIRST.H. ActiveX CWnd (
ColeControl). CFirstCtrl,
FIRSTCTL.CPP FIRSTCTL.H. CFirstPropPage
COlePropertyPage FIRSTPPG.CPP FIRSTPPG.H. COlePropertyPage
CDialog. STDAFX.CPP STDAFX.H MFC
.
FIRST.ODL ODL- (-)
. .
FIRSTLib,
_DFirst ( ) _DFirstEvents ( ).
, First. ,

ODL-. .
DLL-
.
, ,
. , ,
.

, MFC.
.

4.6 : CFirstApp

www.books-shop.com

CFirstApp, , OLE ControlWizard


InitInstance ExitInstance. ,
( ) : DllRegisterServer
DllUnregisterServer. DLL-, ,
( ).
4-8 FIRST.H, 4-9
First.
4-8. FIRST.H

// First.h : FIRST.DLL
#if !defined( __AFXCTL_H__ )
#error include afxctl.h before including this file
#endif
#include "resource.h"
//
/////////////////////////////////////////////////////////////////
// CFirstApp : First.cpp
class CFirstApp : public COleControlModule
{
public:
BOOL InitInstance();
int ExitInstance();
};
extern const GUID CDECL _tlid;
extern const WORD _wVerMajor;
extern const WORD _wVerMinor;
RESOURCE.H,
, . CFirstApp
COleControlModule, (
).
( FIRST.CPP,
, ). _tlid
GUID , wVerMajor _wVerMinor
.
4-9 CFirstApp theApp
, GUID
, 1.0.
CFirstApp::InitInstance, , InitInstance
, . ExitInstance
.
ExitInstance . :
DllRegisterServer DllUnregisterServer. DllRegisterServer AFX_MANAGE_STATE,
AFX_MAINTAIN_STATE, .
,
, AutoPro3.
, _E_TYPELIB.
, DllRegisterServer
. SELFREG_E_CLASS,
. DllUnregisterServer
, ,
.// First.cpp : CFirstApp DLL

#include "stdafx.h"
#include "First.h"
#ifdef _DEBUG
#define new DEBUG_NEW

www.books-shop.com

#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CFirstApp NEAR theApp;
const GUID CDECL BASED_CODE _tlid =
{ 0xa29db7d2, 0xe4e5, 0x11cf, { 0x84, 0x8a, 0, 0xaa,
0, 0x57, 0x54, 0xfd } };
const WORD _wVerMajor = 1;
const WORD _wVerMinor = 0;
//////////////////////////////////////////////////////////////////
// CFirstApp::InitInstance DLL-
BOOL CFirstApp::InitInstance()
{
BOOL bInit = COleControlModule::InitInstance();
if (bInit)
{
//
}
return bInit;
}
//////////////////////////////////////////////////////////////////
// CFirstApp::ExitInstance DLL-
int CFirstApp::ExitInstance()
{
//
return COleControlModule::ExitInstance();
}
//////////////////////////////////////////////////////////////////
// DllRegisterServer
STDAPI DllRegisterServer(void)
{
AFX_MANAGE_STATE(_afxModuleAddrThis);
if (!AfxOleRegisterTypeLib(AfxGetInstanceHandle(), _tlid))
return ResultFromScode(SELFREG_E_TYPELIB);
if (!COleObjectFactoryEx::UpdateRegistryAll(TRUE))
return ResultFromScode(SELFREG_E_CLASS);
}

return NOERROR;

//////////////////////////////////////////////////////////////////
// DllUnregisterServer
STDAPI DllUnregisterServer(void)
{
AFX_MANAGE_STATE(_afxModuleAddrThis);
if (!AfxOleUnregisterTypeLib(_tlid, _wVerMajor, _wVerMinor))

www.books-shop.com

return ResultFromScode(SELFREG_E_TYPELIB);
if (!COleObjectFactoryEx::UpdateRegistryAll(FALSE))
return ResultFromScode(SELFREG_E_CLASS);
return NOERROR;
}

4.6.1 : CFirstCtrl
,
CFirstCtrl.
ActiveX, MFC: ,
COleControl. FIRSTCTL.H
4-10.
4-10. FIRSTCTL.H

// FirstCtl.h : OLE CFirstCtrl


///////////////////////////////////////////////////////////////
// CFirstCtrl : FirstCtl.cpp
class CFirstCtrl : public COleControl
{
DECLARE_DYNCREATE(CFirstCtrl)
//
public:
CFirstCtrl();
//
// ,
// ClassWizard
//{{AFX_VIRTUAL(CFirstCtrl)
public:
virtual void OnDraw(CDC* pdc, const CRect& rcBounds,
const CRect& rcInvalid);
virtual void DoPropExchange(CPropExchange* pPX);
virtual void OnResetState();
//}}AFX_VIRTUAL
//
protected:
~CFirstCtrl();
DECLARE_OLECREATE_EX(CFirstCtrl)
DECLARE_OLETYPELIB(CFirstCtrl)
DECLARE_PROPPAGEIDS(CFirstCtrl)
DECLARE_OLECTLTYPE(CFirstCtrl)

//
//
//
//
//
//

guid
GetTypeInfo

//
//{{AFX_MSG(CFirstCtrl)
// ClassWizard
// .
//
// !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
//

www.books-shop.com

//{{AFX_DISPATCH(CFirstCtrl)
// ClassWizard
// .
//
// !
//}}AFX_DISPATCH
DECLARE_DISPATCH_MAP()
afx_msg void AboutBox();
//
//{{AFX_EVENT(CFirstCtrl)
// ClassWizard
// .
//
// !
//}}AFX_EVENT
DECLARE_EVENT_MAP()
//
public:
enum {
//{{AFX_DISP_ID(CFirstCtrl)
// ClassWizard
// .
//
// !
//}}AFX_DISP_ID
};
};
. DECLARE_DYNCREATE
MFC.
IMPLEMENT_DYNCREATE. ,
(OnDraw), (DoPropExchange) OnResetState.
,
; .
, . (
MFC) . DECLARE_OLECREATE_EX
, DECLARE_OLETYPELIB
ITypeLib
(, MFC), DECLARE_PROPPAGEIDS
CLSID . , DECLARE_OLECTLTYPE
ProgID .
,
, AboutBox.
, dispid ,
.
FIRSTCTL.CPP, 4-11.
4-11. FIRSTCTL.CPP

// FirstCtl.cpp : OLE CFirstCtrl


#include
#include
#include
#include

"stdafx.h"
"First.h"
"FirstCtl.h"
"FirstPpg.h"

#ifdef _DEBUG

www.books-shop.com

#define new DEBUG_NEW


#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
IMPLEMENT_DYNCREATE(CFirstCtrl, COleControl)
///////////////////////////////////////////////////////////////
//
BEGIN_MESSAGE_MAP(CFirstCtrl, COleControl)
//{{AFX_MSG_MAP(CFirstCtrl)
// ClassWizard
// .
//
// !
//}}AFX_MSG_MAP
ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
END_MESSAGE_MAP()
///////////////////////////////////////////////////////////////
//
BEGIN_DISPATCH_MAP(CFirstCtrl, COleControl)
//{{AFX_DISPATCH_MAP(CFirstCtrl)
// ClassWizard
// .
//
// !
//}}AFX_DISPATCH_MAP
DISP_FUNCTION_ID(CFirstCtrl, "AboutBox",
DISPID_ABOUTBOX, AboutBox,
VT_EMPTY, VTS_NONE)
END_DISPATCH_MAP()
///////////////////////////////////////////////////////////////
//
BEGIN_EVENT_MAP(CFirstCtrl, COleControl)
//{{AFX_EVENT_MAP(CFirstCtrl)
// ClassWizard
// .
//
// !
//}}AFX_EVENT_MAP
END_EVENT_MAP()
///////////////////////////////////////////////////////////////
//
// .
// !
BEGIN_PROPPAGEIDS(CFirstCtrl, 1)
PROPPAGEID(CFirstPropPage::guid)
END_PROPPAGEIDS(CFirstCtrl)
///////////////////////////////////////////////////////////////
// GUID

www.books-shop.com

IMPLEMENT_OLECREATE_EX(CFirstCtrl, "FIRST.FirstCtrl.1",
0x14bc5f80, 0xdbd2, 0x11cd, 0x92, 0xb4, 0x8, 0, 0x2b,
0x29, 0x1e, 0xed)
///////////////////////////////////////////////////////////////
//
IMPLEMENT_OLETYPELIB(CFirstCtrl, _tlid, _wVerMajor, _wVerMinor)
///////////////////////////////////////////////////////////////
//
const IID BASED_CODE IID_DFirst =
{ 0xa29db7d3, 0xe4e5, 0x11cf, { 0x84,
0x57,
const IID BASED_CODE IID_DFirstEvents =
{ 0xa29db7d4, 0xe4e5, 0x11cf, { 0x84,
0x57,

0x8a, 0, 0xaa, 0,
0x54, 0xfd } };
0x8a, 0, 0xaa, 0,
0x54, 0xfd } };

///////////////////////////////////////////////////////////////
//
static const DWORD BASED_CODE _dwFirstOleMisc =
OLEMISC_ACTIVATEWHENVISIBLE |
OLEMISC_SETCLIENTSITEFIRST |
OLEMISC_INSIDEOUT |
OLEMISC_CANTLINKINSIDE |
OLEMISC_RECOMPOSEONRESIZE;
IMPLEMENT_OLECTLTYPE(CFirstCtrl, IDS_FIRST, _dwFirstOleMisc)
///////////////////////////////////////////////////////////////
// CFirstCtrl::CFirstCtrlFactory::UpdateRegistry // CFirstCtrl
BOOL CFirstCtrl::CFirstCtrlFactory::UpdateRegistry(BOOL bRegister)
{
// ,
// .
// MFC TechNote 64.
// ,
//
// 6- afxRegApartmentThreading 0.

if (bRegister)
return AfxOleRegisterControlClass(
AfxGetInstanceHandle(),
m_clsid,
m_lpszProgID,
IDS_FIRST,
IDB_FIRST,
afxRegApartmentThreading,
_dwFirstOleMisc,
_tlid,
_wVerMajor,
_wVerMinor);
else
return AfxOleUnregisterClass(m_clsid, m_lpszProgID);

%RRNVVKRS

piracy@books-shop.com

/////////////////////////////////////////////////////////////////
// CFirstCtrl::CFirstCtrl
CFirstCtrl::CFirstCtrl()
{
InitializeIIDs(&IID_DFirst, &IID_DFirstEvents);
//
}
////////////////////////////////////////////////////////////////
// CFirstCtrl::~CFirstCtrl Destructor
CFirstCtrl::~CFirstCtrl()
{
//
}
///////////////////////////////////////////////////////////////
// CFirstCtrl::OnDraw
void CFirstCtrl::OnDraw(
CDC* pdc, const CRect& rcBounds,
const CRect& rcInvalid)
{
//
pdc->FillRect(rcBounds,
CBrush::FromHandle((HBRUSH)GetStockObject(WHITE_BRUSH)));
pdc->Ellipse(rcBounds);
}
////////////////////////////////////////////////////////////////
// CFirstCtrl::DoPropExchange
void CFirstCtrl::DoPropExchange(CPropExchange* pPX)
{
ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
COleControl::DoPropExchange(pPX);
// PX_
//
}
///////////////////////////////////////////////////////////////
// CFirstCtrl::OnResetState
//
void CFirstCtrl::OnResetState()
{
COleControl::OnResetState();

//
//
// DoPropExchange

//

////////////////////////////////////////////////////////////////
// CFirstCtrl::AboutBox About

www.books-shop.com

void CFirstCtrl::AboutBox()
{
CDialog dlgAbout(IDD_ABOUTBOX_FIRST);
dlgAbout.DoModal();
}
////////////////////////////////////////////////////////////////
// CFirstCtrl
, ,
ON_OLEVERB, OLE ControlWizard.
(verbs) OLE.
Edit .
Properties, .
.
AboutBox, OLE ControlWizard About Box.
.
, , .
BEGIN_PROPPAGEIDS ,
CLSID . IMPLEMENT_OLECREATE_EX
CLSID ProgID. ,
IMPLEMENT_OLETYPELIB , DECLARE-
. IID
, _dwFirstOleMisc OLEMISC
. OLEMISC_CANTLINKINSIDE,
, OLEMISC_RECOMPOSEONRESIZE,
,
.
. _dwFirstOleMisc
, IMPLEMENT_OLECTLTYPE. ProgID
.
CFirstCtrl::CfirstCtrlFactory::UpdateRegistry ,
MFC . ,
.
, ,
(. ),
.
CFirstCtrl.
, .
, .


. , .
, OnDraw, . ,
. , OLE ControlWizard,
,
! : -, ,
, -, Circ
Visual Basic Control Development Kit (CDK).
.
: MFC,
, . ActiveX,
OLE, - . , ?
ActiveX , ,
- ,
. ,
ActiveX, :
, (0, 0);

www.books-shop.com

, (0, 0)
, . -
OCX 96 ActiveX, Advanced, OnDraw
,
OCX 96.

COM
16- 32- COM ( Windows NT 3.5)
. ,
CoInitialize ( OleInitialize)
. 32- COM
,
, ,
.
(single-threaded). ,
, .

.
Windows 95 Windows NT 3.51 , (apartment
model). ,
, .
,
. COM
, .
, -
, ,
.
, Windows NT 4.0 ,
. ,

.
COM, Microsoft Knowledge
Base, .
DoPropExchange.
, .
ExchangeVersion, ,
, DoPropExchange ,
,
. ,
.
OnResetState , ,
, . , ,
. -
, . ,
, AboutBox AboutBox.
CDialog ,
DoModal, About.
About (,
), .

4.6.2 : CFirstPropPage
. 3,
,
. , COM-.
(

www.books-shop.com

) , . OLE ControlWizard
. MFC,
COlePropertyPage.
CFirstPropPage. 4-12
FIRSTPPG.H, 4-13 FIRSTPPG.CPP.
4-12. FIRSTPPG.H

// FirstPpg.h : CFirstPropPage
///////////////////////////////////////////////////////////////
// CFirstPropPage : FirstPpg.cpp
class CFirstPropPage : public COlePropertyPage
{
DECLARE_DYNCREATE(CFirstPropPage)
DECLARE_OLECREATE_EX(CFirstPropPage)
//
public:
CFirstPropPage();
//
//{{AFX_DATA(CFirstPropPage)
enum { IDD = IDD_PROPPAGE_FIRST };
// ClassWizard .
//
// !
//}}AFX_DATA//
protected:
virtual void DoDataExchange(CDataExchange* pDX);
// DDX/DDV
//
protected:
//{{AFX_MSG(CFirstPropPage)
// ClassWizard .
//
// !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
FIRSTPPG.H ,
. , ,
( Automation).
, , Visual C++

. ,
(IDD_PROPPAGE_FIRST).
DoDataExchange /
(DDX/DDV),
.
, .
Visual C++, , , .
4-13. FIRSTPPG.CPP

// FirstPpg.cpp :
// CFirstPropPage
#include "stdafx.h"
#include "First.h"
#include "FirstPpg.h"

www.books-shop.com

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
IMPLEMENT_DYNCREATE(CFirstPropPage, COlePropertyPage)
//////////////////////////////////////////////////////////////
//
BEGIN_MESSAGE_MAP(CFirstPropPage, COlePropertyPage)
//{{AFX_MSG_MAP(CFirstPropPage)
// ClassWizard
// .
//
// !
//}}AFX_MSG_MAPEND_MESSAGE_MAP()
///////////////////////////////////////////////////////////////
// GUID
IMPLEMENT_OLECREATE_EX(CFirstPropPage, "FIRST.FirstPropPage.1",
0xa29db7d5, 0xe4e5, 0x11cf, 0x84, 0x8a, 0, 0xaa, 0,
0x57, 0x54, 0xfd)
///////////////////////////////////////////////////////////////
// CFirstPropPage::CFirstPropPageFactory::UpdateRegistry // CFirstPropPage
BOOL CFirstPropPage::CFirstPropPageFactory::UpdateRegistry(
BOOL bRegister)
{
if (bRegister)
return AfxOleRegisterPropertyPageClass(
AfxGetInstanceHandle(),
m_clsid, IDS_FIRST_PPG);
else
return AfxOleUnregisterClass(m_clsid, NULL);
}
//////////////////////////////////////////////////////////////
// CFirstPropPage::CFirstPropPage
CFirstPropPage::CFirstPropPage() :
COlePropertyPage(IDD, IDS_FIRST_PPG_CAPTION)
{
//{{AFX_DATA_INIT(CFirstPropPage)
// ClassWizard
// .
//
// !
//}}AFX_DATA_INIT}
///////////////////////////////////////////////////////////////
// CFirstPropPage::DoDataExchange
//
void CFirstPropPage::DoDataExchange(CDataExchange* pDX)
{
//{{AFX_DATA_MAP(CFirstPropPage)
// ClassWizard
// DDP, DDV DDV.
//
// !
//}}AFX_DATA_MAP
DDP_PostProcessing(pDX);
}

www.books-shop.com

///////////////////////////////////////////////////////////////
// CFirstPropPage
CFirstPropPage . ActiveX,
IMPLEMENT_OLECREATE_EX CLSID
ProgID. , UpdateRegistry,
.
,
.
, .
DoDataExchange,
DDX DDP_PostProcessing.
, Visual C++
.

4.7 OCX 96 ActiveX


MFC
OLE ControlWizard , OCX 96
ActiveX, . ,
, ,

.
OLEMISC_ACTIVATEWHENVISIBLE, , COleControl,
GetControlFlags. 4-14.
4-14. GetControlFlags, DWORD
CNowndnoactivateCtrl::GetControlFlags()

{
DWORD dwFlags = COleControl::GetControlFlags();
// .
//
// m_hWnd ,
// NULL.
dw_Flags |= windowlessActivate;

//
// .
// WM_SETCURSOR
// WM_MOUSEMOVE, m_hWnd
// , NULL.
dw_Flags |= pointerInactive;
return dwFlags;

, MFC ,
OCX 96. , ,
, (, ).
MFC GetControlFlags
.
, (
, ),
, GetControlFlags. ,
OnDraw. , ,
, GDI
.

www.books-shop.com

, ,
m_lReadyState,
.

4.8 Runtime- MFC


, MFC, , ,
, ? ! ,
MFC , ,
runtime- MFC DLL.
Internet, , DLL-
, (-). ,
MFC DLL, ,
MFC. MFC?
ActiveX , VBX,
.
. , VBX
ActiveX. , ,
,
. ,
(, ATL), , MFC.
, .
C++? MFC. ,
COM ATL,
.
MFC ,
COleControl, COlePropertyPage COleControlModule,
MFC DLL-.
, ,
.
DLL- , ANSI
Unicode-. MFCxx.DLL, xx
MFC, DLL-. D
, MFC40D.DLL. Unicode- U , MFC40U.DLL
MFC40UD.DLL.
OLE Windows
, runtime- MFC () .
, ,
,
.

4.9 First

. Build
. , , ,
.
, RegSvr32 ( \MSDEV\BIN).
(-), DLL, :

regsvr32 /u control.ocx
control.ocx DLL-, (-).
:

regsvr32 control.ocx

www.books-shop.com


ActiveX.
,
.
? OLE CDK 1994 ,
OLE (Microsoft Access 2.0),
. - ,
Microsoft OLE CDK Visual C++ 4.x ( ).
, ,
, , ,
, .
.


ActiveX (, Microsoft Internet
Explorer 3.0 , Microsoft Visual Basic 4.0 Microsoft Visual FoxPro 3.0
), , .
, Visual Basic.
Visual Basic, ,
.

4.10
(TSTCON32.EXE) Tools
Visual C++. , ,
Start. , ActiveX

Edit|Insert OLE Control. Insert OLE Control,
, .
First Control, .
. 4-2 , .

. 4-2. First

www.books-shop.com

, , ,
. ,
, . Edit|Invoke
Methods; , . 4-3.

. 4-3. Invoke Control Method First


AboutBox,
About . , Invoke.
,
Invoke Control Method. ,
. - ,
.
.
.
, .
,
View|Properties.
, .
,
.
Edit|Properties First Control Object. ,
. 4-4.

www.books-shop.com

. 4-4. First ()
- ,
View|Event Log
. ,
View|Notification Log .

.
. Edit|Set Ambient Properties Ambient
Properties, . 4-5, .
- ,
, ,
, .
, .
, ,
. :
, , (
), .
,
. ,
. OnDraw,
,
.
,
. ,
,
. ,
(,
).

%RRNVVKRS

piracy@books-shop.com

. 4-5. Ambient Properties

4.11 ActiveX Template


Library (ATL)
Microsoft
Visual C++. ,
. Galileo (,
). Galileo ,
,
.
,
. ,
:

,
.
, .
.

, Microsoft ,
. ,
COM, ,
COM-,
,
, .
Microsoft, COM-,

. , ,
COM, .
Galileo C++,
.
ActiveX Template Library, ATL. ,
,
COM- ATL . , 1996 World Wide Web
ATL 1.0.
1996 ATL 1.1, ,
,
. ,
. ATL Microsoft
ActiveX C++.
MFC: ,
C++ , ATL

www.books-shop.com

C++ , .
, ATL MFC.
ATL C++, COM
, MFC. ,
, ++. ,
- ,
,
. ,

template< T > class MyClass


{
T *pNext;
T *pPrev;
};
- MyClass, ,
. , :

MyClass< int > iMyClass;


:

class iMyClass
{
int *pNext;
int *pPrev;
};
,

.
, ATL ,
. COM- CComObjectBase, IUnknown IClassFactory ( ,
).
- CComDualImpl,
IDispatch , ISupportErrorInfo.
ATL 1.x
, . ATL 1.1
IClassFactory2 IProvideClassInfo2.
ATL 1.x .
ATL
ATL 2.0, .
OCX 96 ActiveX.
,
. , Visual C++
ActiveX ATL (, IDE),
. ,
, , ,
/ .
, ,
, . runtime . ATL ,
. ,

, . RTTI
(runtime- ), . ATL
,
runtime-.
ATL ,
. -, ,
.

www.books-shop.com

ATL .
ATL 2.0 . ATL
( !) , .
-, ATL .
, MFC, , ATL
-,
. , ATL CWinApp,
. , , ATL
COM-.
, ATL 2.0 ,
Visual C++, . :n
ATL (, ATL 1.x)
ATL 2.x.

ATL, ,
.

(, IPerPropertyBag) ,
ATL, ATL, Visual C++
. , . ,
,
.

4.12 ActiveX
BaseCtl
C++ OLE CDK
Visual Basic (Marc Wanschnider) ,
MFC API ,
,
COM.
,
. 1996 Microsoft Developers
Network (MSDN), .
,
, .
ActiveX SDK 1996 ATL
( ),
Visual Basic SDK ActiveX BaseCtl (
Win32 BaseCtl).
Microsoft, ,
ATL.
.
, , ActiveX BaseCtl
( - ).
. , Visual
Basic. C++,
, .
, MFC,
. BaseCtl MF-
, Windows
BaseCtl ,
OCX 96 ActiveX,
1996 . ATL
BaseCtl, , BaseCtl,
( ) ATL.

www.books-shop.com

4.13 ActiveX Java


Visual J++
Visual J++ Microsoft
COM Java. , Java Sun Microsystems
. Java ,
Java COM- .
Visual J++
, , (
), ( ) ,
Java. , COM,
Visual J++ , .
, . COM Java
, .
Microsoft Java (VM),
COM Java.
COM Visual J++, 1996 .
, , HTML-
, Automation .
:

import mytlbs.hexedt32;
class Jtest
{
public void CallMe()
{
CGateway x;
x.Show();
}
}
, (
, #include) , Java.
, , .
, ,
. , import mytlbs.hexedt32.CGateway;
CGateway.
JTest,
CallMe. CallMe CGateway (, ,
COM- ) Show.
Java . ,
, COM- Java.
Visual J++ ( ,
, . .) - :

.
Java?

Microsoft Java-
(, AWT ), VM
Java. ( Sun) ,
, Java.
, COM.

www.books-shop.com

4.14 ,

,
MFC.
, .
, ,
. ,
, . ,

Visual Basic, Visual Basic .
( ), Visual J++. :
C++. ( ,
) MFC,
.
, ATL ( )
,
COM, . ,
MFC ,
.

www.books-shop.com

ActiveX

, :
, ! , , ,
, , .
ActiveX, , ClassWizard
, MFC. ?
3, : ,
.
, ,
, ,
.
,
.
. ,
.
4 ,
(, ) (,
).
,
ActiveX, .
.

5.1
OLECTL.H ,
dispid (
). ,
,
.
dispid. OLECTL.H,
OCX 96 ActiveX.
*

Dispid

BackColor

DISPID_AMBIENT_BACKCOLOR

701

DisplayName

DISPID_AMBIENT_DISPLAYNAME

702

Font

DISPID_AMBIENT_FONT

703

ForeColor

DISPID_AMBIENT_FORECOLOR

704

LocaleID

DISPID_AMBIENT_LOCALEID

705

MessageReflect

DISPID_AMBIENT_MESSAGEREFLECT

706

ScaleUnits

DISPID_AMBIENT_SCALEUNITS

707

TextAlign

DISPID_AMBIENT_TEXTALIGN

708

UserMode

DISPID_AMBIENT_USERMODE

709

UIDead

DISPID_AMBIENT_UIDEAD

710

www.books-shop.com

ShowGrabHandles

DISPID_AMBIENT_SHOWGRABHANDLES 711

ShowHatching

DISPID_AMBIENT_SHOWHATCHING

712

DisplayAsDefaultButton

DISPID_AMBIENT_DISPLAYASDEFAULT

713

SupportMnemonics

DISPID_AMBIENT_SUPPORTMNEMONICS 714

AutoClip

DISPID_AMBIENT_AUTOCLIP

715

Appearance

DISPID_AMBIENT_APPEARANCE

716

Palette (OCX 96)

DISPID_AMBIENT_PALETTE

726

TransferPriority (ActiveX) DISPID_AMBIENT_TRANSFERPRIORITY

728

OLE, OCX 96,


ActiveX, , SDK.

, dispid,
,
(DISPID_AMBIENT_FONT). ,
. OLECTL.H
INCLUDE Visual C++, .
C:\MSDEV\INCLUDE. Win32 SDK,
, C:\MSTOOLS\INCLUDE. ,
ActiveX SDK, (
C:\INETSDK\INCLUDE).
.
, .
, , .
, ,
- .
,
(, BackColor
), LocaleID, MessageReflect, TextAlign,
SupportMnemonics, AutoClip, Palette TransferPriority.

LocaleID ,
. ,
.
MessageReflect TRUE,
Microsoft Windows, .
ActiveX,
Windows. , Windows
.
, WM_COMMAND
BN_CLICKED. ActiveX,
VBX,
, .
, ,
, -
. MFC
COleControl. ,
-,
( , OCM_
OLECTL.H). ,
ActiveX , .
(
), MessageReflect TRUE,
-.
TextAlign ,
. 0,
: , . 1
, 2 , 3 4
( ).

www.books-shop.com

SupportMnemonics ,

, .
FALSE,
, , , ,
(,
).
AutoClip ,
. TRUE,
lprcClipRect IOleInPlaceObject::SetObjectRects.
, FALSE.
Palette HPAL ( ) .
, (
,
). ,
, , , .
NULL,
,
( ) .
TransferPriority ,
.

,
.
MFC . , ,
MFC, Font,
Font .
, . ,
BackColor. ,
BackColor .
,
BackColor.

5.2
, ,
. ,
, (tab order).
,
( ). /
, .
, ,
. IDispatch
.
.
( -
). dispid, dispid
.
, .
MFC Enabled,
. ,
. , ,
. ,
Enabled
. , ,
.
dispid 0x80010000 0x8001FFFF.
, OLECTL.H
. .

www.books-shop.com

5.3

Name

Dispid

. ,
Visual Basic (, Text1),
0x80010000

.

Visible 0x80010007 , .
Parent 0x80010008 Automation , .
Cancel 0x80010037

, Cancel ,
.

TRUE ,
Default 0x80010038 , FALSE
.

ActiveX
.
, ;
-.
, Visual Basic, ,
. ,
, , OLE dispid.
ActiveX,
, .

5.4
, ,
! ,
( , Automation) ,
.
, MFC
. ,
dispid, ,
. :

dispid
.
, , dispid.
( ) ,
, (
MFC) ,
.

, . ,
, ,
ActiveX. ,
, .
,
OLECTL.H, OC 96 ActiveX.

www.books-shop.com

5.5

Dispid

AutoSize

500

TRUE, ,
.

BackColor*

501

, .

BackStyle

502

,
. , ,
.

BorderColor

503

BorderStyle

504

.
, .

BorderWidth 505

DrawMode

507

(, Draw),
,
.

DrawStyle

508

, .

DrawWidth

509

, .

FillColor

510

FillStyle

511

Font

512

, .

ForeColor

513

, .

Enabled

514

, .

HWnd

515

TabStop

516

, (
Tab).

Text

517

( , Caption).

Caption

518

( , Text).

BorderVisible 519

, .

Appearance

520

MousePointer 521

Windows,
.

MouseIcon

522

MousePointer 99, MouseIcon


.

Picture

523

IsValid

524

, , .

ReadyState

525

(
).

, MFC 4.2 ( Microsoft


Visual C++ 4.2), .

, , ,
MFC .
, ,
, ,
. ,
. ,
,
.

5.5.1

%RRNVVKRS

piracy@books-shop.com

First
ClassWizard. ClassWizard.
OLE Automation, CFirstCtrl Add Property.
External Name OK.
, : BackColor,
Caption, Enabled, Font, ForeColor hWnd.
, .
ANSI-, Unicode,
Windows NT. , ,
ClassWizard ODL- .
:

[id(DISPID_BACKCOLOR), bindable, requestedit] OLE_COLOR BackColor;


[id(DISPID_CAPTION), bindable, requestedit] BSTR Caption;
[id(DISPID_ENABLED), bindable, requestedit] boolean Enabled;
[id(DISPID_FONT), bindable] IFontDisp* Font;
[id(DISPID_FORECOLOR), bindable, requestedit] OLE_COLOR ForeColor;
[id(DISPID_HWND)] OLE_HANDLE hWnd;
, (bindable)
, .
, requestedit; ,
.
.
, ,
, , (
) .
First
.
, , ,
:

DISP_STOCKPROP_BACKCOLOR()
DISP_STOCKPROP_CAPTION()
DISP_STOCKPROP_ENABLED()
DISP_STOCKPROP_FONT()
DISP_STOCKPROP_FORECOLOR()
DISP_STOCKPROP_HWND()
, .
, -
. - .
, , Microsoft , COM-
. !
.
, Visual Basic 4.0 ( , ,
, ).
Visual Basic 4.0, Tools|Custom Controls.
. ,
, , . 5-1.

.5-1. , OLE ControlWizard


.
. ? , .
. ,

www.books-shop.com

. ,
. , , OLE ControlWizard:

pdc->FillRect(rcBounds,
CBrush::FromHandle((HBRUSH)GetStockObject(WHITE_BRUSH)));
pdc->Ellipse(rcBounds);
, .
,
, . ? ,
- runtime- ? ,
.
, Visual Basic,
( ), .
, ,
. : Visual Basic
,
. ,
, Text, Caption hWnd;
.
Visual Basic,
. ,
.
, ,
Visual Basic. First (
):

Begin FIRSTLib.First First1


Height
=
1335
Left
=
240
TabIndex
=
0
Top
=
240
Width
=
2895
_Version
=
65536
_Extentx
=
5106
_Extenty
=
2355
_StockProps
=
79
ForeColor
=
16711680
BackColor
=
16711935
BeginProperty font {FB8F0823-0164-101B-84ED-08002B2EC713}
name
=
"MS Sans Serif"
charset
=
0
weight
=
700
size
=
9.75
underline
=
0
False
italic
=
-1 True
strikethrough
=
0
False
EndProperty
End
ForeColor, BackColor Font. , ForeColor
BackColor Visual Basic ,
, , Font
. ,
, (weight = 700) (italic = 1)
, (size = 9.75).

www.books-shop.com

Visual Basic, .
, About, AboutBox. ,
, . ,
Custom, (-) . ,
, OLE ControlWizard
.

5.6
- .
, . MFC
, .
, InternalGetFont COleControl ,
GetBackColor .
InternalGetFont ,
(DC) .
, COleControl
SelectStockFont.
OnDraw :

CFont *hfOld = SelectStockFont(pdc);


CBrush cbBack(TranslateColor(GetBackColor()));
pdc-> FillRect(rcBounds, &cbBack);
pdc-> SetTextColor(TranslateColor(GetForeColor()));
RECT rcTemp = rcBounds;
pdc-> DrawText(InternalGetText(), -1, &rcTemp,
DT_SINGLELINE | DT_CENTER, DT_VCENTER);
pdc-> SelectObject(hfOld);
,
MFC, , ,
.
: , (
) . ,
, (0,0) .

. ,
.
DC,
hfOld. ,
, DC.
DC,
, ,
OCX 96.
, cbBack, . ,
BackColor GetBackColor.
, GetBackColor
TranslateColor.
OLE_COLOR, GetBackColor, COLORREF,
CBrush::CBrush. FillRect ,
(. ).
ForeColor. , TranslateColor GetForeColor
. GDI, SetBkMode,
TRANSPARENT. , .
(OPAQUE),
.
BackColor , DC ( ).

www.books-shop.com


, , DC ,
Windows , ,
OnDraw . , MFC,
MFC WM_PAINT. ,
DC , UI-.

DrawText,
Caption InternalGetText
, DT_VCENTER DT_CENTER. DT_VCENTER
DT_SINGLELINE, .
SelectObject, DC
, hfOld.
, , .
Property Visual Basic,
.

5.7
, ActiveX,
,
, . , Visual Basic
BASIC.
. Visual
Basic: ,
. Visual Basic
object.property object.method, object
.
, Visual Basic First First1.
, Caption:

First1.Caption = "Ive been set programmatically"


Click , ,
,
, . .

5.8
, .
- ,
. ,
, .
, .
COM, HRESULT.
, .
HRESULT , ,
- , , .
, HRESULT
, (,
), ,
(, RPC, Win32 COM), .
. ,
First .
, .

www.books-shop.com

short

HRESULT ( 16 ).
.

ErrorName BSTR

#define. .

Facility

BSTR

HRESULT. .

Message

BSTR

, HRESULT.
.

HResult

SCODE HRESULT.

Severity

BSTR

Code

HRESULT, .
.

. -, BSTR? -,
?
BSTR Automation . BSTR
. C C++,
-. ,
, .
API ,
. BSTR
API, Automation.
SysAllocString SysStringLen. Automation (, Visual Basic)
BSTR , MFC
.
,
. HRESULT
, .
HResult.
, .
. First Visual C++ ClassWizard.
OLE Automation CfirstCtrl. ,
:

Get/Set Methods (
Add Property).
, , HResult, Set Function .
ClassWizard ,
.

, ClassWizard
. .
, Get ,
, .
CString strResult, AllocSysString
. MFC CString BSTR API AllocSysString,
CString BSTR.
Visual Basic. Visual Basic
First ( ) Tools|Custom
Controls. , ,
. HResult .
, HResult? Code, Error, Facility, Message
Severity , Visual Basic .
HResult ? .
Click.
HResult First :

www.books-shop.com

First1.HResult = &H8001FFFF
. , ,
, Visual Basic. : Visual Basic
SCODE, ( !)
HResult.
? , - ,
HRESULT. ,
, HRESULT (32
), long.
. ClassWizard, HResult
Delete. ; ,
CFirstCtrl::GetHResult CFirstCtrl::SetHResult. Yes.
GetHResult SetHResult. ,
ODL- , ClassWizard
. , , ,
. Visual C++ ,
.
, ,
, !
HResult, long.
, Visual Basic.
HResult Visual Basic,
, .


, , .
!

HRESULT WINERROR.H, Microsoft Visual C++ Win32 SDK.


. 5-2.
HResult
. , ,
. , HRESULT
:
1.
2.

HResult.
HRESULT,
Caption. (), HRESULT .
3. HRESULT , Facility
, HRESULT. Code ,
Severity : Success (), Informational (
), Warning () Error (). ErrorName
, HRESULT, Message
( Caption ).

www.books-shop.com

. 5-2. HRESULT
:
1.

,
HRESULT.
2. HResult , .
3. , ,
.
4. Message,
ErrorName. , Caption.
5. Code HRESULT, 16
HResult.
6. Facility HRESULT HResult
Facility . .
7. Severity HRESULT HResult
Severity . .
.
FIRSTCTL.H
:

private:
long
BOOL
CString
CString

m_HResult;
m_bIsValid;
m_csSymbol;
m_csMessage;

m_HResult HRESULT, HResult.


m_bIsValid , m_HResult
HRESULT. m_csSymbol HRESULT, m_csMessage
.
. CString
CString. CFirstCtrl InitializeIIDs:

m_HResult = 0;
m_bIsValid = FALSE;

HResult ( m_HResult). , SetHResult,
5-1.
5-1. , SetHResult

long CFirstCtrl::GetHResult()
{
return m_HResult;
}
short CFirstCtrl::GetCode()
{
if (m_bIsValid)
{

www.books-shop.com

return short(m_HResult & 0xFFFF);


}
else
{
return -1;
}
}
BSTR CFirstCtrl::GetFacility()
{
CString strResult;
short nFacility = IDS_NOVALID_HRESULT;
if (m_bIsValid)
{
nFacility = short((m_HResult & 0x0FFF0000) >> 16);
switch (nFacility)
{
case 0: case 1: case 2: case 3:
case 4: case 7: case 8: case 9:
case 10: case 11:
break;
default:
nFacility = -1;
}
nFacility += IDS_FACILITY_NULL;
}
strResult.LoadString(nFacility);
return strResult.AllocSysString();
}
BSTR CFirstCtrl::GetSeverity()
{
CString strResult;
short nSeverity = IDS_NOVALID_HRESULT;

if (m_bIsValid)
{
nSeverity = short((m_HResult & 0xC0000000) >> 30) +
IDS_SEVERITY_SUCCESS;
}
strResult.LoadString(nSeverity);
return strResult.AllocSysString();

BSTR CFirstCtrl::GetMessage()
{
return m_csMessage.AllocSysString();
}
BSTR CFirstCtrl::GetErrorName()
{
return m_csSymbol.AllocSysString();
}
GetHResult m_HResult.
. GetCode HRESULT 16
, 16 .

www.books-shop.com

1
HRESULT, 1 0xFFFF,
.

GetFacility . strResult, CString,


, nFacility
HRESULT. ,
. ,
HRESULT ( . 5-3).
nFacility ,
HRESULT. AND 0x0FFF0000
, 16 16 ,
nFacility.
HRESULT , nFacility
.
, CString::LoadString,
BSTR CString::AllocSysString.
,
, IDS_FACILITY_NULL (
NULL, 0,
IDS_FACILITY_NULL). ,
IDS_FACILITY_NULL 1.

IDS_NO_FACILITY

101

Unknown Facility

IDS_FACILITY_NULL

102

NULL

IDS_FACILITY_RPC

103

RPC

IDS_FACILITY_DISPATCH

104

Automation

IDS_FACILITY_STORAGE

105

Storage

IDS_FACILITY_ITF

106

Interfaces (COM)

IDS_FACILITY_WIN32

109

Win32

IDS_FACILITY_WINDOWS

110

Windows

IDS_FACILITY_SSPI

111

SSPI

IDS_FACILITY_CONTROL

112

Controls

IDS_FACILITY_CERT

113

Cert

IDS_SEVERITY_SUCCESS

114

Success

IDS_SEVERITY_INFORMATIONAL 115

Informational

IDS_SEVERITY_WARNING

116

Warning

IDS_SEVERITY_ERROR

117

Error

IDS_SEVERITY_HRESULT

118

The current HRESULT is not valid

.5-3. , First.
, HRESULT
, GetSeverity, , switch
2 ,
. GetMessage GetErrorName
CString:: AllocSysString.
. SetHResult,
HResult, HRESULT
Message, ErrorName Caption ,
. First
( , )

www.books-shop.com

WINERROR.H. Visual C++ Win32 SDK.


. 5-2
SetHResult .
5-2. SetHResult

void CFirstCtrl::SetHResult(long nNewValue)


{
CString csFile;
csFile.LoadString(IDS_HRESULT_FILE);
CStdioFile cfCodes;
m_csMessage.Empty();
m_csSymbol.Empty();
if (cfCodes.Open(csFile, CFile::modeRead | CFile::typeText) == 0)
{
m_bIsValid = FALSE;
return;
}
CString csLine;
m_bIsValid = FALSE;
while (GetNextDefineLine(&cfCodes, &csLine))
{
if (GetTheCode(&csLine) == nNewValue)
{
m_bIsValid = TRUE;
break;
}
}
if (m_bIsValid)
{
csLine = m_csSymbol + _T(": ") + m_csMessage;
}
else
{
csLine.LoadString(IDS_NOVALID_HRESULT);
}
m_HResult = nNewValue;
SetText(csLine);
SetModifiedFlag();
cfCodes.Close();
// !!

}
BOOL CFirstCtrl::GetNextDefineLine(CStdioFile *cfFile,
CString *csLine)
{
_TCHAR szBuf[256];
CString csCompare;
BOOL bFound = FALSE;
LPTSTR lpszCnt;
do
{
try
{
lpszCnt = cfFile -> ReadString(szBuf, 255);
}
catch (CFileException *e)
{
e -> Delete();
break;
}

%RRNVVKRS

piracy@books-shop.com

if (lpszCnt == NULL)
{
break;
}
csCompare = szBuf;
bFound = (csCompare.Find(_T("// MessageText:")) != -1);
}
while (bFound == FALSE);
if (bFound)
{
try
{
//
cfFile -> ReadString(szBuf, 255);
// ()
m_csMessage.Empty();
do
{
cfFile -> ReadString(szBuf, 255);
if (szBuf[3])
{
if (!m_csMessage.IsEmpty())
{
m_csMessage += _T(" ");
}
szBuf[_tcslen(szBuf) - 1] = TCHAR(0);
m_csMessage += szBuf + 4;
}
}
while (szBuf[3]);
//
lpszCnt = cfFile -> ReadString(szBuf, 255);
}
catch (CFileException *e)
{
m_csMessage.Empty();
e -> Delete();
return FALSE;
}
if (lpszCnt == NULL)
{
m_csMessage.Empty();
return FALSE;
}
*csLine = szBuf;
return TRUE;
}
return FALSE;
}
long CFirstCtrl::GetTheCode(CString *csLine)
{
// #define
int i = 7;
// -
while ((csLine -> GetLength() > i) &&
(_istspace(csLine -> GetAt(i))))
{
++i;
}
if (csLine -> GetLength() <= i)
{
return 0;
}

www.books-shop.com

//
m_csSymbol.Empty();
while ((csLine -> GetLength() > i) &&
!(_istspace(csLine -> GetAt(i))))
{
m_csSymbol += csLine -> GetAt(i);
++i;
}
if (csLine -> GetLength() <= i)
{
m_csSymbol.Empty();
return 0;
}
// -
while ((csLine -> GetLength() > i) &&
(_istspace(csLine -> GetAt(i))))
{
++i;
}
if (csLine -> GetLength() <= i)
{
m_csSymbol.Empty();
return 0;
}
// WINERROR.H
// _HRESULT_TYPEDEF(),
// .
int pos;
if ((pos = csLine ->
Find(_T("_HRESULT_TYPEDEF_(")))
!= -1)
{
i = pos + 18;
// 18
}
//
CString csNumber;
try
{
csNumber = csLine -> Mid(i);
}
catch (CMemoryException *e)
{
m_csSymbol.Empty();
e -> Delete();
return 0;
}
return _tcstoul(csNumber, NULL, 0);
}
CString
WINERROR.H. ,
IDS_HRESULT_FILE C:\\MSDEV\\INCLUDE\\WINERROR.H (
WINERROR.H ).
(m_csMessage m_csSymbol), .
cfCodes CStdioFile. CStdioFile
MFC, . ,
. CStdioFile
CFile,
, CStdioFile .

www.books-shop.com

WINERROR.H .
- , .

GetNextDefineLine , ( ,
). GetNextDefineLine ,
csLine. , GetTheCode, ,
. , HRESULT,
. , , GetNextDefineLine
FALSE ,
. GetTheCode , m_bIsValid
TRUE, m_csSymbol m_csMessage
;
, . .
SetHResult m_HResult
Caption SetText. , ,
SetModifiedFlag, . Close
, ( ,
, ).
GetNextDefine , .
, WINERROR.H Message Compiler (MC)
( MC Visual C++
Win32 SDK). , !
:

//
// MessageId: RPC_E_UNEXPECTED
//
// MessageText:
//
// An internal error occured
//
#define RPC_E_UNEXPECTED

_HRESULT_TYPEDEF_(0x8001FFFFL)

, ,
, MessageText:, #define,
( ) _HRESULT_TYPEDEF_. ,
MessageId:, CStdioFile::ReadString,
, CString::Find, .
ReadString , .
, , ReadString NULL,
. ,
hFound TRUE.
,
ReadString. m_csMessage
, .
, NULL.
, TCHAR(0) \0. ,
\0 char, Unicode, , ,
, , .
, strlen _tcslen,
, _UNICODE. ANSI
strlen, Unicode (,
, WINERROR.H ANSI). ,
m_csMessage 4 , ,
( ,
). , .

www.books-shop.com

. , , #define. ReadString ,
, #define CString,
.
GetTheCode . i
. 7
#define ( 7
).
, - (white space).
( Unicode) -
_istspace.
, m_csSymbol. . _HRESULT_TYPEDEF_,
. WINERROR.H , HRESULT
, ,
- .
, Unicode _tctoul (
strtoul wctoul). ASCII-
. 0x, , 0 ,
. 0,
_tctoul .
GetTheCode HRESULT.
,
:

BOOL GetNextDefineLine(CStdioFile *cfFile, CString *csLine);


long GetTheCode(CString *csLine);

5.9
. ,
WINERROR.H .
, HResult
, 0x7FFFFFFF, .
,
( , ,
). HResult
Visual Basic, . ( Visual Basic),
&H, Visual Basic
, . . 5-4
, , HRESULT.

www.books-shop.com

.5-4. First,
, ,
, .
:

.
.
.
HRESULT, WINERROR.H.
, .

ActiveX
.

5.10

(, , ),
, C++ MFC,
COM STDMETHOD
STDMETHODIMP ( AutoProg ,
). ,
IDL ( ODL, !)
. ,
. , ,
,
H, CPP IDL .
, . MFC ClassWizard
:

.
.
/ .

, , COM
. MFC ,
.

www.books-shop.com

(
), put ( get
, ). , ,
Automation , put
,
put .
C++, ,
. , Visual Basic
. Microsoft Visual J++
.

www.books-shop.com

:
.
.
: , ActiveX,
. ,
, -
. ? .

First 5 Microsoft Visual Basic 4.0,


, FRM-
. .
,
. , FRM- First :

Begin FirstLib.First First1


Height
=
1695
Left
=
120
TabIndex
=
0
Top
=
120
Width
=
4215
_Version
=
65536
_ExtentX
=
7435
_ExtentY
=
2990
_StockProps
=
79
Caption
=
"Hello 32-bit VB4!"
ForeColor
=
255
BackColor
=
16711680
BeginProperty Font {FB8F0823-0164-101B-84ED-08002B2EC713}
name
=
"Algerian"
charset
=
1
weight
=
400
size
=
20.25
underline
=
0
False
italic
=
0
False
strikethrough
=
0
False
EndProperty
End
Caption, ForeColor BackColor.
, MFC.
(, HResult Message) . , Visual Basic
(, Height
TabIndex). , , FRM- ,
Visual Basic
.
, .
, :
, , .
IPersistStreamInit .

www.books-shop.com


IPersistStorage. IPersistxxx,
.
, , ,

IPersistStorage () IPersistStreamInit.
, .
(, ) IDataObject
, / .
, ,
IPersistPropertyBag.
,
( ),
.

, , .
HTML-.
ActiveX Internet-
13, ActiveX Internet.
, , ,
.
IPersistStorage :
1.

IPersistStorage
QueryInterface.
2. IStorage.
3. Save Load IPersistStorage ,
IStorage.
4. ,
.
IPersistStreamInit , ,
IStream IStorage, .
IPersistPropertyBag :
1.
2.
3.
4.

IPersistPropertyBag
QueryInterface.
IPropertyBag,
IErrorLog ( ).
Save Load IPersistPropertyBag ,
IPropertyBag IErrorLog (
IErrorLog Load).

IPropertyBag::Read IPropertyBag::Write. ,
VARIANT.
.

(, ),

IPersistStream ( . .),
IPersistPropertyBag. ,
.
, ,
. .

www.books-shop.com

Visual Basic,
. ,
,
, IDataObject.
First File|Save
Property Set, TMP.DFL. ,
( , ,
First ,
C:\MSDEV\BIN). TMP.DFL
, DocView, Visual C++.
DFVIEW.EXE.
, . ,
. . 6-1.
, .

.6-1. , First 5
, , , ,
.
,
( , Code, Facility Severity,
HResult ).
?
Message ErrorName? ,
Caption Message ErrorName; Caption
, .
, m_bIsValid,
HResult, :

HResult,
m_bIsValid?
,
.
, ,
, HResult
.

www.books-shop.com

, .
, SetHResult,
HResult
. ,
, . ,
, ,
.

6.2 ( MFC)
ActiveX MFC
COleControl. , . ,
, ,
. ActiveX ,
(IPersistStorage . .)
( ),
COleControl::DoPropExchange, . OLE ControlWizard
, , COleControl,
DoPropExchange, .
4 , MFC;
DoPropExchange,
:

ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));


COleControl::DoPropExchange(pPX);
,
DoPropExchange . COleControl::ExchangeExtent
() , COleControl::ExchangeStockProps
.

DoPropExchange ( ),
( ). , (. )

IPersistxxx, MFC (
).

,
. MFC
, . PX_,
PX-. PX
property exchange, . ,
, , PX-. ,
PX_Bool BOOL.
PX-:

CPropExchange, DoPropExchange
(,
).
, PX-.
( , , ),
.

PX- ,
, -
. PX- (,

%RRNVVKRS

piracy@books-shop.com

COM-) ,
, .
HResult, PX_Long:

PX_Long(pPX, _T("HResult"), m_HResult);


,
:

PX_Long(pPX, _T("HResult"), m_HResult, 0);


HResult ,
, ,
.
. Caption ,
DoPropExchange .
HResult, m_bIsValid.
, Caption,
HResult. ?
HResult,
m_bIsValid , HResult.
DoPropExchange, HResult.
, ?
CPropExchange IsLoading, TRUE,
. ,
DoPropExchange :

void CFirstCtrl::DoPropExchange(CPropExchange* pPX)


{
ExchangeVersion(pPX, MAKELONG(w_VerMinor, _wVerMajor));
COleControl::DoPropExchange(pPX);

PX_Long(pPX, _T("HResult"), m_HResult, 0);


if(pPX -> IsLoading())
{
SetHResult(m_HResult);
}

HResult,
,
. , , ,
Caption,
, .
, ,
. , IPersistPropertyBag::Load .
( , MFC 4.2) CTLPBAG.CPP
COleControl:: XPersistPropertyBag::Load (MFC COM-
C++; XPersistPropertyBag , COleControl
IPersistPropertyBag). CPropbagPropExchange
DoPropExchange . ,
IPropertyNotifySink ,
( DISPID_ UNKNOWN), . ,
CPropbagPropExchange DoPropExchange
.
CPropbagPropExchange .
, , COleControl::DoPropExchange.
PX- ,

www.books-shop.com

. PX- (, PX_Long)
ExchangeProp px ( px
CPropbagPropExchange). IPropertyBag::Read,
VARIANT,
, IErrorLog .
, VARIANT ,
. , ,
IPropertyBag::Write, Write
VARIANT.

6.3 PX-
PX-, , PX_Blob,
BLOB-. BLOB
, , , ,
! PX_Blob PX-
, PX_Blob ,
PX- ,
. C++ new,
delete.
PX_Font PX- ,
,
, .
, ,
,
.

6.4
, First Visual Basic,
, . ,
_Version, _ExtentX,
_ExtentY _StockProps. ,
. _Version
. : 16
(major) , 16 (minor).
, 65536, 0x10000
. 1,
0, 1.0. _Version
COleControl::ExchangeVersion DoPropExchange.
, ,
. , , ,
. , DoPropExchange
.
DoPropExchange ExchangeVersion
CPropExchange. .
_ExtentX _ExtentY HIMETRIC.
ActiveX ,
.
ExchangeExtent, COleControl::DoPropExchange.
COleControl::ExchangeStockProps
, . ,
hWnd, ,
( ), .
,
, , .
.

www.books-shop.com

(Caption, BackColor, ForeColor, Font Enabled). ,


?
, , FRM- Visual Basic,
_StockProps. ,
MFC , .
,
(, 1 BackColor).
CTLPROP.CPP, \MSDEV\MFC\SRC. ,
STOCKPROP_BACKCOLOR 000000001.
79, 04F . ExchangeStockProps
, .
, MFC ,
. ,
.
.

6.5 ( MFC)
, ActiveX C++, MFC,

. , IPersistPropertyBag,
(, , )
, - ,
IPersistPropertyBag .
ActiveX Template Library (ATL) 2.0
. ,
,
. ATL.
,
, .

www.books-shop.com

Microsoft Visual Basic (


VBX), ,
VBX .
- .

.
VBX ,
, ,
. , -
Visual Basic,
, ,
.

7.1 ActiveX
ActiveX ,
, , ,
Automation.
, MFC 15 (
!).
ActiveX ,
. ,
VBX , .
ActiveX, VBX,
, ,
.
MFC , .
ClassWizard OLE Automation. , MFC
. ,
. DoClick Refresh
. DoClick
, .
COleControl::OnClick, , Click
(. ) . Refresh COleCOntrol::
Refresh, . ,
.

7.2
MFC
- , -
. First,
. , Refresh
, -
.
?
First ,
. ,

www.books-shop.com

HRESULT,
, .

7.3 HRESULT
HRESULT, ,
. , ,
- ( 10
ODBC
).
: ,
. ,
,
. ,
HRESULT, 32- HRESULT,
. HRESULT
, ,
.
.
:

,
?
?
HRESULT ,
?
,
HRESULT
()?
?
WINERROR.H?

: ,
.
. ,
.
HRESULT ,
.
( ) HRESULT
. ,
,
HRESULT . ,
( 8
, , ).
, 32- ( ?),
, 16- .
,

7.4 HRESULT
HRESULTS.IND, ,
HRESULT. 8 .
4 HRESULT, 4
, HRESULTS.MSG, HRESULT. HRESULTS.MSG,
, HRESULT,
. , -,

www.books-shop.com

-.
HRESULT.
. 7-1
.
Add, HRESULT .
: HRESULT, .
TRUE, - FALSE.
, BatchLoad,
HRESULT , WINERROR.H. BatchLoad
, HRESULT, .

. BatchLoad HRESULT .
,

.
. Microsoft
Visual C++, ClassWizard OLE Automation.
CFirstCtrl Add Method. External Name
Refresh OK. Add,
BOOL :

HResult long,
Symbol LPCTSTR,
Message LPCTSTR.

. 7-1.
, BatchLoad, long
FileName LPCTSTR.
, ( Refresh) .
, :
1.

(HRESULTS.IND),
.
2. ,
.
3. SetHResult, HRESULT
(HRESULTS.MSG).
4. Add BatchLoad.
. ,
,
. FIRSTCTL.H CHRESULTEntry,
HRESULT/:

www.books-shop.com

struct CHRESULTEntry
{
long lHRESULT;
unsigned long ulOffset;
};


, C++ class struct ?
, (
C), .

HRESULT
.
CHRESULTEntry, , ,
, , HRESULT
; .
, CFirstCtrl:

CHRESULTEntry *m_lpseCodes;
,
. HRESULT, Add,
, , BatchLoad
. ,
.
FIRSTCTL.H :

class CHRESULTEntryList
{
public:
void SetNext(CHRESULTEntryList *selNew) { m_pNext = selNew; }
CHRESULTEntryList *GetNext(void) const { return m_pNext };
CHRESULTEntry
*GetEntry(void) { return &m_seThis; }
private:
CHRESULTEntryList *m_pNext;
CHRESULTEntry
m_seThis;
};
m_pNext , m_seThis
HRESULT . SetNext m_pNext
; m_pNext
, .
GetNext ;
, GetEntry CHRESULTEntry
.
, CFirstCtrl: m_lpseNewCodes
m_lpseListEnd. , .
,
.
7-1 ,
.
m_lHRESULTs,
. ReadIndexFile ,
.
BatchLoad . ,

www.books-shop.com

, ClearList.
.
C++ , ReadIndexFile
(, ).
, ,
. , ,
. . ,
ReadIndexFile ,
.
7-1.

CFirstCtrl::CFirstCtrl()
{
InitializeIIDs(&IID_DFirst, &IID_DFirstEvents);
m_HResult = 0;
m_bIsValid = FALSE;
m_lpseCodes = 0;
m_lpseNewCodes = 0;
m_lpseListEnd = 0;
m_lHRESULTs = 0;
}

ReadIndexFile();

CFirstCtrl::~CFirstCtrl()
{
ClearList();
}
void CFirstCtrl::ClearList(void)
{
delete [] m_lpseCodes;
CHRESULTEntryList *pNext = m_lpseNewCodes;
while (pNext)
{
CHRESULTEntryList *pTemp = pNext -> GetNext();
delete pNext;
pNext = pTemp;
}
}
#define ENTRYSIZE (sizeof(long) + sizeof(unsigned long))
void CFirstCtrl::ReadIndexFile(void)
{
CFile cfIndex;
CString csIndex;
csIndex.LoadString(IDS_INDEXFILE);
if (cfIndex.Open(csIndex, CFile::modeRead |
CFile::shareDenyNone) == TRUE)
{
try
{
long lCode;
unsigned long ulOffset;
m_lHRESULTs = cfIndex.GetLength() / ENTRYSIZE;
m_lpseCodes = new CHRESULTEntry[m_lHRESULTs];
long lCurrent = 0;
UINT uRead1, uRead2;
do
{

www.books-shop.com

uRead1 = cfIndex.Read(&lCode, sizeof(lCode));


uRead2 = cfIndex.Read(&ulOffset, sizeof(ulOffset));
if (uRead1 == 0 && uRead2 == 0)
{
break;
}
if ((uRead1 == sizeof(lCode)) &&
(uRead2 == sizeof(ulOffset)))
{
m_lpseCodes[lCurrent].lHRESULT = lCode;
m_lpseCodes[lCurrent].ulOffset = ulOffset;
++lCurrent;
}
else
{
AfxThrowFileException(CFileException::endOfFile);
}
}
while (uRead1);
cfIndex.Close();
}
catch (CException *e)
{
TRACE(_T("Error reading index file or out
of memory\n"));
delete [] m_lpseCodes;
m_lpseCodes = 0;
m_lHRESULTs = 0;
e -> Delete();
}
}
else
{
TRACE(_T("Index file not found will be created\n"));
}
}
ReadIndexFile csIndex CString
(
C:\\CONTROLS\\CHAP07\\FIRST\\HRESULTS.IND, , ,
). cfIndex
CFile. , ReadIndexFile
.
, .
, try- ,
.
.
, (HRESULT)
(). Win32 8 . m_lHRESULTs.
m_lpseCodes
m_lpseCodes CHRESULTEntry.
new MFC CMemoryException.
, HRESULT/
.
. ,
( 8 )
AfxThrowFileException, .
catch-, ,
, CException. ,
,
. , ,

www.books-shop.com

m_lpseCodes 0, .
, delete C++
null delete , .
7-2 ,
HResult. SetHResult .
, FindEntry
HRESULT , . ,
FindEntry ,
HRESULT.
GetInfo
. , HRESULT
Caption .
FindEntry . ,
, , HRESULT,
. ,
( )
HRESULT, .
, ,
.
GetInfo . (
IDS_MESSAGEFILE) .
, 0,
. , Unicode,
ANSI- ,
(-
WINERROR.H ,
).
, .
7-2. HRESULT

void CFirstCtrl::SetHResult(long nNewValue)


{
m_csMessage.Empty();
m_csSymbol.Empty();
CString csLine;
unsigned long ulOffset;
m_bIsValid = FALSE;
if (FindEntry(nNewValue, &ulOffset))
{
m_bIsValid = TRUE;
GetInfo(ulOffset);
csLine = m_csSymbol + _T(": ") + m_csMessage;
}
else
{
csLine.LoadString(IDS_NOVALID_HRESULT);
}
m_HResult = nNewValue;
SetText(csLine);
SetModifiedFlag();
}
BOOL CFirstCtrl::FindEntry(long lCode, unsigned long *pulOffset)
{
for (long lEntry = 0; lEntry < m_lHRESULTs; ++lEntry)
{
if (m_lpseCodes[lEntry].lHRESULT == lCode)
{
*pulOffset = m_lpseCodes[lEntry].ulOffset;
return TRUE;
%RRNVVKRS

piracy@books-shop.com

}
}
CHRESULTEntryList *lpEntry = m_lpseNewCodes;
while (lpEntry)
{
if (lpEntry -> GetEntry() -> lHRESULT == lCode)
{
*pulOffset = lpEntry -> GetEntry() -> ulOffset;
return TRUE;
}
lpEntry = lpEntry -> GetNext();
}
return FALSE;

void CFirstCtrl::GetInfo(unsigned long ulOffset)


{
CFile
cfMsg;
CString csMsg;
TCHAR
tcChar;
csMsg.LoadString(IDS_MESSAGEFILE);
if (cfMsg.Open(csMsg, CFile::modeRead |
CFile::shareDenyNone) == TRUE)
{
try
{
cfMsg.Seek(ulOffset, CFile::begin);
UINT uRead;
for (;;)
{
uRead = cfMsg.Read(&tcChar, sizeof(tcChar));
if (uRead < sizeof(tcChar))
{
return;
}
if (tcChar == 0)
{
break;
}
m_csSymbol += tcChar;
}
for (;;)
{
uRead = cfMsg.Read(&tcChar, sizeof(tcChar));
if (uRead < sizeof(tcChar))
{
return;
}
if (tcChar == 0)
{
break;
}
m_csMessage += tcChar;
}
cfMsg.Close();
}
catch (CException *e)
{
TRACE(_T("Error reading message file\n"));
e -> Delete();
}
}
else

www.books-shop.com

{
}

TRACE(_T("Message file not found\n"));

}
Add, 7-3.
FindEntry, , HRESULT.
, .
HRESULT,
( ). HRESULT
, .
CHRESULTEntryList
CHRESULTEntry GetEntry.
, AddMessage (. ), HRESULT
WriteEntry ( . ).
, ,
, m_lpseListEnd ( ).
,
m_lpseNewCodes, .
7-3. Add

BOOL CFirstCtrl::Add(long hResult, LPCTSTR Symbol,


LPCTSTR Message)
{
unsigned long ulOffset;
if (FindEntry(hResult, &ulOffset))
{
TRACE(_T("HRESULT already in database\n"));
return TRUE;
}
CHRESULTEntryList *pNew = 0;
try
{
pNew = new CHRESULTEntryList;
pNew -> GetEntry() -> lHRESULT = hResult;
pNew -> GetEntry() -> ulOffset = AddMessage(Symbol,
Message);
WriteEntry(pNew -> GetEntry());
pNew -> SetNext(0);
if (m_lpseNewCodes)
{
m_lpseListEnd -> SetNext(pNew);
m_lpseListEnd = pNew;
}
else
{
m_lpseNewCodes = m_lpseListEnd = pNew;
}
}
catch (CException *e)
{
delete pNew;
TRACE(_T("Error adding HRESULT\n"));
e -> Delete();
return FALSE;
}
return TRUE;
}
unsigned long CFirstCtrl::AddMessage(LPCTSTR lpszSymbol,

www.books-shop.com

LPCTSTR lpszMessage)
{

CFile
cfMsg;
CString csMsg;
unsigned long ulReturn = 0xFFFFFFFF;
csMsg.LoadString(IDS_MESSAGEFILE);
if (cfMsg.Open(csMsg, CFile::modeWrite |
CFile::shareExclusive) == TRUE)
{
try
{
ulReturn = cfMsg.Seek(0, CFile::end);
cfMsg.Write(lpszSymbol,
(_tcslen(lpszSymbol) + 1) * sizeof(TCHAR));
cfMsg.Write(lpszMessage,
(_tcslen(lpszMessage) + 1) * sizeof(TCHAR));
cfMsg.Close();
}
catch (CFileException *e)
{
TRACE(_T("Error writing message file\n"));
e -> Delete();
return 0xFFFFFFFF;
}
}
else
{
TRACE(_T("Failed to open message file for writing\n"));
}
return ulReturn;

}
void CFirstCtrl::WriteEntry(CHRESULTEntry *pNew)
{
CFile
cfIndex;
CString csIndex;

csIndex.LoadString(IDS_INDEXFILE);
if (cfIndex.Open(csIndex, CFile::modeWrite |
CFile::shareExclusive) == TRUE)
{
cfIndex.Seek(0, CFile::end);
cfIndex.Write(&pNew -> lHRESULT, sizeof(pNew -> lHRESULT));
cfIndex.Write(&pNew -> ulOffset, sizeof(pNew -> ulOffset));
cfIndex.Close();
}

AddMessage .
,
, .
( ), ,
, -, . _tclen,
,
Unicode ANSI. WriteEntry HRESULT
.
,
CHRESULTEntry.
BatchLoad, 7-4.
:
1.

www.books-shop.com

2. ; .
3. .
4. , :

HRESULT, .
, HRESULT ; ,
.
.
HRESULT .
.

5. .
6. .
7. Add.
8. , .
9. .
7-4. BatchLoad

long CFirstCtrl::BatchLoad(LPCTSTR FileName)


{
CFile
cfIndex, cfMsg;
CStdioFile cfInput;
long lEntries = 0;
if (cfInput.Open(FileName, CFile::typeText |
CFile::modeRead) == TRUE)
{
CString csIndex;
try
{
csIndex.LoadString(IDS_INDEXFILE);
if (cfIndex.Open(csIndex, CFile::modeWrite |
CFile::shareExclusive) == TRUE)
{
CString csMsg;
csMsg.LoadString(IDS_MESSAGEFILE);
if (cfMsg.Open(csMsg, CFile::modeWrite |
CFile::shareExclusive) == TRUE)
{
lEntries = DoBatchLoad(&cfInput, &cfIndex,
&cfMsg);
cfMsg.Close();
}
else
{
TRACE(_T("Failed to open message file\n"));
}
cfIndex.Close();

}
else
{
TRACE(_T("Failed to open index file\n"));
}
cfInput.Close();
}
catch (CException *e)
{
TRACE(_T("Error closing files\n"));
e -> Delete();
}

}
else

www.books-shop.com

{
}

TRACE(_T("Failed to open input file\n"));

if (lEntries)
{
ClearList();
m_lpseCodes = 0;
m_lpseNewCodes = 0;
m_lpseListEnd = 0;
m_lHRESULTs = 0;
ReadIndexFile();
}
return lEntries;
}
long CFirstCtrl::DoBatchLoad(CStdioFile *cfIn,
CFile *cfIndex,
CFile *cfMsg)
{
long lEntries = 0;
try
{
cfIndex -> Seek(0, CFile::end);
CString csLine, csMsg, csSymbol;
while (GetNextDefineLine(cfIn, &csLine, &csMsg))
{
long lCode = GetTheCode(&csLine, &csSymbol);
unsigned long ulOffset;
if (FindEntry(lCode, &ulOffset))
{
TRACE1(_T("HRESULT %08X already in database ignored\n"),
lCode);
}
else
{
long lMsgPos = cfMsg -> Seek(0, CFile::end);
cfIndex -> Write(&lCode, sizeof(lCode));
cfIndex -> Write(&lMsgPos, sizeof(lMsgPos));

cfMsg -> Write((LPCTSTR) csSymbol,


(csSymbol.GetLength() + 1) *
sizeof(TCHAR));
cfMsg -> Write((LPCTSTR) csMsg,
(csMsg.GetLength() + 1) *
sizeof(TCHAR));
++lEntries;

}
catch (CException *e)
{
TRACE(_T("Error writing HRESULT to database\n"));
e -> Delete();
}
return lEntries;
}
BOOL CFirstCtrl::GetNextDefineLine(CStdioFile *cfFile,
CString *csLine,
CString *csMessage)

www.books-shop.com

{
_TCHAR szBuf[256];
CString csCompare;
BOOL bFound = FALSE;
LPTSTR lpszCnt;
do
{
try
{
lpszCnt = cfFile -> ReadString(szBuf, 255);
}
catch (CFileException *e)
{
e -> Delete();
break;
}
if (lpszCnt == NULL)
{
break;
}
csCompare = szBuf;
bFound = (csCompare.Find(_T("// MessageText:")) != -1);
}
while (bFound == FALSE);
if (bFound)
{
try
{
//
cfFile -> ReadString(szBuf, 255);
// ()
csMessage -> Empty();
do
{
cfFile -> ReadString(szBuf, 255);
if (szBuf[3])
{
if (!csMessage -> IsEmpty())
{
*csMessage += _T(" ");
}
szBuf[_tcslen(szBuf) - 1] = TCHAR(0);
*csMessage += szBuf + 4;
}
}
while (szBuf[3]);
//
lpszCnt = cfFile -> ReadString(szBuf, 255);

}
catch (CFileException *e)
{
csMessage -> Empty();
e -> Delete();
return FALSE;
}
if (lpszCnt == NULL)
{
csMessage -> Empty();
return FALSE;
}

www.books-shop.com

*csLine = szBuf;
return TRUE;

}
return FALSE;
}

long CFirstCtrl::GetTheCode(CString *csLine, CString *csSymbol)


{
// #define
int i = 7;
// -
while ((csLine -> GetLength() > i) &&
(_istspace(csLine -> GetAt(i))))
{
++i;
}
if (csLine -> GetLength() <= i)
{
return 0;
}
//
csSymbol -> Empty();
while ((csLine -> GetLength() > i) &&
!(_istspace(csLine -> GetAt(i))))
{
*csSymbol += csLine -> GetAt(i);
++i;
}
if (csLine -> GetLength() <= i)
{
csSymbol -> Empty();
return 0;
}
// -
while ((csLine -> GetLength() > i) &&
(_istspace(csLine -> GetAt(i))))
{
++i;
}
if (csLine -> GetLength() <= i)
{
csSymbol -> Empty();
return 0;
}
// WINERROR.H
// _HRESULT_TYPEDEF(),
// .
int pos;
if ((pos = csLine -> Find(_T("_HRESULT_TYPEDEF_("))) != -1)
{
i = pos + 18;
// 18
}
//
CString csNumber;
try
{
csNumber = csLine -> Mid(i);
}

www.books-shop.com

catch (CMemoryException *e)


{
csSymbol -> Empty();
e -> Delete();
return 0;
}
return _tcstoul(csNumber, NULL, 0);
}
BatchLoad .
. CStdioFile, CFile,

. BatchLoad DoBatchLoad,
, .
, BatchLoad ,
, Add,
ReadIndexFile.
DoBatchLoad try-catch,
.
,
GetNextDefineLine, -
. GetNextDefineLine ,
, , CString
, m_csMessage.
, HRESULT ,
, ,
HRESULT ( ).
, GetTheCode,
CString (
m_csSymbol).
, HRESULT. DoBatchLoad FindEntry
, HRESULT -
. ,
; DoBatchLoad
HRESULT
. ,
.
CD-ROM
\CODE\CHAP07\FIRST. HRESULTS.IND
HRESULTS.MSG, WINERROR.H, Visual C++ 4.2,
BatchLoad. BatchLoad , 1013
HRESULT. EMPTY.IND EMPTY.MSG,
. HRESULT 0x00000000,
BatchLoad.
BatchLoad, , WINERROR.H;
, , Message Compiler
(MC). HRESULT, ,
.

7.5
.
, 32-
, .
. ,
, , .
,
: .

www.books-shop.com

,
.

7.6 ,
MFC
, , , MFC.
( C++),
, ,
( ),
. , Automation,
,
Automation. , ,
IDL- ( ODL-)
, .
MFC,
, First . ,
CString , ,
ANSI C++. ,
,
,
.

www.books-shop.com

, ActiveX.
.
;
, ( ) ,
.
3, ActiveX
COM, ,
. ,
, COM
(, IConnectionPoint),
.
32- COM Microsoft Windows NT 4.0 Windows 95,
Microsoft Internet Explorer 3.0.
ActiveX MFC,
, , MFC
Microsoft Visual C++. , , MFC,
First, .

8.1
. , Automation
, - ,
, . ActiveX
, -
.
, .
,
. ,
- ,
. , ,

, .
, MFC
,
, 16- .
. MFC 4.2 ( )
, . ,
ATL Microsoft Visual J++
.
? ,
,
, . ,
Web-, . ,
,
, ( ,
) !

%RRNVVKRS

piracy@books-shop.com

?
, .
(, ), ,
- , . . ,
,
.
,
.

8.2
:

Request-
Before-
After-
Do-.

8.2.1 Request-
request-,
.
( Cancel) CancelBoolean ,
ActiveX. ,
, FALSE. TRUE,
, , , .
, Request, ,
RequestUpdate.

8.2.2 Before-
before- , ,
. ,
BeforeClose
, , ,
. Before- .
Beforexxx, xxx , .

8.2.3 After-
after-, -
, . After-
; ,
after- .
. ,
.

8.2.4 Do-
Do- - C++ ,
-
. do- ,
TRUE ,
EnableDefault ( ).
FALSE, ,
. Do- Doxxx, xxx .

8.3

www.books-shop.com

, Invoke
IDispatch ( ), ,
IConnectionPoint::Advise.
,
; ,
, . ,
, ( ) VARIANT
Invoke.
, ,
, ,
.
: ,
(, , v-),
IDispatch,
Invoke? ,
IDispatch. Visual Basic Scripting.
C++ ATL,
.
ATL
, v-,
dispinterface (
GUID), Invoke.

8.4
ActiveX ,
. ,
,
. ,
ActiveX, .
(, )
dispid, ,
.
ActiveX ,
(
). , Visual Basic 4.0
:

DragDrop
DragOver
GotFocus
LostFocus

, , .

8.4.1 (
ActiveX)

Dispid

Click

600

.
,
.

DblClick

601

KeyDown

602

,
.

KeyUp

604

,
.

www.books-shop.com

MouseDown

605

,
.

MouseMove

606

,
.

MouseUp

607

,
.

608

,
.

( ;
).

609

() .
, ,
, . ,
, 13,
ActiveX Internet.

Error

ReadyStateChange

8.5 , MFC Visual C++


, MFC Visual C++
ActiveX. , ClassWizard OLE Events.
( ,
), OLE Events Add Event,
.
MFC , .
MFC
ActiveX, . . 8-1
, Add Event.

.8-1. Add Event Microsoft Visual C++ 2.0


8.6
(, Click), ClassWizard
, ,

www.books-shop.com

EVENT_STOCK_CLICK()
FireClick,
Click . FireClick,
COleControl, Invoke (-) IDispatch,
(-) , .
, .

8.7
ClassWizard
Firexxx, xxx ( ,
, ?) , InvalidHResult,
( , HRESULT),
:

void FireInvalidHResult(long HResult)


{FireEvent(eventidInvalidHResult,EVENT_PARAM(VTS_I4), HResult);}
FireInvalidHResult,
. .
FireEvent, (
), ClassWizard. COleControl
,
. FireEvent FireEventV ,
, ,
COleDispatchDriver::InvokeHelperV, Invoke
. COleDispatchDriver MFC
Automation C++ . ,
COleDispatchDriver IDispatch
. , MFC
. - COleControl
CTLEVENT.CPP MFC.
ClassWizard
:

EVENT_CUSTOM("InvalidHResult", FireInvalidHResult, VTS_I4)


, .
,
.
, . ,
IOleControl::FreezeEvents, .
MFC OnFreezeEvents.
COleControl , ,
,
, .
, First .

8.8 First
First, ,
. -, ( ),
. -, ,
HResult HRESULT.
, ,
, .
,
, (

www.books-shop.com

, , ,
).
, :
, ,
.
, , HResult
HRESULT. ,
.

: InvalidHResult FilesCreated.
HResult, .
ClassWizard ,
:

//
//{{AFX_EVENT(CFirstCtrl)
void FireInvalidHResult(long HResult)
{FireEvent(eventidInvalidHResult,EVENT_PARAM(VTS_I4),
HResult);}
void FireFilesCreated()
{FireEvent(eventidFilesCreated,EVENT_PARAM(VTS_NONE));}
//}}AFX_EVENT
DECLARE_EVENT_MAP()
:
BEGIN_EVENT_MAP(CFirstCtrl, COleControl)
//{{AFX_EVENT_MAP(CFirstCtrl)
EVENT_CUSTOM("InvalidHResult", FireInvalidHResult, VTS_I4)
EVENT_CUSTOM("FilesCreated", FireFilesCreated, VTS_NONE)
//}}AFX_EVENT_MAP
END_EVENT_MAP()

, ,
. ODL-, ,
:

//

CFirstCtrl

[ uuid(A29DB7D4-E4E5-11CF-848A-00AA005754FD),
helpstring("Event interface for First Control") ]
dispinterface _DFirstEvents
{
properties:
//

};

methods:
// - ClassWizard
// .
//
// .
//{{AFX_ODL_EVENT(CFirstCtrl)
[id(1)] void InvalidHResult(long HResult);
[id(2)] void FilesCreated();
//}}AFX_ODL_EVENT

, ,
, dispinterface _DFirstEvents ;
dispid 1, 2.
HResult ,
SetHResult .
FireInvalidHResult HResult:

www.books-shop.com

FireInvalidHResult(nNewValue);

sLine.LoadString(IDS_NOVALID_HRESULT);
else if. HResult ,
( ),
InvalidHResult.
.
( ) , ,
.
, .

CFirstControl, ReadIndexFile. ReadIndexFile;
.
if, - .
,
. ,
, (
), .
CFile GetStatus, .
GetStatus ,
CFile . , ,
.
, CFile. CFile
( ) CFile,
, ,
.
:

// ?
CFileStatus cfsDummy;
if (CFile::GetStatus(csIndex, cfsDummy) == 0)
{
// , ( )
TRACE(_T("Index file not found - being created\n"));
if (CreateFiles() == FALSE)
{
return;
}
}
, GetStatus 0.
CreateFiles, .
GetStatus CFileStatus,
. ,
. CreateFiles
FALSE, ReadIndexFile
- . ,
, ,
else

TRACE(_T("Cannot open the index file"));


CreateFiles :

BOOL CFirstCtrl::CreateFiles(void)
{
CFile
cfFile;
CString csFile;
BOOL
bRet = FALSE;
//
csFile.LoadString(IDS_INDEXFILE);
if (cfFile.Open(csFile, CFile::modeCreate |

www.books-shop.com

CFile::modeWrite |
CFile::shareExclusive) == 0)

TRACE(_T("Error creating index file\n"));


}
else
{
cfFile.Close();
// :
// .
}
//
csFile.LoadString(IDS_MESSAGEFILE);
if (cfFile.Open(csFile, CFile::modeCreate |
CFile::modeWrite |
CFile::shareExclusive) == 0)
{
TRACE(_T("Error creating message file\n"));
}
else
{
cfFile.Close();
bRet = TRUE;
FireFilesCreated();
}
return bRet;
}
. CFile::modeCreate,
Open ,
, . ,
.
, . ,
ReadIndexFile .
, ,
, .
: 0 ( ),
0 . 32- Visual C++ ;
. 16- Visual C++
ASSERT, ( )
. , C++
0 . ,
.
,
. :

m_lHRESULTs = cfIndex.GetLength() / ENTRYSIZE;


:
if ((m_lHRESULTs = cfIndex.GetLength() / ENTRYSIZE) == 0)
{
TRACE (_T("The index file is empty\n"));
return;
}
, ,
.
. ,
.
View|Event Log.
First. , ,
HRESULT. Windows Explorer

www.books-shop.com

, . (
), HResult . ,
HRESULT.
HRESULT WINERROR.H Edit|Invoke
Methods BatchLoad, HResult,
(
). ?
,
,
( 10). ,
FireFilesCreation , COleControl.
. ,
,
. , ,
.
, ,
IConnectionPoint::Advise. MFC ( COleControl)
OnEventAdvise.
; - ,
. ,
, , .
COleControl, OnFreezeEvents,
IOleControl::FreezeEvents . ,
, .
FreezeEvents ,
, TRUE, ,
FALSE. OnFreezeEvents , ,
.
, , OnFreezeEvents OnEventAdvise,
, FilesCreated ,
First. .
CFirstCtrl.
(
ClassWizard
CPP- Message Maps,
Messages ).

virtual void OnFreezeEvents(BOOL bFreeze);


virtual void OnEventAdvise(BOOL bAdvise);
:

BOOl m_bFilesCreated;
BOOL m_nEventsFrozen;
, ,
; IOleControl::FreezeEvents
TRUE IOleControl::FreezeEvents FALSE
( ; 0 , ).
CFirstCtrl , m_bFilesCreated FALSE,
m_nEventsFrozen 0. CreateFiles
:

m_bFilesCreated = TRUE;

//

, :

void CFirstCtrl::OnFreezeEvents(BOOL bFreeze)


{
m_nEventsFrozen += (bFreeze ? 1 : -1);
}

www.books-shop.com

void CFirstCtrl::OnEventAdvise(BOOL bAdvise)


{
if (bAdvise && m_bFilesCreated && (m_nEventsFrozen == 0))
{
FireFilesCreated();
}
}
OnFreezeEvents bFreeze.
OnFreezeEvents ,
,
, FreezeEvents
FALSE , TRUE.
OnEventAdvise . ,
( ), m_bCreateFiles ,
, . ,
, . ,
, ,
. ,
,
, .
,
.
SetHResult :

if (m_nEventsFrozen == 0)
{
FireInvalidHResult(nNewValue);
}
FireInvalidHResult , .
. -,
, ,
HResult .
-, HResult ( , )
Add BatchLoad.
, .
, Add BatchLoad
HResult,
. ,
HResult ,
InvalidHResult, .
, SetHResult
CheckHResult. TRUE,
HResult , FALSE , ,
m_bIsValid.
, . :

BOOL CFirstCtrl::CheckHResult(long nNewValue)


{
CString csLine;
BOOL
bRet = FALSE;
m_csMessage.Empty();
m_csSymbol.Empty();
unsigned long ulOffset;

www.books-shop.com

if (FindEntry(nNewValue, &ulOffset))
{
bRet = TRUE;
GetInfo(ulOffset);
csLine = m_csSymbol + _T(": ") + m_csMessage;
}
else
{
csLine.LoadString(IDS_NOVALID_HRESULT);
}
SetText(csLine);
return bRet;
}
CheckHResult !
SetHResult .
SetHResult :

void CFirstCtrl::SetHResult(long nNewValue)


{
if (CheckHResult(nNewValue) == FALSE)
{
if (m_nEventsFrozen == 0)
{
FireInvalidHResult(nNewValue);
}
}
m_HResult = nNewValue;
SetModifiedFlag();
}
Add BatchLoad
, . Add
:

if (m_bIsValid == FALSE)
{
CheckHResult(m_HResult);
}

return TRUE;
. BatchLoad ,

if (lEntries)

return lEntries;
. HResult
. Add ,
. .
, HResult,
, .
First , ,
CD-ROM, \CODE\CHAP08\FIRST.

%RRNVVKRS

piracy@books-shop.com

8.9 MFC
++ MFC,
. ,
,
( ATL
). , ,
, .

www.books-shop.com


-.
, .
, ActiveX,
. ,
, , .

,
. , ,
C++ (
MFC, ), COM,
Automation ActiveX,
!
, .
, ActiveX .
, First,
, . ,
, C++,
, Automation.

9.1 ?
,
, ,
. (, ,
) . ,
,
. First
, .
First ,
MFC C++ -.
, 32-
C++ try catch.
: 16- Windows,
TRY CATCH MFC.
32- , .
, ,
C++ .
C++ (, 16- Microsoft
C++).

9.2 MFC C++


MFC ;
new. ,
CMemoryException. , new
0, CMemoryException, ,
,
catch-, CMemoryException
CException. C++
,

www.books-shop.com

. , C++
,
.
, (
, ),
, .
C++ (, 16-
Microsoft Visual C++ 1.5x),
, .
? ,
new
new. :

try
{

CMyObject *x = new CMyObject;


}
catch (CException *e)
{
AfxMessageBox("Help!");
e -> Delete();
return;
}
, CException (
), try- ,
catch-. , new
, CMemoryException.
CException, catch-,
. , .
,
.
catch-,
, .
, MFC ( runtime- C/C++, MFC)
. ,
.
catch- ,
. ,
, , ,
, ,
.
, , .
, ,

throw, ,
.
C++ .
MFC
CException . MFC ,
, ,
, COM OLE, Automation Windows.
CException catch-
catch- CException,
( catch(...),
).
, catch (
MFC CATCH) . , MyFunc

www.books-shop.com

CMemoryException, CFileException COleException,


catch- CException :

try
{

MyFunc();
}
catch (CMemoryException *e)
{
// ,
//
e -> Delete();
//
}
catch (CFileException *e)
{
//
e -> Delete();
//
}
catch (COleException *e)
{
// OLE
e -> Delete();
//
}
, catch
, .
, . e (
). MFC CATCH
atch, :
(, CMemoryException) .
, CException.
,
,
.
, First,
.
, : ,
, , .
, .
, .
, .
,
. ,
, , !
.
, ,
. , - .
First ,
. , , ,
CString, ,
.
,
! MFC ,
C++ (, ATL,
) . ATL
, .
, .

www.books-shop.com

,
. ,
( C) .
, .

9.3 ActiveX
, ActiveX. ,
. , ,
, , ,
ActiveX.
2 3 , Automation
, ,
. , ActiveX
Automation, ,
Automation.
Automation ActiveX .
Automation ,
. ActiveX
, .
, .
:

,
Automation (ThrowError MFC).

Error, (FireError MFC).

ThrowError FireError COleControl


: HRESULT , ( )
.
ThrowError
COleDispatchException, MFC Automation. ,
COleDispatchExceptionEx, IDispatch::Invoke
,
. , Microsoft Visual C++ 4.2
. ,
!
FireError , Error.
Error dispid 608 (DISPID_ERROREVENT, OLECTL.H)
:

, .
, BSTR.
HRESULT .
BSTR.
BSTR.
, .
; TRUE,
.

,
. ,
/ .
. FALSE, ,
. MFC
DisplayError, .
,
ActiveX.

www.books-shop.com

MFC FireError
(, HRESULT) ,
. (
),
, Error
. MFC FireError.
First ,
Error. , First,
, ThrowError.

9.4
, Automation,
, IDispatch::Invoke.
Automation, v-, IDispatch,
. ,
Invoke. Invoke,
. , ,
. ( ,
) .
,
3,
COM- , HRESULT.
, Automation ,
,
Automation, IDispatch. ,
v-, HRESULT.
,
Automation ,
. , - .
, ISupportErrorInfo.
IUnknown
InterfaceSupportsErrorInfo. IID
. Invoke,
S_OK, S_FALSE.
. , ,
,
. (
Automation), :

CreateErrorInfo ( Automation API)


.
ICreateErrorInfo.
, ICreateErrorInfo ,
SetDescription.
QueryInterface IErrorInfo.
IErrorInfo SetErrorInfo ( Automation
API), GetErrorInfo.

( )
, .

,
Automation.

9.5 First

www.books-shop.com

,
. ,
, ,
, . First
, .
,
, . ,
.
CD-ROM, \CODE\CHAP09\FIRST.
9-1 9-4 ( FIRSTCTL.H FIRSTCTL.CPP
FIRSTEX.H FIRSTEX.CPP). , ,
.
9-1. FIRSTCTL.H

// FirstCtl.h : OLE CFirstCtrl


struct CHRESULTEntry
{
long lHRESULT;
unsigned long ulOffset;
};
class CHRESULTEntryList{
public:
void SetNext(CHRESULTEntryList *selNew) {m_pNext = selNew;}
CHRESULTEntryList *GetNext (void) const {return m_pNext;}
CHRESULTEntry
*GetEntry(void) {return &m_seThis;}
private:
CHRESULTEntryList *m_pNext;
CHRESULTEntry
m_seThis;
};
///////////////////////////////////////////////////////////////
// CFirstCtrl : FirstCtl.cpp
class CFirstCtrl : public COleControl{
DECLARE_DYNCREATE(CFirstCtrl)
//
public:
CFirstCtrl();
//
// ,
// ClassWizard
//{{AFX_VIRTUAL(CFirstCtrl)
public:
virtual void OnDraw(CDC* pdc,
const CRect& rcBounds,
const CRect& rcInvalid);
virtual void DoPropExchange(CPropExchange* pPX);
virtual void OnResetState();
virtual void OnFreezeEvents(BOOL bFreeze);
virtual void OnEventAdvise(BOOL bAdvise);
//}}AFX_VIRTUAL
//
protected:
~CFirstCtrl();
DECLARE_OLECREATE_EX(CFirstCtrl)
DECLARE_OLETYPELIB(CFirstCtrl)
DECLARE_PROPPAGEIDS(CFirstCtrl)
DECLARE_OLECTLTYPE(CFirstCtrl)

//
//
//
//
//
//

guid
GetTypeInfo

//
//{{AFX_MSG(CFirstCtrl)
// - ClassWizard
// .

www.books-shop.com

//
// !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
//
//{{AFX_DISPATCH(CFirstCtrl)
afx_msg short GetCode();
afx_msg BSTR GetErrorName();
afx_msg BSTR GetFacility();
afx_msg BSTR GetMessage();
afx_msg BSTR GetSeverity();
afx_msg long GetHResult();
afx_msg void SetHResult(long nNewValue);
afx_msg BOOL Add(long hResult, LPCTSTR Symbol,
LPCTSTR Message);
afx_msg long BatchLoad(LPCTSTR FileName);
//}}AFX_DISPATCH
DECLARE_DISPATCH_MAP()
afx_msg void AboutBox();
//
//{{AFX_EVENT(CFirstCtrl)
void FireInvalidHResult(long HResult)
{FireEvent(eventidInvalidHResult,EVENT_PARAM(VTS_I4),
HResult);}
void FireFilesCreated()
{FireEvent(eventidFilesCreated,EVENT_PARAM(VTS_NONE));}
//}}AFX_EVENT
DECLARE_EVENT_MAP()
//
public:
enum {
//{{AFX_DISP_ID(CFirstCtrl)
dispidCode = 1L,
dispidErrorName = 2L,
dispidFacility = 3L,
dispidMessage = 4L,
dispidSeverity = 5L,
dispidHResult = 6L,
dispidAdd = 7L,
dispidBatchLoad = 8L,
eventidInvalidHResult = 1L,
eventidFilesCreated = 2L,
//}}AFX_DISP_ID
};
private:
long
m_HResult;
BOOL
m_bIsValid;
CString m_csSymbol;
CString m_csMessage;
long
m_lHRESULTs;
BOOL
m_bFilesCreated;
short
m_nEventsFrozen;
BOOL
m_bInDispatch;
CString m_csBadMessage;
CHRESULTEntry
*m_lpseCodes;
CHRESULTEntryList *m_lpseNewCodes;
CHRESULTEntryList *m_lpseListEnd;

www.books-shop.com

};

BOOL GetNextDefineLine(CStdioFile *cfFile,


CString *csLine,
CString *csMessage);
long GetTheCode(CString *csLine, CString *csSymbol);
void ReadIndexFile(void);
void ClearList(void);
BOOL FindEntry(long lCode, unsigned long *pulOffset);
void GetInfo(unsigned long ulOffset);
unsigned long AddMessage(LPCTSTR lpszSymbol,
LPCTSTR lpszMessage);
void WriteEntry(CHRESULTEntry *pNew);
long DoBatchLoad(CStdioFile *cfIn, CFile *cfIndex,
CFile *cfMsg);
BOOL CreateFiles(void);
BOOL CheckHResult(long nNewValue);
void DoError(HRESULT hresult, UINT uDescription, UINT helpid);
void ReallySetHResult(long nNewValue);
HRESULT GetFileExceptionString(CFileException *cfEx,
UINT &uStr) const;

9-2. FIRSTCTL.CPP

// FirstCtl.cpp : OLE CFirstCtrl


#include
#include
#include
#include
#include

"stdafx.h"
"First.h"
"FirstCtl.h"
"FirstPpg.h"
"FirstEx.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
IMPLEMENT_DYNCREATE(CFirstCtrl, COleControl)
///////////////////////////////////////////////////////////////
//
BEGIN_MESSAGE_MAP(CFirstCtrl, COleControl)
//{{AFX_MSG_MAP(CFirstCtrl)
// - ClassWizard
// .
//
// !
//}}AFX_MSG_MAP
ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////
//
BEGIN_DISPATCH_MAP(CFirstCtrl, COleControl)
//{{AFX_DISPATCH_MAP(CFirstCtrl)
DISP_PROPERTY_EX(CFirstCtrl, "Code", GetCode,
SetNotSupported, VT_I2)
DISP_PROPERTY_EX(CFirstCtrl, "ErrorName", GetErrorName,
SetNotSupported, VT_BSTR)

www.books-shop.com

DISP_PROPERTY_EX(CFirstCtrl, "Facility", GetFacility,


SetNotSupported, VT_BSTR)
DISP_PROPERTY_EX(CFirstCtrl, "Message", GetMessage,
SetNotSupported, VT_BSTR)
DISP_PROPERTY_EX(CFirstCtrl, "Severity", GetSeverity,
SetNotSupported, VT_BSTR)
DISP_PROPERTY_EX(CFirstCtrl, "HResult", GetHResult,
SetHResult, VT_I4)
DISP_FUNCTION(CFirstCtrl, "Add", Add, VT_BOOL,
VTS_I4 VTS_BSTR VTS_BSTR)
DISP_FUNCTION(CFirstCtrl, "BatchLoad", BatchLoad,
VT_I4, VTS_BSTR)
DISP_STOCKFUNC_REFRESH()
DISP_STOCKPROP_BACKCOLOR()
DISP_STOCKPROP_CAPTION()
DISP_STOCKPROP_ENABLED()
DISP_STOCKPROP_FONT()
DISP_STOCKPROP_FORECOLOR()
DISP_STOCKPROP_HWND()
//}}AFX_DISPATCH_MAP
DISP_FUNCTION_ID(CFirstCtrl, "AboutBox", DISPID_ABOUTBOX,
AboutBox, VT_EMPTY, VTS_NONE)
END_DISPATCH_MAP()
///////////////////////////////////////////////////////////////
//
BEGIN_EVENT_MAP(CFirstCtrl, COleControl)
//{{AFX_EVENT_MAP(CFirstCtrl)
EVENT_CUSTOM("InvalidHResult", FireInvalidHResult, VTS_I4)
EVENT_CUSTOM("FilesCreated", FireFilesCreated, VTS_NONE)
//}}AFX_EVENT_MAP
END_EVENT_MAP()
///////////////////////////////////////////////////////////////
//
// .
// !
BEGIN_PROPPAGEIDS(CFirstCtrl, 1)
PROPPAGEID(CFirstPropPage::guid)
END_PROPPAGEIDS(CFirstCtrl)
///////////////////////////////////////////////////////////////
// GUID
IMPLEMENT_OLECREATE_EX(CFirstCtrl, "FIRST.FirstCtrl.1",
0x14bc5f80, 0xdbd2, 0x11cd, 0x92, 0xb4, 0x8, 0, 0x2b, 0x29,
0x1e, 0xed)
///////////////////////////////////////////////////////////////
//
IMPLEMENT_OLETYPELIB(CFirstCtrl, _tlid, _wVerMajor, _wVerMinor)
///////////////////////////////////////////////////////////////
//
const IID BASED_CODE IID_DFirst =
%RRNVVKRS

piracy@books-shop.com

{ 0xa29db7d3, 0xe4e5, 0x11cf, { 0x84,


0x57,
const IID BASED_CODE IID_DFirstEvents =
{ 0xa29db7d4, 0xe4e5, 0x11cf, { 0x84,
0x57,

0x8a, 0, 0xaa, 0,
0x54, 0xfd } };
0x8a, 0, 0xaa, 0,
0x54, 0xfd } };

///////////////////////////////////////////////////////////////
//
static const DWORD BASED_CODE _dwFirstOleMisc =
OLEMISC_ACTIVATEWHENVISIBLE |
OLEMISC_SETCLIENTSITEFIRST |
OLEMISC_INSIDEOUT |
OLEMISC_CANTLINKINSIDE |
OLEMISC_RECOMPOSEONRESIZE;
IMPLEMENT_OLECTLTYPE(CFirstCtrl, IDS_FIRST, _dwFirstOleMisc)
///////////////////////////////////////////////////////////////
// CFirstCtrl::CFirstCtrlFactory::UpdateRegistry // CFirstCtrl
BOOL CFirstCtrl::CFirstCtrlFactory::UpdateRegistry(BOOL bRegister)
{
// ,
// .
// MFC TechNote 64.
// ,
//
// 6- afxRegApartmentThreading 0.

if (bRegister)
return AfxOleRegisterControlClass(
AfxGetInstanceHandle(),
m_clsid,
m_lpszProgID,
IDS_FIRST,
IDB_FIRST,
afxRegApartmentThreading,
_dwFirstOleMisc,
_tlid,
_wVerMajor,
_wVerMinor);
else
return AfxOleUnregisterClass(m_clsid, m_lpszProgID);

///////////////////////////////////////////////////////////////
// CFirstCtrl::CFirstCtrl -
CFirstCtrl::CFirstCtrl()
{
InitializeIIDs(&IID_DFirst, &IID_DFirstEvents);
m_HResult = 0;
m_bIsValid = FALSE;
m_lpseCodes = 0;
m_lpseNewCodes = 0;
m_lpseListEnd = 0;
m_lHRESULTs = 0;
m_bFilesCreated = FALSE;

www.books-shop.com

m_nEventsFrozen = 0;
m_bInDispatch = FALSE;
m_csBadMessage.LoadString(IDS_BADMESSAGE);
//
//
//
//
//

,
.
, - ,
(
).

try
{

ReadIndexFile();
}
catch (CException *e)
{
CString csExtra;
UINT uStr = 0;
if (e -> IsKindOf(RUNTIME_CLASS(CFirstException)))
{
((CFirstException *)e) -> GetErrorString(uStr);
}
else if (e -> IsKindOf(RUNTIME_CLASS(CFileException)))
{
GetFileExceptionString((CFileException *)e, uStr);
}
if (uStr)
{
csExtra.LoadString(uStr);
m_csBadMessage += _T("\n\nActual error message:\n\n");
m_csBadMessage += csExtra;
}
AfxMessageBox(m_csBadMessage, MB_OK);
if (uStr)
{
m_csBadMessage.LoadString(IDS_BADMESSAGE);
}
e -> Delete();
}

///////////////////////////////////////////////////////////////
// CFirstCtrl::~CFirstCtrl -
CFirstCtrl::~CFirstCtrl()
{
ClearList();
}
void CFirstCtrl::ClearList(void)
{
delete [] m_lpseCodes;
CHRESULTEntryList *pNext = m_lpseNewCodes;
while (pNext)
{
CHRESULTEntryList *pTemp = pNext -> GetNext();
delete pNext;
pNext = pTemp;
}
}
#define ENTRYSIZE (sizeof(long) + sizeof(unsigned long))

www.books-shop.com

// CFirstException,
// CFileException CMemoryException
void CFirstCtrl::ReadIndexFile(void)
{
CFile cfIndex;
CString csIndex;
csIndex.LoadString(IDS_INDEXFILE);
// ?
CFileStatus cfsDummy;
if (CFile::GetStatus(csIndex, cfsDummy) == 0)
{
// , ( )
TRACE(_T("Index file not found - being created\n"));
if (CreateFiles() == FALSE)
{
// ...
//
throw new CFirstException(CFirstException:: noCreateFile);
}
}
if (cfIndex.Open(csIndex, CFile::modeRead |
CFile::shareDenyNone) == TRUE)
{
try
{
long lCode;
unsigned long ulOffset;
if ((m_lHRESULTs = cfIndex.GetLength() / ENTRYSIZE) == 0)
{
TRACE(_T("The index file is empty\n"));
return;
}
m_lpseCodes = new CHRESULTEntry[m_lHRESULTs];
long lCurrent = 0;
UINT uRead1, uRead2;
do
{
uRead1 = cfIndex.Read(&lCode, sizeof(lCode));
uRead2 = cfIndex.Read(&ulOffset, sizeof(ulOffset));
if (uRead1 == 0 && uRead2 == 0)
{
break;
}
if ((uRead1 == sizeof(lCode)) &&
(uRead2 == sizeof(ulOffset)))
{
m_lpseCodes[lCurrent].lHRESULT = lCode;
m_lpseCodes[lCurrent].ulOffset = ulOffset;
++lCurrent;
}
else
{
AfxThrowFileException(CFileException::endOfFile);
}
}
while (uRead1);
cfIndex.Close();
}
catch (CException *e)
{
//
delete [] m_lpseCodes;

www.books-shop.com

m_lpseCodes = 0;
m_lHRESULTs = 0;
cfIndex.Close();
throw;
}
}
else
{
throw new CFirstException(CFirstException::noIndexFile);
}
}
///////////////////////////////////////////////////////////////
// CFirstCtrl::OnDraw -
void CFirstCtrl::OnDraw(CDC* pdc, const CRect& rcBounds,
const CRect& rcInvalid)
{
//
CFont *hfOld = SelectStockFont(pdc);
CBrush cbBack(TranslateColor(GetBackColor()));
pdc -> FillRect(rcBounds, &cbBack);
pdc -> SetTextColor(TranslateColor(GetForeColor()));
pdc -> SetBkMode(TRANSPARENT);
RECT rcTemp = rcBounds;
pdc -> DrawText(InternalGetText(), -1, &rcTemp,
DT_SINGLELINE | DT_CENTER | DT_VCENTER);
pdc -> SelectObject(hfOld);
}
///////////////////////////////////////////////////////////////
// CFirstCtrl::DoPropExchange -
void CFirstCtrl::DoPropExchange(CPropExchange* pPX)
{
ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
COleControl::DoPropExchange(pPX);

PX_Long(pPX, _T("HResult"), m_HResult, 0);


if (pPX -> IsLoading())
{
m_bInDispatch = FALSE;
ReallySetHResult(m_HResult);
}
///////////////////////////////////////////////////////////////
// CFirstCtrl::OnResetState -
//
void CFirstCtrl::OnResetState()
{
COleControl::OnResetState(); //
// DoPropExchange
}

//
///////////////////////////////////////////////////////////////
// CFirstCtrl::AboutBox - About
void CFirstCtrl::AboutBox()
{
CDialog dlgAbout(IDD_ABOUTBOX_FIRST);

www.books-shop.com

dlgAbout.DoModal();
}
///////////////////////////////////////////////////////////////
// CFirstCtrl
long CFirstCtrl::GetHResult()
{
return m_HResult;
}
short CFirstCtrl::GetCode()
{
if (m_bIsValid)
{
return short(m_HResult & 0xFFFF);
}
else
{
return -1;
}
}
BSTR CFirstCtrl::GetFacility()
{
CString strResult;
short nFacility = IDS_NOVALID_HRESULT;
if (m_bIsValid)
{
nFacility = short((m_HResult & 0x0FFF0000) >> 16);
switch (nFacility)
{
case 0: case 1: case 2: case 3:
case 4: case 7: case 8: case 9:
case 10: case 11:
break;
default:
nFacility = -1;
}
nFacility += IDS_FACILITY_NULL;
}
strResult.LoadString(nFacility);
return strResult.AllocSysString();
}
BSTR CFirstCtrl::GetSeverity()
{
CString strResult;
short nSeverity = IDS_NOVALID_HRESULT;

if (m_bIsValid)
{
nSeverity = short((m_HResult & 0xC0000000) >> 30) +
IDS_SEVERITY_SUCCESS;
}
strResult.LoadString(nSeverity);
return strResult.AllocSysString();
BSTR CFirstCtrl::GetMessage()
{
return m_csMessage.AllocSysString();
}

www.books-shop.com

BSTR CFirstCtrl::GetErrorName()
{
return m_csSymbol.AllocSysString();
}
void CFirstCtrl::SetHResult(long nNewValue)
{
m_bInDispatch = TRUE;
ReallySetHResult(nNewValue);
m_bInDispatch = FALSE;
}
void CFirstCtrl::ReallySetHResult(long nNewValue)
{
if (CheckHResult(nNewValue) == FALSE)
{
if (m_nEventsFrozen == 0)
{
FireInvalidHResult(nNewValue);
}
}
m_HResult = nNewValue;
SetModifiedFlag();
}
//
BOOL CFirstCtrl::FindEntry(long lCode, unsigned long *pulOffset)
{
for (long lEntry = 0; lEntry < m_lHRESULTs; ++lEntry)
{
if (m_lpseCodes[lEntry].lHRESULT == lCode)
{
*pulOffset = m_lpseCodes[lEntry].ulOffset;
return TRUE;
}
}
CHRESULTEntryList *lpEntry = m_lpseNewCodes;
while (lpEntry)
{
if (lpEntry -> GetEntry() -> lHRESULT == lCode)
{
*pulOffset = lpEntry -> GetEntry() -> ulOffset;
return TRUE;
}
lpEntry = lpEntry -> GetNext();
}
return FALSE;
}
// CFirstException,
// CFileException CMemoryException
void CFirstCtrl::GetInfo(unsigned long ulOffset)
{
CFile
cfMsg;
CString csMsg;
TCHAR
tcChar;
csMsg.LoadString(IDS_MESSAGEFILE);
if (cfMsg.Open(csMsg, CFile::modeRead |
CFile::shareDenyNone) == TRUE)
{
cfMsg.Seek(ulOffset, CFile::begin);
UINT uRead;
for (;;)

www.books-shop.com

{
uRead = cfMsg.Read(&tcChar, sizeof(tcChar));
if (uRead < sizeof(tcChar))
{
cfMsg.Close();
TRACE(_T(
"Error reading symbol name
from message file\n"));
throw new
CFirstException(CFirstException::invalidFile);
}
if (tcChar == 0)
{
break;
}
m_csSymbol += tcChar;

}
for (;;)
{
uRead = cfMsg.Read(&tcChar, sizeof(tcChar));
if (uRead < sizeof(tcChar))
{
cfMsg.Close();
TRACE(_T("Error reading message string
from file\n"));
throw new
CFirstException(CFirstException::invalidFile);
}
if (tcChar == 0)
{
break;
}
m_csMessage += tcChar;
}
cfMsg.Close();

}
else
{
TRACE(_T("Message file not found\n"));
throw new CFirstException(CFirstException::noMessageFile);
}

//
BOOL CFirstCtrl::Add(long hResult, LPCTSTR Symbol,
LPCTSTR Message)
{
unsigned long ulOffset;
if (FindEntry(hResult, &ulOffset))
{
TRACE(_T("HRESULT already in database\n"));
return TRUE;
}
CHRESULTEntryList *pNew = 0;
m_bInDispatch = TRUE;
try
{
// NULL
if (Symbol == 0 || Message == 0 ||
*Symbol == 0 || *Message == 0)
{
throw new CFirstException(CFirstException::

www.books-shop.com

badParameters);
}
pNew = new CHRESULTEntryList;
pNew -> GetEntry() -> lHRESULT = hResult;
pNew -> GetEntry() -> ulOffset = AddMessage(Symbol, Message);
WriteEntry(pNew -> GetEntry());
pNew -> SetNext(0);
if (m_lpseNewCodes)
{
m_lpseListEnd -> SetNext(pNew);
m_lpseListEnd = pNew;
}
else
{
m_lpseNewCodes = m_lpseListEnd = pNew;
}
}
catch (CException *e)
//
{
delete pNew;
HRESULT hr;
UINT uStr;
if (e -> IsKindOf(RUNTIME_CLASS(CFirstException)))
{
hr = ((CFirstException *)e) -> GetErrorString(uStr);
}
else if (e -> IsKindOf(RUNTIME_CLASS(CFileException)))
{
hr = GetFileExceptionString((CFileException *)e, uStr);
}
else if (e -> IsKindOf(RUNTIME_CLASS(CMemoryException)))
{
hr = CTL_E_OUTOFMEMORY;
uStr = IDS_MEMORYERROR;
}
else
{
hr = CTL_E_ILLEGALFUNCTIONCALL;
uStr = IDS_UNEXPECTEDEXCEPTION;
}
e -> Delete();
DoError(hr, uStr, 0);
m_bInDispatch = FALSE;
return FALSE;
}
if (m_bIsValid == FALSE)
{
CheckHResult(m_HResult);
}
m_bInDispatch = FALSE;
return TRUE;

// CFirstException,
// CFileException CMemoryException
unsigned long CFirstCtrl::AddMessage(LPCTSTR lpszSymbol,
LPCTSTR lpszMessage)
{
CFile
cfMsg;
CString csMsg;
unsigned long ulReturn = 0xFFFFFFFF;
csMsg.LoadString(IDS_MESSAGEFILE);
if (cfMsg.Open(csMsg, CFile::modeWrite |
CFile::shareExclusive) == TRUE)

www.books-shop.com

{
ulReturn = cfMsg.Seek(0, CFile::end);
cfMsg.Write(lpszSymbol,(_tcslen(lpszSymbol) + 1)
* sizeof(TCHAR));
cfMsg.Write(lpszMessage,(_tcslen(lpszMessage) + 1)
* sizeof(TCHAR));
cfMsg.Close();
}
else
{
TRACE(_T("Failed to open message file for writing\n"));
throw new CFirstException(CFirstException::noWriteMsg);
}
return ulReturn;
}
// CFirstException,
// CFileException CMemoryException
void CFirstCtrl::WriteEntry(CHRESULTEntry *pNew)
{
CFile
cfIndex;
CString csIndex;

csIndex.LoadString(IDS_INDEXFILE);
if (cfIndex.Open(csIndex, CFile::modeWrite |
CFile::shareExclusive) == TRUE)
{
cfIndex.Seek(0, CFile::end);
cfIndex.Write(&pNew -> lHRESULT, sizeof(pNew -> lHRESULT));
cfIndex.Write(&pNew -> ulOffset, sizeof(pNew -> ulOffset));
cfIndex.Close();
}
else
{
TRACE(_T("Unable to open index file for writing\n"));
throw new CFirstException(CFirstException::noWriteIdx);
}
long CFirstCtrl::BatchLoad(LPCTSTR FileName)
{
CFile
cfIndex, cfMsg;
CStdioFile cfInput;
long lEntries = 0;
m_bInDispatch = TRUE;
try
{
// NULL
if (FileName == NULL)
{
throw new CFirstException(CFirstException::
badParameters);
}
if (cfInput.Open(FileName, CFile::typeText |
CFile::modeRead) == TRUE)
{
CString csIndex;
csIndex.LoadString(IDS_INDEXFILE);
if (cfIndex.Open(csIndex, CFile::modeWrite |
CFile::shareExclusive) == TRUE)
{
CString csMsg;

www.books-shop.com

csMsg.LoadString(IDS_MESSAGEFILE);
if (cfMsg.Open(csMsg, CFile::modeWrite |
CFile::shareExclusive) == TRUE)
{
lEntries = DoBatchLoad(&cfInput,
&cfIndex, &cfMsg);
cfMsg.Close();
}
else
{
TRACE(_T(
"Failed to open message file for writing\n"));
cfIndex.Close();
cfInput.Close();
throw new
CFirstException(CFirstException::
noWriteMsg);
}
cfIndex.Close();

}
else
{
TRACE(_T("Failed to open index file for writing\n"));
cfInput.Close();
throw new
CFirstException(CFirstException::noWriteIdx);
}
cfInput.Close();
}
else
{
TRACE(_T("Failed to open input file %s\n"), FileName);
throw new CFirstException(CFirstException::
noInputFile);
}
if (lEntries)
{
ClearList();
m_lpseCodes = 0;
m_lpseNewCodes = 0;
m_lpseListEnd = 0;
m_lHRESULTs = 0;
ReadIndexFile();
if (m_bIsValid == FALSE)
{
CheckHResult(m_HResult);
}
}
}
catch (CFirstException *e)
{
UINT uStr;
HRESULT hr = e -> GetErrorString(uStr);
e -> Delete();
DoError(hr, uStr, 0);
}
catch (CFileException *e)
{
UINT uStr;
HRESULT hr = GetFileExceptionString(e, uStr);
e -> Delete();
DoError(hr, uStr, 0);
}

%RRNVVKRS

piracy@books-shop.com

catch (CMemoryException *e)


{
e -> Delete();
DoError(CTL_E_OUTOFMEMORY, IDS_MEMORYERROR, 0);
}
m_bInDispatch = FALSE;
return lEntries;
}
// ,
// , .
// CFirstException,
// CFileException CMemoryException.
long CFirstCtrl::DoBatchLoad(CStdioFile *cfIn,
CFile *cfIndex,
CFile *cfMsg)
{
long lEntries = 0;
cfIndex -> Seek(0, CFile::end);
CString csLine, csMsg, csSymbol;
while (GetNextDefineLine(cfIn, &csLine, &csMsg))
{
long lCode = GetTheCode(&csLine, &csSymbol);
unsigned long ulOffset;
if (FindEntry(lCode, &ulOffset))
{
TRACE1(_T("HRESULT %08X already in database - ignored\n"),
lCode);
}
else
{
long lMsgPos = cfMsg -> Seek(0, CFile::end);
cfIndex -> Write(&lCode, sizeof(lCode));
cfIndex -> Write(&lMsgPos, sizeof(lMsgPos));
cfMsg -> Write((LPCTSTR)csSymbol, csSymbol.GetLength() + 1);
cfMsg -> Write((LPCTSTR)csMsg, csMsg.GetLength() + 1);
++lEntries;

}
}
return lEntries;

// (
// CFirstException,
// CFileException CMemoryException.)
BOOL CFirstCtrl::GetNextDefineLine(CStdioFile *cfFile,
CString *csLine,
CString *csMessage)
{
_TCHAR szBuf[256];
CString csCompare;
BOOL bFound = FALSE;
LPTSTR lpszCnt;
do
{
lpszCnt = cfFile -> ReadString(szBuf, 255);
if (lpszCnt == NULL)
{
break;
}
csCompare = szBuf;

www.books-shop.com

bFound = (csCompare.Find(_T("// MessageText:")) != -1);


}
while (bFound == FALSE);
if (bFound)
{
//
cfFile -> ReadString(szBuf, 255);
// ()
csMessage -> Empty();
do
{
cfFile -> ReadString(szBuf, 255);
if (szBuf[3])
{
if (!csMessage -> IsEmpty())
{
*csMessage += _T(" ");
}
szBuf[_tcslen(szBuf) - 1] = TCHAR(0);
*csMessage += szBuf + 4;
}
}
while (szBuf[3]);
//
lpszCnt = cfFile -> ReadString(szBuf, 255);
if (lpszCnt == NULL)
{
TRACE(_T(
"The file given to BatchLoad
is in the wrong format\n"));
throw new CFirstException
(CFirstException::badCodesFile);
}
*csLine = szBuf;
return TRUE;
}

}
return FALSE;
long CFirstCtrl::GetTheCode(CString *csLine, CString *csSymbol)
{
// #define
// , MC
if (csLine -> Find(_T("#define")))
{
TRACE(_T(
"#define line doesnt start with exactly #define\n"));
throw new CFirstException(CFirstException::badCodesFile);
}
// #define
int i = 7;
// -
while ((csLine -> GetLength() > i) &&
(_istspace(csLine -> GetAt(i))))
{
++i;
}
if (csLine -> GetLength() <= i)
{
TRACE(_T("#define line is only #define\n"));
throw new CFirstException(CFirstException::badCodesFile);

www.books-shop.com

}
//
csSymbol -> Empty();
while ((csLine -> GetLength() > i) &&
!(_istspace(csLine -> GetAt(i))))
{
*csSymbol += csLine -> GetAt(i);
++i;
}
if (csLine -> GetLength() <= i)
{
TRACE(_T("#define line is only #define SYMBOL\n"));
throw new CFirstException(CFirstException::badCodesFile);
}
// -
while ((csLine -> GetLength() > i) &&
(_istspace(csLine -> GetAt(i))))
{
++i;
}
if (csLine -> GetLength() <= i)
{
TRACE(_T("#define line is only #define SYMBOL\n"));
throw new CFirstException(CFirstException::badCodesFile);
}
// WINERROR.H
// _HRESULT_TYPEDEF(),
// .
int pos;
if ((pos = csLine -> Find(_T("_HRESULT_TYPEDEF_("))) != -1)
{
i = pos + 18;
// 18
}

//
CString csNumber;
csNumber = csLine -> Mid(i);
// ,
// (. )
return _tcstoul(csNumber, NULL, 0);

//
BOOL CFirstCtrl::CreateFiles(void)
{
CFile
cfFile;
CString csFile;
BOOL
bRet = FALSE;
try
{

//
csFile.LoadString(IDS_INDEXFILE);
if (cfFile.Open(csFile, CFile::modeCreate |
CFile::modeWrite |
CFile::shareExclusive) == 0)
{
TRACE(_T("Error creating index file\n"));
}
else
{

www.books-shop.com

cfFile.Close();
}

// :
// .

//
// csFile.LoadString(IDS_MESSAGEFILE);
if (cfFile.Open(csFile, CFile::modeCreate |
CFile::modeWrite |
CFile::shareExclusive) == 0)
{
TRACE(_T("Error creating message file\n"));
}
else
{
cfFile.Close();
bRet = TRUE;
m_bFilesCreated = TRUE;
//
}

}
catch (CException *e)
{
// FALSE
e -> Delete();
return FALSE;
}
return bRet;
void CFirstCtrl::OnFreezeEvents(BOOL bFreeze)
{
m_nEventsFrozen += (bFreeze ? 1 : -1);
}

void CFirstCtrl::OnEventAdvise(BOOL bAdvise)


{
if (bAdvise && m_bFilesCreated && (m_nEventsFrozen == 0))
{
FireFilesCreated();
}
}
//
BOOL CFirstCtrl::CheckHResult(long nNewValue)
{
CString csLine;
m_csMessage.Empty();
m_csSymbol.Empty();
m_bIsValid = FALSE;
unsigned long ulOffset;
try
{
if (FindEntry(nNewValue, &ulOffset))
{
m_bIsValid = TRUE;
GetInfo(ulOffset);
csLine = m_csSymbol + _T(": ") + m_csMessage;
}
else
{
csLine.LoadString(IDS_NOVALID_HRESULT);
}

www.books-shop.com

SetText(csLine);
}
catch (CFirstException *e)
{
UINT uStr;
HRESULT hr = e -> GetErrorString(uStr);
e -> Delete();
DoError(hr, uStr, 0);
}
catch (CFileException *e)
{
UINT uStr;
HRESULT hr = GetFileExceptionString(e, uStr);
e -> Delete();
DoError(hr, uStr, 0);
}
catch (CMemoryException *e)
{
e -> Delete();
DoError(CTL_E_OUTOFMEMORY, IDS_MEMORYERROR, 0);
}
return m_bIsValid;

// , , ,
// !
void CFirstCtrl::DoError(HRESULT hresult,
UINT uDescription,
UINT helpid)
{
CString csDescription;
csDescription.LoadString(uDescription);
if (m_bInDispatch)
{
m_bInDispatch = FALSE;
ThrowError(hresult, csDescription, helpid);
}
else
{
if (m_nEventsFrozen == 0)
{
FireError(hresult, csDescription, helpid);
}
}
}
HRESULT CFirstCtrl::GetFileExceptionString(CFileException *cfEx,
UINT &uStr) const
{
HRESULT hr = S_OK;
uStr = IDS_FILEEXCEPTIONBASE + cfEx -> m_cause;
switch (cfEx -> m_cause)
{
case CFileException::generic:
hr = CTL_E_ILLEGALFUNCTIONCALL;
break;
case CFileException::fileNotFound:
hr = CTL_E_FILENOTFOUND;
break;
case CFileException::badPath:
hr = CTL_E_PATHFILEACCESSERROR;
break;

www.books-shop.com

case CFileException::tooManyOpenFiles:
hr = CTL_E_TOOMANYFILES;
break;
case CFileException::invalidFile:
hr = CTL_E_BADFILENAMEORNUMBER;
break;
case CFileException::directoryFull:
case CFileException::diskFull:
hr = CTL_E_DISKFULL;
break;
case CFileException::badSeek:
case CFileException::hardIO:
hr = CTL_E_DEVICEIOERROR;
break;
case CFileException::accessDenied:
case CFileException::removeCurrentDir:
case CFileException::sharingViolation:
case CFileException::lockViolation:
hr = CTL_E_PERMISSIONDENIED;
break;
case CFileException::endOfFile:
hr = CTL_E_BADRECORDLENGTH;
break;
default:
hr = CTL_E_ILLEGALFUNCTIONCALL;
uStr = IDS_UNKNOWNEXCEPTIONCAUSE;
break;
}

}
return hr;

9-3. FIRSTEX.H

class CFirstException : public CException


{
DECLARE_DYNAMIC(CFirstException)
public:
enum
{
none = 0,
noMessageFile,
invalidFile,
noWriteMsg,
noWriteIdx,
noIndexFile,
noCreateFile,
noInputFile,
badCodesFile,
badParameters
};
//
CFirstException(int cause = CFirstException::none)
{
m_cause = cause;
}
//

www.books-shop.com

int m_cause;
//
HRESULT GetErrorString(UINT &uStr) const;
//
virtual ~CFirstException() {}
};
9-4. FIRSTEX.H

#include "stdafx.h"
#include "first.h"
#include "firstex.h"
IMPLEMENT_DYNAMIC(CFirstException, CException)
HRESULT CFirstException::GetErrorString(UINT &uStr) const
{
HRESULT hr = S_OK;
uStr = IDS_FIRSTEXCEPTIONBASE + m_cause;
switch (m_cause)
{
case noMessageFile:
case noIndexFile:
case noInputFile:
hr = CTL_E_FILENOTFOUND;
break;
case invalidFile:
case badCodesFile:
hr = CTL_E_INVALIDFILEFORMAT;
break;
case noWriteMsg:
case noWriteIdx:
hr = CTL_E_PATHFILEACCESSERROR;
break;
case noCreateFile:
hr = CTL_E_PERMISSIONDENIED;
break;
case badParameters:
hr = CTL_E_INVALIDUSEOFNULL;
break;
default:
hr = CTL_E_ILLEGALFUNCTIONCALL;
uStr = IDS_UNKNOWNEXCEPTIONCAUSE;

}
return hr;

FIRSTCTL.H ( 9-1) :

BOOL
m_bInDispatch;
CString m_csBadMessage;
:

void DoError(HRESULT hresult, UINT uDescription, UINT helpid);


void ReallySetHResult(long nNewValue);
HRESULT GetFileExceptionString(CFileException *cfEx,
UINT &uStr) const;

www.books-shop.com

m_bInDispatch , ,
, (
ThrowError) , Automation (
FireError). m_csBadMessage ,
,
. DoError
ThrowError FireError,
m_bInDispatch. ReallySetHResult SetHResult,
ReallySetHResult ( SetHResult
), ( ), , ,
,
Automation, . GetFileExceptionString
, CFileException
( CFileException
).
FirstCtrl. #include
FIRSTEX.H , CFirstException.
CException
. ,
FirstCtrl.
CFirstCtrl.
ReadIndexFile.
, try-
CException. ReadIndexFile ,
, / .
.
( ),
.
m_csBadMessage
CException. m_csBadMessage ,
: ,
HRESULT . ,
. ,
IsKindOf RUNTIME_CLASS ,
CFirstException CFileException ( MFC,
RTTI, runtime- ).
, (
GetErrorString CFirstException
GetFileExceptionString CFileException). .
Error;
.
.

.
catch- (
), .
, .
DoPropExchange : - SetHResult
, DoPropExchange
Automation,
, Automation. m_bInDispatch FALSE
ReallySetHResult. SetHResult :
m_bInDispatch TRUE (
COM), ReallySetHResult
m_bInDispatch. , SetHResult,
ReallySetHResult. ,
CheckHResult ,
(
ReallySetHResult).

www.books-shop.com

,
( , ,
). ,
. Add: HRESULT
( FindEntry, )
m_bInDispatch TRUE try-.
, Add. ,
CFirstException throw.
, CFirstException ,
, catch-
, .
badParameters , .
catch Add ( ) .
,
. ,
DoError, ThrowError FireError (
m_bInDispatch). ThrowError. :
HRESULT GetErrorString ,
.
,
. ThrowError Automation
. , ,
DoError ( m_bInDispatch FALSE),
! , catch-, DoError,

.
BatchLoad try-, .
, ,
.
CFirstException , ,
.
DoError . ,
. (,
e -> Delete() ).
,
( ).
ReadIndexFile. catch-,
,
( , ReadIndexFile, ,
, ) throw .
,
. ReadIndexFile ,
CFirstException.

,
. , DoBatchLoad.
.
, , .
, , ,
DoBatchLoad , BatchLoad.
GetTheCode,
. , HRESULT ,
. ,
, ,
GetTheCode _tcstoul .
, 0, . ,
, ,
. , 123L

www.books-shop.com

L, 123. , 123X4
123, X. , ,
, , .
. !
CreateFiles
FALSE, ,
.
DoError .
, , Automation,
. ,
.
GetFileExceptionString m_cause CFileException
HRESULT . ,
, m_cause ,
. C++, m_cause,
, .
CFileException !
, CFirstException.
FIRSTEX.CPP.
CException ( MFC) (
MFC). ,
, . ,
m_cause. .
GetErrorString,
m_cause HRESULT.
FIRSTEX.CPP, , m_cause
HRESULT. HRESULT.
HRESULT CUSTOM_CTL_SCODE,
.
m_cause ,
.
.


,
C++ , Microsoft Visual C++ 1.5x.
MFC, TRY, CATCH, THROW . .
. ,
. ? CString. CString
(heap) new,
CString. C++ ,
. ,
CString::Empty . , 16-
ActiveX, :

cString csMsg;
csMsg.LoadString(IDS_INDEX_FILE);
if (DoSomething() == FALSE)
{
THROW(new CAnException);
}
:

csMsg.LoadString(IDS_INDEX_FILE);
if (DoSomething() == FALSE)
{
csMsg.Empty();
%RRNVVKRS

piracy@books-shop.com

THROW(new CAnException);
}
First, ,
32- ,
C++ ++ try, catch, throw . .
MFC. !

, CFirstException ,
. , .
First ,
. ( )

. ,
, ,
. ,

.

9.6 MF
MFC, CException
. :
C++ ? ,
MFC, .
C++, , .
MFC ( ,
).
,
. , :

if (- )
{
throw 42;
}

catch (int e)
{
if (e == 42)
{
, 42
}
}
. , catch-
, .
delete , . ,
,
42!

www.books-shop.com

10


ActiveX. -
, .
, ?
,
. , World Wide Web (
), Web
. , First ,
, , .
,
, , .
, ,
ODBC , , ,
.
First,
. . First
. , Second.

10.1
ActiveX ,
,
, (
). ActiveX , .

, . ,
, ActiveX (,
). Microsoft Visual Basic, -
C++ Java. , ,
,
( ) - .

10.2
, ? , ,
ActiveX ,
Automation ( , ,
).
(, C++)
Automation
, . , ,
, .
, ActiveX
.

www.books-shop.com

ActiveX (,
. .)? . ActiveX,
,
. -,
1. ,
,
.

, ,
ActiveX. , ,
, ,
.
, . ?
,
(, ), ,
,
.
,
. ,
( ,
, ,
).
, .
, ActiveX , ,
?
,
. ,
. ,
. (
), (
). , .
,
,
. , ,
, . ,
.
,
. , !
( 56% 57% 58% . .);
, . ,
. ,
, ,
.
,
. , ,
. ,
.
(,
)
.
, - Web .
, ( , )
Web-, . ,
, -. Microsoft
,
.
, .
Web- ,
.

www.books-shop.com

OCX 96 Microsoft
.
, .
, ,
, .
C++ ATL.

10.3
,
Automation - .
? ?
, ? ,
, , .
?
, ,
,
?
?
:

?
?

,
. , ,
. ,
.
Automation? ,
(
). , - -
Address,
- ( , IDispatch).
Visual Basic :

If TheCustomer.Address.IsValidZip = False Then


MsgBox "The zip code is invalid - please re-enter"
End If
- , ClassWizard Address
LPIDISPATCH , COleControl. ClassWizard
, CCmdTarget,
Automation. COM- (

, Visual Basic), .
- .
COM-, : ActiveX
, Automation,
. ActiveX
, . ,
- :

Dim TheCustomer As Customer


Set TheCustomer = CreateObject("Customer.Control.1")
... . .
? CreateInstance
(, ,

www.books-shop.com

. .)
, . Automation,
. : ,
, .
, -
. , Automation
, :

. ,

.
BSTR.
, ,
-
, , ASCII
Unicode. !
BSTR.
!
.
IDataObject. . ,
, .
. ,
.
.
, IDataObject.

, . ,
( ),
(IDataObject).

10.4
, Windows
(,
). .

Windows. OLE ControlWizard ,
. (,
) , -
.
. ,
.

10.5
ActiveX
, Visual Basic. , ,
, ,
Visual Basic, . 10-1.

www.books-shop.com

.10-1.
, (IDE)
. . ,
.
First. TestProp,
ClassWizard,
( ). short.
ODL- importlib:

typedef enum
{
[helpstring("First")] valOne = 1,
[helpstring("Second")] valTwo = 2,
[helpstring("Third")] valThree = 3,
} MYENUM;
MYENUM. MYENUM
ODL/IDL.
C/C++ (, ,
short). : valOne, valTwo valThree.
1, 2 3. ,
0, 1 2. ,
. Visual Basic.
TestProp , Visual Basic
.
? , . ODL-
TestProp. :

www.books-shop.com

[id(1)] short TestProp;


( .) ,
:

[id(1)] MYENUM TestProp;


, C++
short, .
Visual Basic.
TestProp. ,
, . , Visual Basic
, .
. ,
,
. ,
, .
COleControl,
IPerPropertyBrowsing.
, (,
C++ This Property).
IPerPropertyBrowsing 11, .

10.6 ActiveX
, First,
. ( , ) ,
, ,
. ODBC ( , Remote Data
Objects), , HRESULT .
, .
, MFC CRecordSet,
. 10-1 10-2
, CRecordSet, .
10-3 10-4
( CD-ROM
\CODE\CHAP10\FIRST).

ODBC Unicode,
First Unicode. First ANSI Microsoft Win32
, ODBC , Unicode.

Microsoft Access (
ODBC- Microsoft Access, Access )
HRESULTS.MDB. , : HRESULT
long, 255 ,
MEMO- ( , ,
255 ) 1023 .
HRESULTS. CDbSet ClassWizard,
. ClassWizard , Add Class,
New CDbSet. CRecordSet
Create. ClassWizard ODBC (
DAO Data Access Objects). HRESULTS
OK. , .
, HRESULTS.

www.books-shop.com

OK, ClassWizard ,
.
, ,
. RFX_Text
DoFieldExchange .
. 255
, RFX_Text 256.
1023 , 1024.
? (recordset) ,
ODBC.
CString. CString ,
, .
, ODBC ,
.
MFC ASSERT (
!). RFX_Text ,
.

,
255 .
.
. ,
ODBC ; . ,
, ,
.
!

(public) :

long m_HRESULTParam;
,
. DoFieldExchange,
:

pFX -> SetFieldType(CFieldExchange::param);


RFX_Long(pFX, "HRESULT", m_HRESULTParam);
, ,
HRESULT. CDbSet,
m_HRESULTParam HRESULT, ,
SQL-. ,

m_nParams .
.
10-1. DBSET.H

// DbSet.h :
//////////////////////////////////////////////////////////////
// CDbSet
class CDbSet : public CRecordset
{
public:
CDbSet(CDatabase* pDatabase = NULL);
DECLARE_DYNAMIC(CDbSet)

www.books-shop.com

// /
//{{AFX_FIELD(CDbSet, CRecordset)
long
m_HRESULT;
CString
m_Symbol;
CString
m_Message;
//}}AFX_FIELD
//
// ,
// ClassWizard
//{{AFX_VIRTUAL(CDbSet)
public:
virtual CString GetDefaultConnect();
//
virtual CString GetDefaultSQL();
// SQL-
virtual void DoFieldExchange(CFieldExchange* pFX);
//}}AFX_VIRTUAL

// RFX

//
public:
long m_HRESULTParam;
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
};
10-2. DBSET.CPP

// DbSet.cpp :
//
#include "stdafx.h"
#include "First.h"
#include "DbSet.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//////////////////////////////////////////////////////////////
// CDbSet
IMPLEMENT_DYNAMIC(CDbSet, CRecordset)
CDbSet::CDbSet(CDatabase* pdb)
: CRecordset(pdb)
{
//{{AFX_FIELD_INIT(CDbSet)
m_HRESULT = 0;
m_Symbol = _T("");
m_Message = _T("");
m_nFields = 3;
//}}AFX_FIELD_INIT
m_nDefaultType = snapshot;
++m_nParams;
}

www.books-shop.com

CString CDbSet::GetDefaultConnect()
{
return _T("ODBC;DSN=HRESULTS");
}
CString CDbSet::GetDefaultSQL()
{
return _T("[HRESULTS]");
}
void CDbSet::DoFieldExchange(CFieldExchange* pFX)
{
//{{AFX_FIELD_MAP(CDbSet)
pFX->SetFieldType(CFieldExchange::outputColumn);
RFX_Long(pFX, _T("[HRESULT]"), m_HRESULT);
RFX_Text(pFX, _T("[Symbol]"), m_Symbol, 256);
RFX_Text(pFX, _T("[Message]"), m_Message, 1024);
//}}AFX_FIELD_MAP
pFX -> SetFieldType ( CFieldExchange::param );
RFX_Long ( pFX, "HRESULT", m_HRESULTParam );
}
//////////////////////////////////////////////////////////////
// CDbSet
#ifdef _DEBUG
void CDbSet::AssertValid() const
{
CRecordset::AssertValid();
}
void CDbSet::Dump(CDumpContext& dc) const
{
CRecordset::Dump(dc);
}
#endif //_DEBUG
10-3. FIRSTCTL.H

// FirstCtl.h : OLE CFirstCtrl


//////////////////////////////////////////////////////////////
// CFirstCtrl : FirstCtl.cpp
class CFirstCtrl : public COleControl
{
DECLARE_DYNCREATE(CFirstCtrl)
//
public:
CFirstCtrl();
//
// ,
// ClassWizard
//{{AFX_VIRTUAL(CFirstCtrl)
public:
virtual void OnDraw(CDC* pdc,
const CRect& rcBounds,
const CRect& rcInvalid);
virtual void DoPropExchange(CPropExchange* pPX);

%RRNVVKRS

piracy@books-shop.com

virtual void OnResetState();


virtual void OnFreezeEvents(BOOL bFreeze);
//}}AFX_VIRTUAL
//
protected:
~CFirstCtrl();
DECLARE_OLECREATE_EX(CFirstCtrl)
DECLARE_OLETYPELIB(CFirstCtrl)
DECLARE_PROPPAGEIDS(CFirstCtrl)
DECLARE_OLECTLTYPE(CFirstCtrl)

//
//
//
//
//
//
//

guid
GetTypeInfo

//
//{{AFX_MSG(CFirstCtrl)
// - ClassWizard
// .
//
// !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
//
//{{AFX_DISPATCH(CFirstCtrl)
short m_testProp;
afx_msg short GetCode();
afx_msg BSTR GetErrorName();
afx_msg BSTR GetFacility();
afx_msg BSTR GetMessage();
afx_msg BSTR GetSeverity();
afx_msg long GetHResult();
afx_msg void SetHResult(long nNewValue);
afx_msg BOOL Add(long hResult, LPCTSTR Symbol,
LPCTSTR Message);
afx_msg long BatchLoad(LPCTSTR FileName);
//}}AFX_DISPATCH
DECLARE_DISPATCH_MAP()
afx_msg void AboutBox();
//
//{{AFX_EVENT(CFirstCtrl)
void FireInvalidHResult(long HResult)
{FireEvent(eventidInvalidHResult,
EVENT_PARAM(VTS_I4), HResult);}
//}}AFX_EVENT
DECLARE_EVENT_MAP()
//
public:
enum
{
//{{AFX_DISP_ID(CFirstCtrl)
dispidCode = 2L,
dispidErrorName = 3L,
dispidFacility = 4L,
dispidMessage = 5L,
dispidSeverity = 6L,
dispidHResult = 7L,
dispidTestProp = 1L,
dispidAdd = 8L,
dispidBatchLoad = 9L,
eventidInvalidHResult = 1L,

www.books-shop.com

//}}AFX_DISP_ID
};
private:
long
m_HResult;
BOOL
m_bIsValid;
CString m_csSymbol;
CString m_csMessage;
short
m_nEventsFrozen;
BOOL
m_bInDispatch;
CString m_csBadMessage;
CDbSet *m_rsTable;
BOOL GetNextDefineLine(CStdioFile *cfFile,
CString *csLine,
CString *csMessage);
long GetTheCode(CString *csLine, CString *csSymbol);
BOOL FindEntry(long lCode);
void GetInfo(void);
long DoBatchLoad(CStdioFile *cfIn);
BOOL CheckHResult(long nNewValue);
void DoError(HRESULT hresult, UINT uDescription,
UINT helpid);
void DoError(HRESULT hresult,
CString &strDescription,
UINT helpid);
void ReallySetHResult(long nNewValue);
HRESULT GetFileExceptionString(CFileException *cfEx,
UINT &uStr) const;
void CheckDatabase(void);
};
10-4. FIRSTCTL.CPP

// FirstCtl.cpp : OLE CFirstCtrl


#include
#include
#include
#include
#include
#include

"stdafx.h"
"First.h"
"DbSet.h"
"FirstCtl.h"
"FirstPpg.h"
"FirstEx.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
IMPLEMENT_DYNCREATE(CFirstCtrl, COleControl)
//////////////////////////////////////////////////////////////
//
BEGIN_MESSAGE_MAP(CFirstCtrl, COleControl)
//{{AFX_MSG_MAP(CFirstCtrl)
// - ClassWizard
// .
//
// !

www.books-shop.com

//}}AFX_MSG_MAP
ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
END_MESSAGE_MAP()
//////////////////////////////////////////////////////////////
//
BEGIN_DISPATCH_MAP(CFirstCtrl, COleControl)
//{{AFX_DISPATCH_MAP(CFirstCtrl)
DISP_PROPERTY(CFirstCtrl, "TestProp", m_testProp, VT_I2)
DISP_PROPERTY_EX(CFirstCtrl, "Code", GetCode,
SetNotSupported, VT_I2)
DISP_PROPERTY_EX(CFirstCtrl, "ErrorName", GetErrorName,
SetNotSupported, VT_BSTR)
DISP_PROPERTY_EX(CFirstCtrl, "Facility", GetFacility,
SetNotSupported, VT_BSTR)
DISP_PROPERTY_EX(CFirstCtrl, "Message", GetMessage,
SetNotSupported, VT_BSTR)
DISP_PROPERTY_EX(CFirstCtrl, "Severity", GetSeverity,
SetNotSupported, VT_BSTR)
DISP_PROPERTY_EX(CFirstCtrl, "HResult", GetHResult,
SetHResult, VT_I4)
DISP_FUNCTION(CFirstCtrl, "Add", Add, VT_BOOL,
VTS_I4 VTS_BSTR VTS_BSTR)
DISP_FUNCTION(CFirstCtrl, "BatchLoad",
BatchLoad, VT_I4, VTS_BSTR)
DISP_STOCKFUNC_REFRESH()
DISP_STOCKPROP_BACKCOLOR()
DISP_STOCKPROP_CAPTION()
DISP_STOCKPROP_ENABLED()
DISP_STOCKPROP_FONT()
DISP_STOCKPROP_FORECOLOR()
DISP_STOCKPROP_HWND()
//}}AFX_DISPATCH_MAP
DISP_FUNCTION_ID(CFirstCtrl, "AboutBox", DISPID_ABOUTBOX,
AboutBox, VT_EMPTY, VTS_NONE)
END_DISPATCH_MAP()
//////////////////////////////////////////////////////////////
//
BEGIN_EVENT_MAP(CFirstCtrl, COleControl)
//{{AFX_EVENT_MAP(CFirstCtrl)
EVENT_CUSTOM("InvalidHResult", FireInvalidHResult, VTS_I4)
//}}AFX_EVENT_MAP
END_EVENT_MAP()
///////////////////////////////////////////////////////////////
//
// .
// !
BEGIN_PROPPAGEIDS(CFirstCtrl, 1)
PROPPAGEID(CFirstPropPage::guid)
END_PROPPAGEIDS(CFirstCtrl)
//////////////////////////////////////////////////////////////
// GUID
IMPLEMENT_OLECREATE_EX(CFirstCtrl, "FIRST.FirstCtrl.1",
0x14bc5f80, 0xdbd2, 0x11cd, 0x92, 0xb4, 0x8, 0,
0x2b, 0x29, 0x1e, 0xed)

www.books-shop.com

//////////////////////////////////////////////////////////////
//
IMPLEMENT_OLETYPELIB(CFirstCtrl, _tlid, _wVerMajor, _wVerMinor)
//////////////////////////////////////////////////////////////
//
const IID BASED_CODE IID_DFirst =
{ 0xa29db7d3, 0xe4e5, 0x11cf, { 0x84,
0x57,
const IID BASED_CODE IID_DFirstEvents =
{ 0xa29db7d4, 0xe4e5, 0x11cf, { 0x84,
0x57,

0x8a, 0, 0xaa, 0,
0x54, 0xfd } };
0x8a, 0, 0xaa, 0,
0x54, 0xfd } };

//////////////////////////////////////////////////////////////
//
static const DWORD BASED_CODE _dwFirstOleMisc =
OLEMISC_ACTIVATEWHENVISIBLE |
OLEMISC_SETCLIENTSITEFIRST |
OLEMISC_INSIDEOUT |
OLEMISC_CANTLINKINSIDE |
OLEMISC_RECOMPOSEONRESIZE;
IMPLEMENT_OLECTLTYPE(CFirstCtrl, IDS_FIRST, _dwFirstOleMisc)
//////////////////////////////////////////////////////////////
// CFirstCtrl::CFirstCtrlFactory::UpdateRegistry // CFirstCtrl
BOOL CFirstCtrl::CFirstCtrlFactory::
UpdateRegistry(BOOL bRegister)
{
// ,
// .
// MFC TechNote 64.
// ,
//
// 6- afxRegApartmentThreading 0.

if (bRegister)
return AfxOleRegisterControlClass(
AfxGetInstanceHandle(),
m_clsid,
m_lpszProgID,
IDS_FIRST,
IDB_FIRST,
afxRegApartmentThreading,
_dwFirstOleMisc,
_tlid,
_wVerMajor,
_wVerMinor);
else
return AfxOleUnregisterClass(m_clsid, m_lpszProgID);

//////////////////////////////////////////////////////////////
// CFirstCtrl::CFirstCtrl -

www.books-shop.com

CFirstCtrl::CFirstCtrl()
{
InitializeIIDs(&IID_DFirst, &IID_DFirstEvents);
m_HResult = 0;
m_bIsValid = FALSE;
m_nEventsFrozen = 0;
m_bInDispatch = FALSE;
m_rsTable = 0;
m_csBadMessage.LoadString(IDS_BADMESSAGE);
try
{

CString csSql;
csSql.LoadString(IDS_SQL);
m_rsTable = new CDbSet;
m_rsTable -> m_HRESULTParam = 0;
if (m_rsTable -> Open(CRecordset::snapshot, csSql) == FALSE)
{
throw new CFirstException(CFirstException::
noDatabase);
}

}
catch (CException *e)
{
CString csExtra;
UINT uStr = 0;
if (e -> IsKindOf(RUNTIME_CLASS(CFirstException)))
{
((CFirstException *)e) -> GetErrorString(uStr);
}
else if (e -> IsKindOf(RUNTIME_CLASS(CFileException)))
{
GetFileExceptionString((CFileException *)e, uStr);
}
else if (e -> IsKindOf(RUNTIME_CLASS(CDBException)))
{
csExtra = ((CDBException *)e) ->
m_strStateNativeOrigin;
}
if (uStr)
{
csExtra.LoadString(uStr);
}
// ,
//
if (!csExtra.IsEmpty())
{
m_csBadMessage += _T("\n\nActual error message:\n\n");
m_csBadMessage += csExtra;
}
AfxMessageBox(m_csBadMessage, MB_OK);

//
m_csBadMessage.LoadString(IDS_BADMESSAGE);
e -> Delete();

//////////////////////////////////////////////////////////////
// CFirstCtrl::~CFirstCtrl -
CFirstCtrl::~CFirstCtrl()
{

www.books-shop.com

if (m_rsTable)
{
if (m_rsTable -> IsOpen())
{
m_rsTable -> Close();
}
delete m_rsTable;
}

////////////////////////////////////////////////////////////
// CFirstCtrl::OnDraw -
void CFirstCtrl::OnDraw(
CDC* pdc, const CRect& rcBounds,
const CRect& rcInvalid)
{
//
CFont *hfOld = SelectStockFont(pdc);
CBrush cbBack(TranslateColor(GetBackColor()));
pdc -> FillRect(rcBounds, &cbBack);
pdc -> SetTextColor(TranslateColor(GetForeColor()));
pdc -> SetBkMode(TRANSPARENT);
RECT rcTemp = rcBounds;
pdc -> DrawText(InternalGetText(), -1, &rcTemp,
DT_SINGLELINE | DT_CENTER | DT_VCENTER);
pdc -> SelectObject(hfOld);
}
//////////////////////////////////////////////////////////////
// CFirstCtrl::DoPropExchange -
void CFirstCtrl::DoPropExchange(CPropExchange* pPX)
{
ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
COleControl::DoPropExchange(pPX);

PX_Long(pPX, _T("HResult"), m_HResult, 0);


if (pPX -> IsLoading())
{
ReallySetHResult(m_HResult);
}
/////////////////////////////////////////////////////////////
// CFirstCtrl::OnResetState -
//
void CFirstCtrl::OnResetState()
{
COleControl::OnResetState();

//
//
// DoPropExchange

//

//////////////////////////////////////////////////////////////
// CFirstCtrl::AboutBox - About
void CFirstCtrl::AboutBox()

www.books-shop.com

{
CDialog dlgAbout(IDD_ABOUTBOX_FIRST);
dlgAbout.DoModal();
}
//////////////////////////////////////////////////////////////
// CFirstCtrl
short CFirstCtrl::GetCode()
{
if (m_bIsValid)
{
return short(m_HResult & 0xFFFF);
}
else
{
return -1;
}
}
BSTR CFirstCtrl::GetErrorName()
{
return m_csSymbol.AllocSysString();
}
BSTR CFirstCtrl::GetFacility()
{
CString strResult;
short nFacility = IDS_NOVALID_HRESULT;
if (m_bIsValid)
{
nFacility = short((m_HResult & 0x0FFF0000) >> 16);
switch (nFacility)
{
case 0: case 1: case 2: case 3:
case 4: case 7: case 8: case 9:
case 10: case 11:
break;
default:
nFacility = -1;
}
nFacility += IDS_FACILITY_NULL;
}
strResult.LoadString(nFacility);
return strResult.AllocSysString();
}
BSTR CFirstCtrl::GetMessage()
{
return m_csMessage.AllocSysString();
}
BSTR CFirstCtrl::GetSeverity()
{
CString strResult;
short nSeverity = IDS_NOVALID_HRESULT;
if (m_bIsValid)
{
nSeverity = short((m_HResult & 0xC0000000) >> 30) +
IDS_SEVERITY_SUCCESS;
}
strResult.LoadString(nSeverity);
return strResult.AllocSysString();

www.books-shop.com

}
long CFirstCtrl::GetHResult()
{
return m_HResult;
}
void CFirstCtrl::SetHResult(long nNewValue)
{
m_bInDispatch = TRUE;
ReallySetHResult(nNewValue);
m_bInDispatch = FALSE;
}
void CFirstCtrl::ReallySetHResult(long nNewValue)
{
if (CheckHResult(nNewValue) == FALSE)
{
if (m_nEventsFrozen == 0)
{
FireInvalidHResult(nNewValue);
}
}
m_HResult = nNewValue;
SetModifiedFlag();
}
//
BOOL CFirstCtrl::Add(long hResult, LPCTSTR Symbol, LPCTSTR Message)
{
m_bInDispatch = TRUE;
try
{
if (FindEntry(hResult))
{
TRACE(_T("Add: HRESULT %ln already in database\n"),
hResult);
return TRUE;
}
// NULL
if (Symbol == 0 || Message == 0 ||
*Symbol == 0 || *Message == 0)
{
throw new CFirstException(CFirstException::
badParameters);
}
if (m_rsTable -> CanAppend() == FALSE)
{
TRACE(_T("Database is read-only\n"));
return FALSE;
}
m_rsTable -> AddNew();
m_rsTable -> m_HRESULT = hResult;
m_rsTable -> m_Symbol = Symbol;
m_rsTable -> m_Message = Message;
m_rsTable -> Update();
}
catch (CException *e)
//
{
HRESULT hr;
UINT uStr;
if (e -> IsKindOf(RUNTIME_CLASS(CFirstException)))
{

www.books-shop.com

hr = ((CFirstException *)e) -> GetErrorString(uStr);


}
else if (e -> IsKindOf(RUNTIME_CLASS(CFileException)))
{
hr = GetFileExceptionString((CFileException *)e, uStr);
}
else if (e -> IsKindOf(RUNTIME_CLASS(CMemoryException)))
{
hr = CTL_E_OUTOFMEMORY;
uStr = IDS_MEMORYERROR;
}
else if (e -> IsKindOf(RUNTIME_CLASS(CDBException)))
{
e -> Delete();
DoError(FIRSTCTL_E_ODBCERROR,
((CDBException *)e) -> m_strStateNativeOrigin, 0);
}
else
{
hr = CTL_E_ILLEGALFUNCTIONCALL;
uStr = IDS_UNEXPECTEDEXCEPTION;
}
e -> Delete();
DoError(hr, uStr, 0);

}
if (m_bIsValid == FALSE)
{
CheckHResult(m_HResult);
}
m_bInDispatch = FALSE;
return TRUE;
long CFirstCtrl::BatchLoad(LPCTSTR FileName)
{
CStdioFile cfInput;
long lEntries = 0;
m_bInDispatch = TRUE;
try
{
CheckDatabase();
if (m_rsTable -> CanAppend() == FALSE)
{
TRACE(_T("Database is read-only\n"));
return FALSE;
}
// NULL
if (FileName == NULL)
{
throw new CFirstException(CFirstException::
badParameters);
}
if (cfInput.Open(FileName, CFile::typeText |
CFile::modeRead) == TRUE)
{
lEntries = DoBatchLoad(&cfInput);
cfInput.Close();
}
else
{
TRACE(_T("Failed to open input file %s\n"),
FileName);
throw new CFirstException(CFirstException::

www.books-shop.com

noInputFile);
}
if (lEntries)
{
if (m_bIsValid == FALSE)
{
CheckHResult(m_HResult);
}
}

}
catch (CFirstException *e)
{
UINT uStr;
HRESULT hr = e -> GetErrorString(uStr);
e -> Delete();
DoError(hr, uStr, 0);
}
catch (CFileException *e)
{
UINT uStr;
HRESULT hr = GetFileExceptionString(e, uStr);
e -> Delete();
DoError(hr, uStr, 0);
}
catch (CMemoryException *e)
{
e -> Delete();
DoError(CTL_E_OUTOFMEMORY, IDS_MEMORYERROR, 0);
}
catch (CDBException *e)
{
CString csError = e -> m_strStateNativeOrigin;
e -> Delete();
DoError(FIRSTCTL_E_ODBCERROR, csError, 0);
}
m_bInDispatch = FALSE;
return lEntries;
// CFirstException,
// CFileException,
// CDBException CMemoryException
BOOL CFirstCtrl::FindEntry(long lCode)
{
CheckDatabase();

m_rsTable -> m_HRESULTParam = lCode;


if (m_rsTable -> Requery() == FALSE)
{
throw new CFirstException(CFirstException::queryFailed);
}
return !m_rsTable -> IsBOF();

// CFirstException,
// CFileException,
// CDBException CMemoryException
void CFirstCtrl::GetInfo()
{
CheckDatabase();
m_csSymbol = m_rsTable -> m_Symbol;
m_csMessage = m_rsTable -> m_Message;
}
%RRNVVKRS

piracy@books-shop.com

// ,
// , .
// CFirstException,
// CFileException CMemoryException.
long CFirstCtrl::DoBatchLoad(CStdioFile *cfIn)
{
long lEntries = 0;

CString csLine, csMsg, csSymbol;


while (GetNextDefineLine(cfIn, &csLine, &csMsg))
{
long lCode = GetTheCode(&csLine, &csSymbol);
if (FindEntry(lCode))
{
TRACE1(_T("HRESULT %08X already in database - ignored\n"),
lCode);
}
else
{
m_rsTable -> AddNew();
m_rsTable -> m_HRESULT = lCode;
m_rsTable -> m_Symbol = csSymbol;
m_rsTable -> m_Message = csMsg;
m_rsTable -> Update();
++lEntries;
}
}
return lEntries;

// (
// CFirstException,
// CFileException CMemoryException.)
BOOL CFirstCtrl::GetNextDefineLine(CStdioFile *cfFile,
CString *csLine,
CString *csMessage)
{
_TCHAR szBuf[256];
CString csCompare;
BOOL bFound = FALSE;
LPTSTR lpszCnt;
do
{
lpszCnt = cfFile -> ReadString(szBuf, 255);
if (lpszCnt == NULL)
{
break;
}
csCompare = szBuf;
bFound = (csCompare.Find(_T("// MessageText:")) != -1);
}
while (bFound == FALSE);
if (bFound)
{
//
cfFile -> ReadString(szBuf, 255);
// ()
csMessage -> Empty();
do
{
cfFile -> ReadString(szBuf, 255);

www.books-shop.com

if (szBuf[3])
{
if (!csMessage -> IsEmpty())
{
*csMessage += _T(" ");
}
szBuf[_tcslen(szBuf) - 1] = TCHAR(0);
*csMessage += szBuf + 4;
}
}
while (szBuf[3]);
//
lpszCnt = cfFile -> ReadString(szBuf, 255);
if (lpszCnt == NULL)
{
TRACE(_T("The file given to BatchLoad is in the wrong format\n"));
throw new CFirstException(CFirstException::
badCodesFile);
}
*csLine = szBuf;
return TRUE;
}
return FALSE;
}
long CFirstCtrl::GetTheCode(CString *csLine, CString *csSymbol)
{
// #define
// , MC
if (csLine -> Find(_T("#define")))
{
TRACE(_T(
"#define line doesnt start with exactly #define\n"));
throw new CFirstException(CFirstException::
badCodesFile);
}
// #define
int i = 7;
// -
while ((csLine -> GetLength() > i) &&
(_istspace(csLine -> GetAt(i))))
{
++i;
}
if (csLine -> GetLength() <= i)
{
TRACE(_T("#define line is only #define\n"));
throw new CFirstException(CFirstException::
badCodesFile);
}
//
csSymbol -> Empty();
while ((csLine -> GetLength() > i) &&
!(_istspace(csLine -> GetAt(i))))
{
*csSymbol += csLine -> GetAt(i);
++i;
}
if (csLine -> GetLength() <= i)
{
TRACE(_T("#define line is only #define SYMBOL\n"));

www.books-shop.com

throw new CFirstException(CFirstException::


badCodesFile);

// -
while ((csLine -> GetLength() > i) &&
(_istspace(csLine -> GetAt(i))))
{
++i;
}
if (csLine -> GetLength() <= i)
{
TRACE(_T("#define line is only #define SYMBOL\n"));
throw new CFirstException(CFirstException::
badCodesFile);
}
// WINERROR.H
//
// _HRESULT_TYPEDEF(),
// .
int pos;
if ((pos = csLine -> Find(_T("_HRESULT_TYPEDEF_("))) != -1)
{
i = pos + 18;
// 18
}

//
CString csNumber;
csNumber = csLine -> Mid(i);
// ,
// (. )
return _tcstoul(csNumber, NULL, 0);
void CFirstCtrl::OnFreezeEvents(BOOL bFreeze)
{
m_nEventsFrozen += (bFreeze ? 1 : -1);
}
//
BOOL CFirstCtrl::CheckHResult(long nNewValue)
{
CString csLine;
m_csMessage.Empty();
m_csSymbol.Empty();
m_bIsValid = FALSE;
try
{

if (FindEntry(nNewValue))
{
m_bIsValid = TRUE;
GetInfo();
csLine = m_csSymbol + _T(": ") + m_csMessage;
}
else
{
csLine.LoadString(IDS_NOVALID_HRESULT);
}
SetText(csLine);

www.books-shop.com

catch (CFirstException *e)


{
UINT uStr;
HRESULT hr = e -> GetErrorString(uStr);
e -> Delete();
DoError(hr, uStr, 0);
}
catch (CFileException *e)
{
UINT uStr;
HRESULT hr = GetFileExceptionString(e, uStr);
e -> Delete();
DoError(hr, uStr, 0);
}
catch (CMemoryException *e)
{
e -> Delete();
DoError(CTL_E_OUTOFMEMORY, IDS_MEMORYERROR, 0);
}
catch (CDBException *e)
{
CString csError = e -> m_strStateNativeOrigin;
e -> Delete();
DoError(FIRSTCTL_E_ODBCERROR, csError, 0);
}
return m_bIsValid;
}
// , , ,
// !
void CFirstCtrl::DoError(HRESULT hresult,
UINT uDescription,
UINT helpid)
{
CString csDescription;
csDescription.LoadString(uDescription);
DoError(hresult, csDescription, helpid);
}
void CFirstCtrl::DoError(HRESULT hresult,
CString &strDescription,
UINT helpid)
{
if (m_bInDispatch)
{
m_bInDispatch = FALSE;
ThrowError(hresult, strDescription, helpid);
}
else
{
if (m_nEventsFrozen == 0)
{
FireError(hresult, strDescription, helpid);
}
}
}
HRESULT CFirstCtrl::GetFileExceptionString(CFileException *cfEx,
UINT &uStr) const
{
HRESULT hr = S_OK;
uStr = IDS_FILEEXCEPTIONBASE + cfEx -> m_cause;
switch (cfEx -> m_cause)
{

www.books-shop.com

case CFileException::generic:
hr = CTL_E_ILLEGALFUNCTIONCALL;
break;
case CFileException::fileNotFound:
hr = CTL_E_FILENOTFOUND;
break;
case CFileException::badPath:
hr = CTL_E_PATHFILEACCESSERROR;
break;
case CFileException::tooManyOpenFiles:
hr = CTL_E_TOOMANYFILES;
break;
case CFileException::invalidFile:
hr = CTL_E_BADFILENAMEORNUMBER;
break;
case CFileException::directoryFull:
case CFileException::diskFull:
hr = CTL_E_DISKFULL;
break;
case CFileException::badSeek:
case CFileException::hardIO:
hr = CTL_E_DEVICEIOERROR;
break;
case CFileException::accessDenied:
case CFileException::removeCurrentDir:
case CFileException::sharingViolation:
case CFileException::lockViolation:
hr = CTL_E_PERMISSIONDENIED;
break;
case CFileException::endOfFile:
hr = CTL_E_BADRECORDLENGTH;
break;
default:
hr = CTL_E_ILLEGALFUNCTIONCALL;
uStr = IDS_UNKNOWNEXCEPTIONCAUSE;
break;
}

}
return hr;
void CFirstCtrl::CheckDatabase()
{
if (m_rsTable == 0)
{
throw new CFirstException(CFirstException::noRecordSet);
}
if (!m_rsTable -> IsOpen())
{
throw new CFirstException(CFirstException::dbClosed);
}
}
, ,
, .
. ,

www.books-shop.com

, ,
. ,
,
.
, m_rsTable,
CDbSet. , .
, try-.
new, () 0.
, ,
Open . Open ,
. CRecordset::snapshot
, ,
. ,
.
CRecordset::dynaset,
.
Open SQL-,
. SQL- SELECT * FROM HRESULTS WHERE HRESULT=?
. SQL, : ,
HRESULTS,
HRESULT ?. SQL,
( ) .
, 0, SELECT * FROM HRESULTS
WHERE HRESULT=0. HRESULT . ,
HRESULT. ,
.
Open , ,
catch-. ,
, CDBException ( MFC,
), .
,
m_strStatenativeOrigin CDBException. MFC ODBC,
!
, ,
. , ,
.
DoPropExchange ,
m_bInDispatch FALSE; .
Add. , Add
FindEntry , HRESULT .
. . Add
,
, . ,
m_rsTable , .
FindEntry, .
, AddNew,
. ,
, Add, Update.
, , , . .
, HRESULT
, CheckResult ,
HRESULT .

www.books-shop.com

BatchLoad.
ChackDatabase, , ,
. , CheckDatabase
CFirstException. CheckDatabase BatchLoad ,
,
. , , , DoBatchLoad.
Add, BatchLoad CheckHResult,
, HRESULT .
FindEntry .
m_rsTable, CheckDatabase,
HRESULT. Requery, SQL, , .
, .
IsBOF ,
, HRESULT .
, , .
GetInfo ,
. CheckDatabase.
, , GetInfo.

. GetInfo .
DoBatchLoad .

AddNew/ /Update. GetNextDefineLine
GetTheCode , , .
OnFreezeEvents , OnEventAdvise ,
FilesCreated.
( ClassWizard) .
CheckHResult ,
CDBException.
(, FindEntry), / (
ODBC) .
CheckDatabase , m_rsTable 0
( )
, .
ODBC
, .
, DoError . DoError
( CString)
ThrowError FireError. DoError
.
DoError , DoError
(
CDBException).

CFirstException , FIRSTEX.H FIRSTEX.CPP.


, . ,
. , ,
.

10.7

www.books-shop.com

Reset,
OnResetState. OnResetState
, , , DoPropExchange ,
( ,
,
). , DoPropExchange
m_bInDispatch.
, , ,
. Reset,
. ,
.

, .
, . .,
. ,
.

10.8
ActiveX? 16- COM-,
EXE-, . 32 32- Microsoft Windows NT
Windows 95.
, ActiveX ,
, DLL
. .
,
. ,
.
Build|Settings Microsoft Visual C++ 4.x.
Debug, General Executable For Debug Session
. ,
C:\MSDEV\BIN\TSTCON32.EXE. Go
.
,
.
. , . ,
, .
, ,
, (, ASSERT),
, .
, ,
, .

10.9
, , First.
, (
HResult). , (
).

www.books-shop.com

, ,
x, y z. ,
x, y z ( , ), ,
NewProp.
,
. ,
, , .
: (,
, ) , ,
?
DoPropExchange. , ,
ExchangeVersion HResult,
DoPropExchange .
. ExchangeVersion
. ,
, . ,
2.0 , 1.0, ,
.
, 1.0 2.0.
, ExchangeVersion (
, ,
). OLE ClassWizard
,
.
DoPropExchange.
, DoPropExchange 2.0 First
1.0, :

void CFirstCtrl::DoPropExchange(CPropExchange* pPX)


{
ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
COleControl::DoPropExchange(pPX);
PX_Long(pPX, _T("HResult"), m_HResult, 0);
if (pPX -> IsLoading())
{
ReallySetHResult(m_HResult);
}
// 2.0 ?
If (pPX -> GetVersion() >= MAKELONG(0, 2))
{
PX_Long(pPX, _T("NewProp"), 1234);
}
}

NewProp , 2.0 .
, . , 3.0
NewProp . Microsoft
(
, ), ,
, .
, MFC.
, .
, ,
.

www.books-shop.com

10.10
,
,
. .

, .
, ( ).
, ,
, , . ,

, .
-.
MFC .
Context Sensitive Help OLE ControlWizard ,
HLP, HLP- RTF (Rich
Text Format, ), HPJ
MAKEHELP. HPJ-
, Windows Help Compiler (HC31.EXE). MAKEHELP.BAT
, ,
(include) . MAKEHM.EXE
, Visual C++. MAKEHELP.BAT
. ,
(hooks).

Windows 95, Windows NT 3.51 ,


Windows 3.1.
HCW.EXE. ,
HC31, .
, , OLE ControlWizard,
HCW.

F1.
, ClassWizard WM_KEYDOWN
, , COleControl (
). ,
F1. ,
F1 CWinApp::WinHelp. :

void CConvolveCtrl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)


{
if (nChar == VK_F1)
{
AfxGetApp -> WinHelp(0, HELP_CONTENTS);
}
else
{
COleControl::OnKeyDown(nChar, nRepCnt, nFlags);
}
}
AfxGetApp - ,
CWinApp. WinHelp,
(contents) .
.
Shift+F1 ,

%RRNVVKRS

piracy@books-shop.com

.
, ,
AppWizard .
m_pszHelpFilePath -.
, ,
HLP.


.
, , !
, .

,
. (,
!), MFC OLE ControlWizard
.

www.books-shop.com

11


. :
,
?
, -
. ?
, .
, OLE ControlWizard
( ).
OLE Properties.
, OLE ControlWizard .
General .

OLE Properties .
, , , ,
. , Properties.
.

11.1 ?

. Internet,
. ,
, HTML-, , -
Web-.
, HTML- .
,
HTML-.
? , ,
. ,
.
, , :
, [ActiveX]
, .
, , ,
. [ActiveX]
. ,
[ActiveX],
.
.
( ). ,
, ,
. , - ;
-

www.books-shop.com

,
, .
,
( , -
).

, . ,
, ,

. Windows 95
Windows NT ,
. ,
, .
[ActiveX].
,
, . MFC
,
.
,
,
, ,
, , . ,
, ,
, , ,
, , , ,
, .
. ,
ATL 2.0, .
ActiveX
,
. , ActiveX
,
, DLL
.
,
,
. . 11-1
First (
CD-ROM, \CODE\CHAP11\FIRST).
,
. COM-.
,
.
( , ) ,
DLL- OLEPRO32.DLL.
Microsoft Windows 95
( ), MFC
,
. ,
,
.
Microsoft Visual C++ OLE Control Wizard ( MFC)
. ,
.
DDX DDV MFC,
,
. MFC
COlePropertyPage,

www.books-shop.com

ControlWizard Class Wizard -,


.

.11-1. First

11.2
.
, .
First
, HResult
.
, ,
. ,
.
. ,
, ? (
!)
HResult ,
. DDX
, .
( ), DDV MFC. HResult
:
1.


IDD_PROPPAGE_FIRST (label) &HResult: ( &
,
, H HResult ).
, TODO,
. .
2. .
3. ClassWizard Ctrl+W. MemberVariables
CFirstPropPage.
4. IDC_EDIT1,
. Add Variable.
5. , m_HResult.
6. , Category Value,
long.
7. OLE Property Name HResult.

www.books-shop.com

8.
9.

Add Member Variable ClassWizard,


OK.
.

, ! 3 4
Ctrl
, ClassWizard Add Member Variable
.
(, ,
,
Properties ), . 11-2.
HResult OK,
, ,
.

.11-2. First
Apply. (
) , .
Apply
Properties.

Automation,
HRESULT InvalidHResult.
, .
.

11.3
,
. ,
. ,
,
, (GUI)
-(HCI).

www.books-shop.com

, , .
.
, ,
. , (
, , Microsoft).
,
(, , ) .
, ,
.
?
, .
, .
. ,
,
. , ,
, . ,
.

.
, .
: ,
,
! ,
ActiveX. ,
, , ..
,
, .
25062
250100 . MFC
, ,
( ).
. ,
, ,
, , .
.
DDV- MFC
, OK Apply.
, .
, .
(,
),
, ,
. .
,
. -
, .
!

,
First , ,
,
HResult. ? ( )
. , .
, HResult,
.

www.books-shop.com

Edit
Properties. Disabled General, Read-Only
Styles.
, .
.
. 11-3 First (
).
.
, , , ,
.

.11-3. First ,

11.5
.
, (, .
) . ,
, .
,
(
!).
,
. :
1.

Insert|Resource
( IDD_OLE_PROPPAGE_LARGE IDD_OLE_PROPPAGE_SMALL).
, IDD_PROPPGE2_FIRST.
2. TODO ( ),
Delete.
3. Dialog Properties,
Properties . ,
Styles Child ( Style) None
( Border),
( Titlebar Visible).
4. ;
( IDD_OLE_PROPPAGE_LARGE IDD_OLE_PROPPAGE_SMALL
).
5. ClassWizard Ctrl+W.
6. Adding A Class MFC ClassWizard.
Create A New Class OK.

www.books-shop.com

7.
8.
9.
10.
11.
12.
13.
14.

15.

16.

Create New Class (, CMyPage2)


, COlePropertyPage.
Create, OK MFC ClassWizard.
( First
FIRSTCTL.CPP) BEGIN_PROPPAGEIDS.
. ,
, 1 2.
( ),
END_PROPPAGEIDS. :
PROPPAGEID(CMyPage2::guid).
ClassWizard DDX/DDV.
.
#include.
(, Page Two ) (,
IDS_PROPPGE2_FIRST_CAPTION). ,

0 COlePropertyPage ,
. ControlWizard
TODO. !
, . ,
ControlWizard First Property Page.
Firsts Second Property Page.

IDS_PROPPGE2_FIRST ( ,
MFC ). ,
AfxOleRegisterPropertyPageClass,
(0) ,
UpdateRegistry .

, :
CMyPage2::CMyPage2Factory::UpdateRegistry. ControlWizard
, .
.

! .
, ,
, , ,
, .

11.6
,
, .
, .
, .
, , First, ,
BackColor ForeColor OLE_COLOR, ,
.
,
, .
FIRSTCTL.CPP :

//////////////////////////////////////////////////////////////
//
// .
// !
BEGIN_PROPPAGEIDS(CFirstCtrl, 1)
PROPPAGEID(CFirstPropPage::guid)
END_PROPPAGEIDS(CFirstCtrl)

www.books-shop.com

:
1.
2.

BEGIN_PROPPAGEIDS.
. ,
:

PROPPAGEID(CLSID_CColorPropPage)
PROPPAGEID (
CLSID_CFontPropPage, CLSID_CPicturePropPage).

3.

,
. , ,
,
. MFC 4.0, Microsoft
, ,
.

. , ,
First, ForeColor BackColor.
,
. ,
OLE_COLOR.

11.7
.
COlePropertyPage::SetHelpInfo ,
COlePropertyPage. SetHelpInfo :

, ,
, .
.
,
. (
!) Help .
WinHelp .

,
.
, F1
WinHelp .

11.8 MFC
, MFC, ,
, . , ,

. ,
.

www.books-shop.com

11.9 ,

,
IPropertyPage IPropertyPage2 ( ).
, (
), .
OleCreatePropertyFrame OleCreatePropertyFrameIndirect.
IPropertyPage
.

SetPageSite

(),
IPropertyPageSite .

Activate

Deactivate

,
Activate.

GetPageInfo

,
.

SetObjects

,
. IUnknown,
. ,
, ,
n , n .
QueryInterface
,
( Automation).
, (-),
(-).

Show

Move

IsPageDirty

, (
). Apply.

Apply

,
(-), .

Help

, .

TranslateAccelerator

IPropertyPage2 ,
, dispid.
,
. ?
IPerPropertyBrowsing. ,
, IPropertyPage
IPerPropertyPage2.
. IPerPropertyBrowsing
( IUnknown): GetDisplayString, MapPropertyToPage, GetPredefinedStrings
GetPredefinedValue. ,
, . , MapPropertyToPage,
IPropertyPage2. CLSID -,
.
(, OleCreatePropertyFrameIndirect,
IPropertyPage::Activate),
IPropertyPage2::EditProperty.

%RRNVVKRS

piracy@books-shop.com

, GetPredefinedStrings GetPredefinedValue, ,
,
( TestProp ).
GetPredefinedStrings ,
( ),
. ,
GetPredefinedValue. ,
, 2 -
.

www.books-shop.com

12

ColeControl ColePropertyPage
MFC,
, ColeControl ColePropertyPage.
, ,
. , ,
.
MFC, ,
.


. , MFC 4.2,
( Microsoft Visual C++ 4.2). ,
MFC.
, .
!

, C++,
MFC. ATL ,
. MFC, ATL? ,
, ActiveX. ,
MFC ATL.
Internet, , ATL. ,
MFC ( , !), .

12.1 ColeControl
, ColeControl ActiveX,
MFC. CWnd
MFC. CWnd ,
ActiveX. COleControl ,
- CWnd. ? ActiveX
. ,
, ActiveX, ,
, ,
.

12.2 Automation ,
ColeControl
. Ambientxxx, xxx
.

www.books-shop.com

, .
( ),
. , GetAmbientProperty,
, (
). ,
, ,
.
,
, IOleControl::OnAmbientPropertyChange.
dispid DISPID_UNKNOWN (1),
. COleControl
OnAmbientPropertyChange.
, ,
, , COleControl.
, , .
OLEMISC_SETCLIENTSITEFIRST,
, -
. ,
. ,
,
COleControl::WillAmbientsBeValidDuringLoad. TRUE,
,
, FALSE .
FALSE, ,

.
.
; , Click
FireClick. Click.

FireEvent -
GetAmbientProperty. dispid ,
, . FireEvent
IDispatch::Invoke,
. , FireEvent
. IDE ,
, FireEvent.
, IDE
, FireEvent .
FireEvent COleDispatchDriver MFC ,
Automation.
()
Invoke. 12-1.
12-1. ColeControl ( MFC 4.2)

void COleControl::FireEventV(DISPID dispid, BYTE* pbParams,


va_list argList)
{
COleDispatchDriver driver;
POSITION pos = m_xEventConnPt.GetStartPosition();
LPDISPATCH pDispatch;
while (pos != NULL)
{
pDispatch = (LPDISPATCH)m_xEventConnPt.GetNextConnection(pos);
ASSERT(pDispatch != NULL);
driver.AttachDispatch(pDispatch, FALSE);
TRY

www.books-shop.com

driver.InvokeHelperV(dispid, DISPATCH_METHOD, VT_EMPTY,


NULL, pbParams, argList);
END_TRY
driver.DetachDispatch();
}
}
FireEventV dispid ,
va_list FireEvent, FireEventV (
va_list Microsoft Visual C++ Run-Time
Library Reference). FireEventV MFC COleDispatchDriver.
- ,
. FireEventV , IDispatch
.
, , Automation
.
, IDispatch,
IDispatch. ,
. ,
, ,
, .
COleDispatchDriver
AttachDispatch Invoke (
InvokeHelperV). InvokeHelperV VARIANT
IDispatch::Invoke. , ,
.
, .
COleCOntrol
. , GetText , SetText
Text Caption (
). InternalGetText
Text Caption . GetText ,
InternalGetText, BSTR
.
RequestEdit.
,
, COleControl::BoundPropertyRequestEdit.
( ,
), ,
COleControl::BoundPropertyChanged.

15, ,

.

MFC ,
. , .
InvalidateControl, ,
- .
OnTextChanged, Text Caption.
OnTextChanged ,
COleControl, .
.
- . ColeControl
.

www.books-shop.com

12.3
, C++, ,
. ? , ,
(,
printf).
printf ,
.
( ), . ,
printf .
printf ,
. , printf,
,
:

int IntPrintf (const char *pszFormat, int nNumber)


{
return printf(pszFormat, int nNumber)
}
C++.
COleControl::FireEvent, , ,
-. ?
,
( ,
).
C++ .

, .
,
-.
. MFC CArray CList.
ATL (ActiveX Template Library) .
( )
. ,
( )
. ,
, IOleControl::FreezeEvents TRUE.
FALSE , .

COleControl::OnFreezeEvents. ,
, , , ,
.
COleControl::OnEventAdvise,
. ,
, . ,
,
. OnEventAdvise
, (,
). , ,
OnFreezeEvents OnEventAdvise First ,
(
).
(, KeyDown),
OnKeyDownEvent,
. (/ ,
) ,
.

www.books-shop.com

12.4 Automation
9 . ActiveX
- Automation,
Automation, . COleControl
, . ,
, IDE .
IDE , ,
COleControl::SetNotSupported. Automation
ThrowError. ,
; GetNotSupported. ,
(
BoundPropertyRequestEdit). ,
, , ,
SetNotPermitted. ,

,
. SetNotPermitted ,
, ,
.
, ,
. ,
HRESULT.
ThrowError 9. :
- , .
,
.
ThrowError. ,
(, ODBC).

, , , .
? -,
, -,
.
ThrowError ,
.
COleDispatchExceptionEx.
MFC COleDispatchException ,
m_wCode HRESULT Automation.
Automation, : ,
.
ActiveX, Error, ,
. ,
,
FALSE. ,

COleControl::DisplayError ( , ).
,
.
, .

12.5 ,
COleControl ,
.
, ExchangeExtent ExchangeStockProps
DoPropExchange, OLE ControlWizard.
DoPropExchange ( ,
), ExchangeExtent
ExchangeStockProps ,

www.books-shop.com

. ( ) ,
.
.


, - ( )
, ExchangeStockProps. ,
, .

, , ExchangeVersion.
,
. ,
, ExchangeVersion ,
,
.
( - ,
,
) , SetModifiedFlag.
, IsModified TRUE
,
.
COleControl. ,
WillAmbientsBeValidDuringLoad, ,
,
. OLEMISC_SETCLIENTSITEFIRST
, .
, IOleObject::SetClientSite ,
.
OnSetClientSite. , -
.
, IsConvertingVBX,
. TRUE, ,
VBX- . , VBX,
Visual Basic, ActiveX,
. Microsoft Visual
Basic 4.0 ActiveX VBX, Visual
Basic. , Visual Basic,
VBX, , ActiveX.
VBX ActiveX,
VBX , ActiveX.
ActiveX VBX Font,
ActiveX .
Visual Basic (.FRM) . VBX
, FontSize, FontName FontItalic.
,
DoPropExchange, .
, COleControl::Serialize
. Serialize DoPropExchange.
Serialize,
SerializeExtent, SerializeStockProps SerializeVersion.
CArchive ,
.

12.6 , ActiveX

www.books-shop.com

, Automation
, , , COleControl
, ActiveX. ,
SetControlSize IOleObject::SetExtent,
. GetControlSize
ActiveX, SetControlSize
. SetRectInContainer
, ,
. GetRectInContainer
.
ControlInfoChanged
().
IOleControl::GetControlInfo . ,
, OnGetControlInfo COleControl.
,
GetExtendedControl, Automation
. ,

.
, (,
) .
LockInPlaceActive TRUE, ,
.
LockInPlaceActive FALSE,

. PreModalDialog
PostModalDialog.
, ,
. ,
, .
, (,
!).
UI- ,
(OLEIVERB_PRIMARY), OLEIVERB_UIACTIVATE. ,
UI-, OnEdit.
, OLE,
, ON_OLEVERB.
,
. ,
COleControl::OnEnumVerbs (, ,
).
, OnDraw.
( , Microsoft
Access 2.0 ), ,
Windows. OnDrawMetafile.
OnDrawMetafile OnDraw. OnDraw, OLE
ControlWizard, ! , ,
.
OnDraw - , , ,
OnDrawMetafile
.
, ,
Windows ,
(combo box). , ( , Windows
3.x) , .
.
,
WM_PAINT ,
InvalidateControl. , ,
.

www.books-shop.com

,
. InvalidateControl
Windows API InvalidateRect ( CWnd),
Windows API , . ?
,
( ) .
,
InvalidateControl,
IAdviseSink::OnViewChange. InvalidateRect
.
, ,
. OnResetState,
OLE ControlWizard . ,
. ,
DoPropExchange .
, , .
Visual C++ Books Online ,
MFC.

12.7 OCX 96 ActiveX COleControl


COleControl , OCX 96
ActiveX. , ,

.
GetFocus SetFocus
.
, GetCapture SetCapture
, . ReleaseCapture
. GetDC ReleaseDC DC
,
. ClientToParent
ParentToClient
, . GetClientOffset
.
, , . .
ClipCaretRect , ( )
. GetWindowlessDropTarget
drag-and-drop.
OnWindowlessMessage Windows (
).
, Windows.
Windows
, HWND,
. , ScrollWindow
.
COleControl
GetActivationPolicy, (
). , OnInactiveMouseMove OnInactiveSetCursor,

.
IsOptimizedDraw ,
OCX 96. ,
, DC
, .
COleControl ,
ReadyState .

www.books-shop.com

FireReadyStateChange ReadyStateChange, ;
, ReadyState.
GetReadyState . InternalSetReadyState
ReadyStateChange.
Load ,
URL.
, IViewObject
. IViewObject
. , - ,
, -!
OnGetNaturalExtent, OnGetViewExtent, OnGetViewRect, OnGetViewStatus,
OnQueryHitPoint OnQueryHitRect. OnGetViewExtent
, ,
. OnGetViewStatus.
OnQueryHitPoint ,
, ,
. ,
. ,
. , OnQueryHitRect ,
.

12.8 ColePropertyPage
- MFC , COlePropertyPage,
CDialog MFC.
CWnd, CDialog. , COlePropertyPage
, COleControl, ,
. MFC 4.0, CWnd
ActiveX, , MFC ActiveX,
, ( )!
,
ActiveX, ,
COlePropertyPage COleControl.
OLE ControlWizard
, , COlePropertyPage.
COlePropertyPage
Windows. COlePropertyPage, CDialog,
OnInitDialog, ,
. -
,
.
COlePropertyPage ,

SetDialogResource.
.
, COlePropertyPage ,
, .
SetPageName, ,
. SetPageName,
,
.
,
.
COlePropertyPage SetHelpInfo : ,
,
, .
, ,
( , ),
-
. , OnHelp, ,

%RRNVVKRS

piracy@books-shop.com

(, Help).
, ,
.
,
(. ), IPropertyPage IPropertyPage2.
,
IPropertyPage::SetPageSite. ActiveX,
.
COlePropertyPage OnSetPageSite.
, .
GetPageSite,
IPropertyPageSite . IPropertyPage2
IPropertyPage, , IPropertyPage2
.
COlePropertyPage OnEditProperty.

OnEditProperty ,
, dispid . .
11, .

.
(,
Visual Basic) ,
. .
, .
IDispatch.
GetObjectArray COlePropertyPage. Release ,
AddRef!
,
, SetModifiedFlag.
IsModified ( COleControl).
,
. , .
GetControlStatus SetControlStatus.
Apply,
, . Apply
. ,
Apply,
IgnoreApply.
Apply .

13
www.books-shop.com

ActiveX
ActiveX Internet
- OLE ,
Microsoft Visual Basic, Microsoft Visual C++, Microsoft Visual FoxPro, Microsoft Access.
. OLE ActiveX. ,
, , ActiveX
Microsoft World Wide Web
, .
( , Microsoft!) Internet 1995
. Microsoft ,
OLE ,
,
. , OLE
,
,
Web, Internet .
:
, , ,
Web-!
OCX 96. ,
. , ,
Web, , OLE
Web- ?
,
, -? ,
.
Microsoft ,
Sweeper,
COM ( ) ActiveX.
ActiveX, Web-
, Internet-, URL,
, ().
, , Microsoft
Internet Explorer 3.0, Microsoft Win32 Intel-
1996 . Microsoft Internet Explorer 4.0,
Windows
.
Microsoft 1996
Internet
.
, , Internet .
, Web. Web
1995 , , Internet Explorer 1.0.
. Web ,
. Web
,
Web. ,
. ,
,
. , 1996
, NBC . ,
,
Web- BBC
. , RealAudio
, .

www.books-shop.com

Web , .
, Java ActiveX? Microsoft
, , Java
ActiveX . Microsoft
(VM) Java COM. , Java
: Java
-
(, Java
, C, Microsoft
COM-, ),
, Java VM .
ActiveX ,
,
Win32 Intel, Macintosh . .
Web-,
. ?
Internet- , ,
, . (
Internet-) , .
, :

Web- HTML- <OBJECT>;


<PARAM>;
;
Web- ;
, Web, :

, Web-.
, Web (
(frames) ). ,
, HTTP, HTML
. Web , Internet
World Wide Web. ? Internet
, . Internet
TCP/IP. , ,
-
TCP/IP Internet. , World Wide Web ,
HTML ( Hypertext Markup Language),
Internet HTTP (
Hypertext Transfer Protocol), TCP/IP. Web,
, - , ,
Internet,

. c
Web-, ,
Web .
, HTML- Internet. ,
HTTP- ( , HTTP HTML-)
Web .
. Microsoft ,
,
.
. ,

(, ). ,

www.books-shop.com


Windows.
, ,
, .
, .
HTML-
.
, Microsoft ActiveX
. ActiveX
, .
OLE ,
,
-,
OLE. ?
ActiveX ( Internet Explorer 3.0 ), Web HTML
Microsoft Word, Microsoft PowerPoint . . ,
, ,
. ,
HTML-,
(, Word). ,
-? Microsoft ActiveX. Web,
( !) .
, Internet
Web. , World Wide Web, W3C,
HTML (
, . .). Internet (IETF)
Internet (, ).

13.1 ActiveX Web-


Web- .
.
. ,
, .
, Web- .

13.2 Web-
Web- . W3C <OBJECT> ,
HTML- ,
ActiveX. . ,
First ,
:

<OBJECT
CLASSID="clsid:14BC5F80-DBD2-11CD-92B4-08002B291EED"
ID=hresultcontrol
>
</OBJECT>
CLSID
( hresultcontrol).
HTML-,
Internet Explorer, . 13-1.

www.books-shop.com

13-1. First HTML-


, , .
- , Internet Explorer .
, , Internet Explorer
HTML- (
). , Internet Explorer View|Options
Security. Active Content
Safety Level. , . 13-2.

.13-2. Safety Level Internet Explorer 3.0


.
High. Internet Explorer
. , Medium. Internet Explorer
,
. ,
, .
, None, . ,
( , )
. , ,
. ,
, .

www.books-shop.com

Medium, Internet Explorer ,


First ( ID: hresultcontrol)
. . 13-3. Yes
Yes To All, .

.13-3. Internet Explorer 3.0


. , CLSID <OBJECT>
. , , , W3C
ProgID ( ) CLSID.
, . ,
. <OBJECT> WIDTH
HEIGHT:

<OBJECT
CLASSID="clsid:14BC5F80-DBD2-11CD-92B4-08002B291EED"
ID=hresultcontrol
WIDTH=500
HEIGHT=60
>
</OBJECT>
WIDTH HEIGHT . , ALIGN

, ALIGN
. HTML
, HTML 3.2
- ( ,
).
. Internet Explorer
HTML-, CLSID, ? ,
.
( ), .
, ,
HTML-. - ,
. , ,
, .
, <OBJECT> CODEBASE,
, ( URL
HTTP ).
CODEBASE:

<OBJECT

www.books-shop.com

CLASSID="clsid:14BC5F80-DBD2-11CD-92B4-08002B291EED"
ID=hresultcontrol
CODEBASE="http://www.somewhere.com/controls/first.ocx"
WIDTH=500
HEIGHT=60
>
</OBJECT>
<OBJECT> (, ),
ActiveX. HTML ActiveX
SDK ( CD-ROM).
.

13.3
. .
, ,
. -,
,
(
), ,
, .
Web- ,
. Internet Explorer <OBJECT>,
,
. (
), PARAM <OBJECT>:

<OBJECT
CLASSID="clsid:14BC5F80-DBD2-11CD-92B4-08002B291EED"
ID=hresultcontrol
WIDTH=500
HEIGHT=60
>
<PARAM NAME="HResult" VALUE=123>
<PARAM NAME="BackColor" VALUE=255>
</OBJECT>
HResult BackColor
( 255 BackColor
).
, ,
, :
IPersistPropertyBag. Internet Explorer 3.0 PARAM <OBJECT>
IPersistPropertyBag .

13.4
PARAM <OBJECT>
Web-, .
? ? Web URL, ,
. ?
, Web- ,
. - - ActiveX SDK
,
API, (Open Stream
functions):

www.books-shop.com

URLDownloadToCacheFile URL, -,
Internet- ActiveX, -;
URLDownloadToFile URL ;
URLOpenStream URL (IStream);
URLOpenBlockingStream URLOpenStream,
, (
);
URLOpenPullStream URLOpenBlockingStream,
, .

, (
URLOpenBlockingStream), , , ,
.
IBindStatusCallback, 3.
IBindStatusCallback ,
,
- .
IStream, .
IBindStatusCallback (
IUnknown), . IUnknown,
:

GetBindInfo , (,
).
OnStartBinding
IBinding. ,
, AddRef IBinding.
GetPriority (,
). ,
S_OK E_UNIMPL.
OnProgress
. ,
, , S_OK E_UNIMPL.
OnDataAvailable ,
.
OnObjectAvailable BindToObject
BindToStorage.
OnLowResources ,
. ,
, , S_OK E_UNIMPL.
OnStopBinding ,
, .

,
. ,
, . ,
MFC ,
. ,
ReadyState
ReadyStateChanged. MFC .

13.5 Web-
ActiveX Web- ,
. Web- C++,
, ++
.
,
. ,
ActiveX, ,
.

www.books-shop.com

Internet Explorer 3.0 ,


ActiveX Microsoft Visual Basic Scripting Edition (VBScript, Visual Basic) JScript (
JavaScript). VBScript , Visual Basic.
Visual Basic.
VBScript VARIANT. VBScript
COM- , Automation
( ,
IDispatch::Invoke). VBScript
Invoke (,
, ).

VBScript 1.0.
.

, VBScript . Web-
<OBJECT> (. ). ,
. ,

(, , , . .).
. ,
HResult First,
hresultcontrol ID <OBJECT>, :

hresultcontrol.HResult = 123
, . ,
, . VBScript
. , ,
Sub ( void Visual
Basic). ,
. , (
, VBScript VARIANT). ,
InvalidHResult First :

Sub hresultcontrol_InvalidHResult(HResult)
Rem - HResult
End Sub
. ,
First, InvalidHResult.
, HResult.
:

<HTML>
<BODY>
<OBJECT
CLASSID="clsid:14BC5F80-DBD2-11CD-92B4-08002B291EED"
ID=hresultcontrol
WIDTH=500
HEIGHT=60
>
<PARAM NAME="HResult" VALUE=-2>
<PARAM NAME="BackColor" VALUE=255>
</OBJECT>
<INPUT TYPE=BUTTON VALUE="Set HResult" NAME="BTNSetHResult"
</BODY>

www.books-shop.com

<SCRIPT LANGUAGE=VBScript>
Sub BtnSetHResult_OnClick
hresultcontrol.BackColor=&hff0000
hresultcontrol.HResult=hresultcontrol.HResult+1
End Sub
Sub hresultcontrol_InvalidHResult(HResult)
alert "Invalid HRESULT Entered:" & HResult
End Sub
</SCRIPT>
</HTML>
First
hresultcontrol HResult 2 ( !),
. HTML
BtnSetHResult Set HResult.
Sub VBScript BtnSetHResult_OnClick. .
(
Visual Basic ),
HResult 1.
Sub hresultcontrol, , ,
, hresultcontrol InvalidHResult.
, HResult. Alert ,
HResult.
HTML- Internet Explorer 3.0,
. 2 ( , )
, . ,
PARAM .
HResult,
( ) HResult 1,
.
, VBScript, ,
. ,
!
JScript? ActiveX ,
. JScript .
. ,
- . ,
ActiveX,
Web- . ,
, .

13.6 ,
Web
,
Web-. , Web
,
, .

13.7
3 COM.
HTML-
, . ,
15. , Web , .

%RRNVVKRS

piracy@books-shop.com

13.8 ,

Web- .
, - ,
( ) , .
Web.
, ,
. Internet Explorer 3.0
, ,
. ?
. , ,
, ( ),
. ,
.
:

, X, ,
X;
, .

, .
(
). , ,
. , Microsoft, IBM
Novell, , , ,
? , Web,
.
, ? Microsoft,
Authenticode,
. ,
Autheticode ,
.
,
, RSA. .
, .
.
. , , ,
.
.
, .

.
?
MakeCert,
. MakeCert :

;
;
.

MakeCert ,
.
, .
ActiveX SDK CD-ROM.

www.books-shop.com

SPC ( Software
Publisher Certificate), X.509.
; SPC
. SPC
Cert2SPC.
, . SignCode,
:

;
;
(-) X.509 SPC;
(-) (-)
;
.

? ,


.
PeSigMgr ( !) ,
SignCode . ChkTrust
Internet Explorer , ,
, .
EXE- ,
ActiveX (OCX DLL) Java. Internet,
,
Internet Explorer ,
. ,
ActiveX SDK CD-ROM.
,
. , .
, .

. , ActiveX ,
Win32 API. - Microsoft ,
.
Automation ,
.
, .
(. ) Controls that are safely
scriptable IObjectSafety.
, (
) .
.
.
( PARAM <OBJECT>)
URL ( ), ,
.
, . ,
,
, (Controls safely initializable from
persistent storage) IObjectSafety. Internet Explorer
, .

www.books-shop.com

, - . ,
, .

IObjectSafety . IUnknown,
GetInterfaceSafetyOptions SetInterfaceSafetyOptions.

. IID. ,
, .
: INTERFACESAFE_FOR_UNTRUSTED_DATA
INTERFACESAFE_FOR_UNTRUSTED_CALLER.

13.9
, , IUnknown.

(, , ). ,

IUnknown::QueryInterface,
,
,
.
, COM ,
.
, ,
, .
,
.
,
,
, ( REG). COM
API ,
.
,
Web-? ,
, . - ,
.
. , .
, , Web- ( , ),
(
). , COM- (,
Insert Object)
.
CLSID,
.
,
,
. , Insertable
(, ,
). ,
, . ,
, , ,
, .
,
(,
ISimpleFrameSite), :

www.books-shop.com


( )
( );
,
( ),
.
, .
First ,
HRESULT.

? GUID,
CATID. CATID Component Categories
HKEY_CLASSES_ROOT. , ,
Description,
( ,
). CLSID
Implemented Categories, CATID ,
. , Required Categories, CATID ,
.
,
, .
. ,
,
.
,
( ,
- ).
,
.
(
CLSID_StdComponentCategoriesManager CoCreateInstance) ,
ICatInformation ICatRegister.
ICatInformation ,
. , IUnknown:

EnumCategories IEnumCATEGORYINFO,
, .
,
.
GetCategoryDesc ,
;
EnumClassesOfCategories IEnumCLSID,
CLSID ,
;
IsClassOfCategories , . ,
, ;
EnumImplCategoriesOFClass IEnumCATID,
, ;
EnumReqCategoriesOfClass IEnumCATID,
, .

ICatRegister /
. , IUnknown:

RegisterCategories ,
;
UnRegisterCategories ;
RegisterClassImplCategories CLSID.
,
CLSID;

www.books-shop.com

UnRegisterClassImplCategories ,
;
RegisterClassReqCategories CLSID.
,
CLSID;
UnRegisterClassReqCategories ,
.

.
, Internet Explorer
Controls safely initializable from persistent storage Controls that are
safely scriptable.

13.10
, , .
, COM, COM.
: ,
.
Internet Explorer 3.0 ()
ActiveX . Internet Explorer 4.0,
Microsoft
.
. ATL
MFC 4.2 ( ATL ,
). MFC ,
.
: ,
. , .
, ,
, . ,

.
, ,
. MFC ,
. ATL
. , ,
( , ).
, ,
.

13.11
. Web ,
. Web-, ,
, . ,
. .
DLL-,
, .
, Web C++
MFC BaseCtl ( runtime C ), , Visual Basic.
, -
runtime- (, Windows 95 DLL- MFC 3.2, Internet
Explorer MFC 4.1), , .
DLL- , .

www.books-shop.com

, ATL, DLL-
(
ATL). ,
. (
), ATL
C++ , Web.

13.12
, , , ActiveX
? ,
Internet Explorer, ? ,
CODEBASE
<OBJECT>, Internet Explorer .
.
, Internet Explorer ( Microsoft
ActiveX SDK), Internet Component Download.
:

(Win32) EXE- , DLL OCX-. ,


, ,
HTTP- .
, EXE- EXE-,
. ,
, .
,
( ),
EXE- .
CAB-. CAB-
Windows 95, Internet Explorer . Diamond,
ActiveX SDK. ,
HTTP-. CAB-
INF-,
Windows 95/Windows NT 4.x. CAB- DLL-.
, INF-
, CAB- URL.
INF-. INF- URL,
. ,
.

, EXE- DLL-, ,
INF- ,
. DLL OCX
DllRegisterServer; EXE- /RegServer.
CODEBASE ,
, . ,
. 1, 1,
1, 1 ,
, . ,
Internet (Internet Search Path),
URL. Internet
(HKEY_LOCAL_
MACHINE\Software\Microsoft\Windows\CurrentVersion\InternetSettings\CodeBaseSearchPath)
URL, (;). URL (
) CODEBASE,
URL, CODEBASE <OBJECT> .
CODEBASE , URL
,
.

www.books-shop.com


, . INF-,
( ,
Windows 95 Windows NT 4.x). ActiveX SDK.
HTTP ,
, .
ActiveX SDK.
HTTP-,
HTTP- ( Microsoft Internet Information Server),
.

13.13 ActiveX Control Pad HTML Layout Control


, HTML
. ,
,
, .
HTML-,
, , .
W3C HTML (,
) Microsoft ActiveX
Control Pad HTML Layout Control. ( ,
) Internet Studio.
, .
ActiveX Control Pad HTML Layout Control Web- Microsoft
(http://www.microsoft.com). HTML Layout Control ,
ActiveX Control Pad . ActiveX Control
Pad HTML-,
:

ActiveX HTML-;
VBScript JScript HTML;
HTML-.

, , . Control Pad
HTML-. HTML Control Pad
WYSIWIG ( , ) HTML. ,
HTML- ActiveX.
,
CODEBASE, .
. ,
Control Pad, . ,
<OBJECT> HTML-.
PARAM
,
PARAM.
HTML-
Script Wizard. , .
, ,
(, ,
, ).
, ,
. ,
Control Pad First,
InvalidHResult. , , ,
.
.
,
. , ActiveX.
HTML-, ()

www.books-shop.com

. ,
( ).
,
Microsoft Office 97. ,
OCX 96.
OCX 96 , z- (
) .

. , ,
OCX 96. ActiveX. ,
,
.
, , ,
, z-
( ,
). ( ALX
, HTML). ALX- <OBJECT>
. HTML .
, Script Wizard
, . ,
ALX- .
. 13-4 , HTML-:

<HTML>
<HEAD><TITLE>New page</TITLE>
</HEAD>
<BODY>
<OBJECT ID="First1" WIDTH=479 HEIGHT=51"
CLASSID="14BC5F80-DBD2-11CD-92B4-08002B291EED">
<PARAM NAME="_Version" VALUE="65536")
<PARAM NAME="_ExtentX" VALUE="12642")
<PARAM NAME="_ExtentY" VALUE="1323")
<PARAM NAME="_StockProps" VALUE="79")
<PARAM NAME="Caption" VALUE="ERROR_SUCCESS: The operation
completed successfully.">
<PARAM NAME="ForeColor" VALUE="65535")
<PARAM NAME="BackColor" VALUE="16384")
</OBJECT>
<OBJECT CLASSID="CLSID:812AE312-8B8E-11CF-93C8-00AA00C08FDF"
ID="lyt1_alx" STYLE="LEFT:0,TOP:0">
<PARAM NAME="ALXPATH" REF VALUE="file:C:\lyt1.alx">
</OBJECT>
</BODY>
</HTML>
ALX-, HTML (C:\LYT1.ALX),
:

<SCRIPT LANGUAGE="VBScript">
<!
Sub CommandButton1_Click()
call CommandButton1.ZOrder(1)
Label1.Caption = "Now that youve pressed the button,
Im coming forward"
end sub
>
</SCRIPT>

www.books-shop.com

<DIV ID="lyt1" STYLE="LAYOUT:FIXED;WIDTH:400pt;HEIGHT:300pt;">


<OBJECT ID="Label1"
CLASSID="CLSID:978C9E23-D4B0-11CE-BF2D-00AA003F40D0"
STYLE="TOP:0pt;LEFT:0pt;WIDTH:66pt;HEIGHT:107pt;ZINDEX:0;">
<PARAM NAME="BackColor" VALUE="4210688">
<PARAM NAME="VariousPropertyBits" VALUE="8388627">
<PARAM NAME="Caption" VALUE="This is a label control, which,
because its also windowless, Im going to send to the back
of the button with which it overlaps">
<PARAM NAME="Size" VALUE="2328;3775">
<PARAM NAME="FontEffects" VALUE="1073741827">
<PARAM NAME="FontCharSet" VALUE="0">
<PARAM NAME="FontPitchAndFamily" VALUE="2">
<PARAM NAME="FontWeight" VALUE="700">
</OBJECT>
<OBJECT ID="CommandButton1"
CLASSID="CLSID:D7053240-CE69-11CD-A777-00DD01143C57"
STYLE="TOP:33pt;LEFT:25pt;WIDTH:83pt;HEIGHT:25pt;TABINDEX:0;
ZINDEX:1;">
<PARAM NAME="Caption" VALUE="My First Button">
<PARAM NAME="Size" VALUE="2928;882">
<PARAM NAME="FontCharSet" VALUE="0">
<PARAM NAME="FontPitchAndFamily" VALUE="2">
<PARAM NAME="ParagraphAlign" VALUE="3">
<PARAM NAME="FontWeight" VALUE="0">
</OBJECT>
</DIV>

.13-4. First , ActiveX Control Pad, Internet Explorer 3.0


, (
) .
z- . ,
.
ActiveX Control Pad HTML-
ActiveX. .
Internet Studio ( , !)
ActiveX.
W3C
HTML-.

www.books-shop.com

14


. 13
, Font.
,
, ,
. ,
? ,
, .


. , Automation COM ,
Automation.
.
IFontDispatch, IDispatch, IFont. ,
,
,
. , ,
. First ,
. ,
, ,
ActiveX. Children.

,
( . ,
).


, ,
. .

14.1 Children
Children .
, ,
, . ,
,
. ,
, ,
EditFont. , Children
, ActiveX.
ActiveX . . 14-1
Children .
%RRNVVKRS

piracy@books-shop.com

.14-1. Children
OLE ControlWizard ,
Children. ( ,

). , EditFont
/ LPFONTDISP ( IFontDisp).
, BeforeValidation Validated, .
, .
,
. , : BackColor, Font
ForeColor. -
EditFont. MFC CEdit CButton.

(Overrides):

virtual void OnFontChanged();


,
. (Implementation)
:

CButton m_btnValidate;
CEdit m_editEntry;
CRect m_rBtn;
CRect m_rEdit;
CFontHolder m_fontEdit;
void ChangeEditFont();
,
. CRect .
CFontHolder EditFont. ChangeEditFont
EditFont, ,
.

//}}AFX_MSG
:

afx_msg void OnValidate();

www.books-shop.com

BN_CLICKED.
MessageMaps ClassWizard , COleControl,
WM_CREATE. , , ,
:

#define
#define

IDC_VALIDATE
IDC_ENTRY

1
2

.
, .
(ClassWizard ),
IDE.

ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
:

ON_BN_CLICKED(IDC_VALIDATE, OnValidate)
MFC , BN_CLICKED
IDC_VALIDATE OnValidate.
.
, , :

BEGIN_PROPPAGEIDS(CChildrenCtrl, 3);
PROPPAGEID(CChildrenPropPage::guid)
PROPPAGEID(CLSID_CColorPropPage)
PROPPAGEID(CLSID_CFontPropPage)
END_PROPPAGEIDS(CChildrenCtrl)

, :

static const FONTDESC _fontdescEdit =


{ sizeof(FONTDESC), L"Arial", FONTSIZE(10), FW_NORMAL,
ANSI_CHARSET, FALSE, FALSE, FALSE };
Arial 10 ,
(
, ).
CRect
( , -
), SetInitialSize,
. ,
. SetInitialSize
( ) 6 ,
, .

CChildrenCtrl::CChildrenCtrl() : m_fontEdit(&m_xFontNotificatioN)
{
InitializeIIDs(&IID_DChildren, &IID_DChildrenEvents);
m_rBtn = CRect(3, 3, 103, 27);
m_rEdit = CRect(3, 30, 103, 60);
SetInitialSize(m_rBtn.right + m_rBtn.left,
m_rEdit.bottom + m_rBtn.top);
}
, CFontHolder
&m_xFontNotification.

www.books-shop.com

OnDraw ,
, .

void CChildrenCtrl::OnDraw(CDC* pdc, const CRect& rcBounds,


const CRect& rcInvalid)
{
CBrush cbBack(TranslateColor(GetBackColor()));
pdc -> FillRect(rcBounds, &cbBack);
}
DoPropExchange
EditFont.
. 445> ChangeEditFont,
. DoPropExhange :

void CChildrenCtrl::DoPropExchange(CPropExchange* pPX)


{
ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
COleControl::DoPropExchange(pPX);
PX_Font(pPX, _T("EditFont"), m_fontEdit, &_fontdescEdit);
if (pPX -> IsLoading())
{
ChangeEditFont();
}
}
,
CFontHolder,
. CFontHolder -,
Automation MFC-.
C++ (, Java)
.
ActiveX
. WM_CREATE,
, . - :

int CChildrenCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)


{
if (COleControl::OnCreate(lpCreateStruct) == -1)
return -1;
if (m_btnValidate.Create(_T("&Validate"),
BS_PUSHBUTTON |
WS_VISIBLE, m_rBtn, this, IDC_VALIDATE) == FALSE)
{
MessageBox(_T("Could not create pushbutton"));
return -1;
}
if (m_editEntry.Create(ES_AUTOHSCROLL |
WS_BORDER | WS_VISIBLE, m_rEdit, this, IDC_ENTRY) == FALSE)
{
MessageBox(_T("Could not create edit box"));
return -1;
}
return 0;
}
WM_CREATE ,
, .
Validate IDC_VALIDATE. ,
BS_PUSHBUTTON. ,
. , ,
WS_BORDER .

www.books-shop.com

ON_BN_CLICKED
IDC_VALIDATE, OnValidate:

void CChildrenCtrl::OnValidate()
{
FireBeforeValidation();
MessageBox(_T("Pushbutton Pressed"));
FireValidated();
}
. ,
(
Children, , ).
EditFont :

LPFONTDISP CChildrenCtrl::GetEditFont()
{
return m_fontEdit.GetFontDispatch();
}
void CChildrenCtrl::SetEditFont(LPFONTDISP newValue)
{
m_fontEdit.InitializeFont(&_fontdescEdit, newValue);
ChangeEditFont();
SetModifiedFlag();
}
CFontHolder,
.
, ,
. ,
SetModifiedFlag, .

COleControl::OnFontChanged.
.

EditFont ( !) :

void CChildrenCtrl::OnFontChanged()
{
ChangeEditFont();
COleControl::OnFontChanged();
}
. ,
,
. ?
.
, ChangeEditFont:

void CChildrenCtrl::ChangeEditFont()
{
if (m_editEntry.GetSafeHwnd())
{
m_editEntry.SendMessage(WM_SETFONT,
(WPARAM)m_fontEdit.GetFontHandle(), TRUE);
}
}

CWnd::GetSafeHwnd. , NULL,
. ,

www.books-shop.com

WM_SETFONT HFONT,
CFontHolder.
. . 14-2 , ,
.

.14-2. Children EditFont

14.2
OnFontChanged
EditFont
? , .
( )

, .
CFontHolder IPropertyNotifySink,
. ,
&m_xFontNotification CChildrenCtrl. CFontHolder

. ,
, IPropertyNotifySink,
OnFontChanged. ,
, .
, ,

OnFontChanged . !

Children CD-ROM, \CODE\CHAP14\CHILDREN.

,
. ,

www.books-shop.com

.
MFC .

14.3

IPropertyNotifySink ,
EditFont.
Children ,
Implementation .
, EditFontNotify.

BEGIN_INTERFACE_PART(EditFontNotify, IPropertyNotifySink)
INIT_INTERFACE_PART(CChildrenCtrl, EditFontNotify)
STDMETHOD(OnRequestEdit)(DISPID);
STDMETHOD(OnChanged)(DISPID);
END_INTERFACE_PART(EditFontNotify)
IUnknown, ,
DISPID HRESULT. OnRequestEdit
, ,
. OnChanged ,
.

STDMETHODIMP_(ULONG) CChildrenCtrl::XEditFontNotify::AddRef()
{
METHOD_MANAGE_STATE(CChildrenCtrl, EditFontNotify)
return 1;
}
STDMETHODIMP_(ULONG) CChildrenCtrl::XEditFontNotify::Release()
{
METHOD_MANAGE_STATE(CChildrenCtrl, EditFontNotify)
return 0;
}
STDMETHODIMP CChildrenCtrl::XEditFontNotify::QueryInterface(
REFIID iid, LPVOID *ppvObj)
{
METHOD_MANAGE_STATE(CChildrenCtrl, EditFontNotify)
if (IsEqualIID(iid, IID_IUnknown) ||
IsEqualIID(iid, IID_IPropertyNotifySink))
{
*ppvObj = this;
AddRef();
return NOERROR;
}
return ResultFromScode(E_NOINTERFACE);
}
STDMETHODIMP CChildrenCtrl::XEditFontNotify::OnChanged(DISPID)
{
METHOD_MANAGE_STATE(CChildrenCtrl, EditFontNotify)
pThis -> ChangeEditFont();
return NOERROR;
}
STDMETHODIMP CChildrenCtrl::XEditFontNotify::OnRequestEdit(DISPID)
{
return NOERROR;
}

www.books-shop.com

METHOD_MANAGE_STATE,
. MFC DLL- .
, (,
) . ,
C++ new.
, , new MFC
. , MFC, new
NULL ( C++).
,
new. ActiveX NULL,
, ,
NULL. , .
, NULL new,
ActiveX ,
. Microsoft Visual C++ 2.x new
, () .
IPropertyNotifySink . OnRequestEdit
, OnChanged ChangeEditFont. .
,
, ,
. ? , ,
( , ) ,
. ,
. ,
ChangeEditFont .
, , CWnd::Create
. CEdit::Create. ,
OnCreate ActiveX :

int CChildrenCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)


{
if (COleControl::OnCreate(lpCreateStruct) == -1)
return -1;
if (m_btnValidate.Create(_T("&Validate"), BS_PUSHBUTTON |
WS_VISIBLE, m_rBtn, this, IDC_VALIDATE) == FALSE)
{
MessageBox(_T("Could not create button"));
return -1;
}
if (m_editEntry.Create(ES_AUTOHSCROLL |
WS_BORDER | WS_VISIBLE, m_rEdit, this, IDC_ENTRY) == FALSE)
{
MessageBox(_T("Could not create edit box"));
return -1;
}
ChangeEditFont();
return 0;
}
,
.

14.4
- , -
. ,
.
, .
.
EditText, /

www.books-shop.com

, (BSTR). ,
,
. Microsoft Visual Basic :

Children1 = "Assigning to Children1.EditText"


, :

Children1.EditText = "Assigning to Children1.EditText"


/ :

BSTR CChildrenCtrl::GetEditText()
{
if (m_editEntry.GetSafeHwnd())
{
CString s;
m_editEntry.GetWindowText(s);
return s.AllocSysString();
}
else
{
ThrowError(CTL_E_ILLEGALFUNCTIONCALL, IDS_NOEDITCTRL);
return NULL;
}
}
void CChildrenCtrl::SetEditText(LPCTSTR lpszNewValue)
{
if (m_editEntry.GetSafeHwnd())
{
m_editEntry.SetWindowText(lpszNewValue);
SetModifiedFlag();
}
else
{
ThrowError(CTL_E_ILLEGALFUNCTIONCALL, IDS_NOEDITCTRL);
}
}
, . ,
, Automation .
, IDS_NOEDITCTRL.
This operation can be performed only when valid edit box control is present. Please activate
the control and try again. ,
GetWindowText BSTR.
.
, SetEditText SetWindowText
, SetModifiedFlag.
OnValidate, .
CString ( ,
CEdit::GetWindowText ,
EditText ).
CString::Find .
, Find ;
1. , 1 (
), ,
, , Validated.
, , .
OLE Events ClassWizard ,
( , Success).
, Validated.

void CChildrenCtrl::OnValidate()
{

www.books-shop.com

FireBeforeValidation();
CString s;
m_editEntry.GetWindowText(s);
BOOL bRet = s.Find(_T(" ")) == -1;
FireValidated(bRet);
}
, .
:
, ,
CEdit::GetSafeHwnd. OnValidate? ,
( ,
), .
. ,
, - ,
.
.
EditText, . Children
CD-ROM, \CODE\CHAP14\CHILDRN2.

14.5
,
, (, ?). ,
(, Visual Basic) Children
. ,
Children. File|Save Property Set,
. File|Load Property Set
.
, . 14-3.

.14-3. Children ( ),

Visual Basic .
Visual Basic Children . ,
Visual Basic,
Internal Application Error. OK Apply, ,

www.books-shop.com

Automation, GetEditText SetEditText.


,
. ,
?

.
OnCreate, . ,
, ?
,
ActiveX. ?
18, VBX
Windows.

%RRNVVKRS

piracy@books-shop.com

15


, Microsoft Visual Basic (VBX),
( )
. ,
.
.

15.1 ActiveX
ActiveX.
Bindable. ,
.
DisplayBind, ,
. ActiveX ,
.
RequestEdit,
, . , -
(, Caption
), DefaultBind,
.
, IDL ODL.
, , ,
, :

[id(1), bindable, requestedit, displaybind, defaultbind] short


DataBoundProp;
DataBoundProp,
dispid, 1.
,
, .
IPropertyNotifySink , 14
.
IUnknown, IPropertyNotifySink : OnChanged OnRequestEdit.
dispid , .
, ,
IPropertyNotifySink .

OnChanged . ,
,
OnRequestEdit .
, ,
ActiveX . , ,
, IPropertyNotifySink ,
OnRequestEdit .
.
, . , . ,
,
. ,
Visual Basic 4.0 Microsoft Visual
++ 4.2 .

www.books-shop.com

: ActiveX
, (, Visual Basic)
- (data source controls).
? , .
( 1996 ) Microsoft -
. , , ,
.
Microsoft , OLE DB
( ) ,
.
,
ActiveX. ,
ActiveX, , ,
- (ISAM) ,
, .

15.2
,
. , MFC,
.
, .
OLE ClassWizard Bound.
( ,
). DataBoundProperty BSTR,
. DataBoundProperty OLE
Automation ClassWizard Data Binding.
Data Binding. ,
( ,

). , CString m_strDBProp.
(private) .
DataBoundProperty, :

BSTR CBoundCtrl::GetDataBoundProperty()
{
return m_strDBProp.AllocSysString();
}
void CBoundCtrl::SetDataBoundProperty(LPCTSTR lpszNewValue)
{
if (BoundPropertyRequestEdit(dispidDataBoundProperty))
{
m_strDBProp = lpszNewValue;
SetModifiedFlag();
BoundPropertyChanged(dispidDataBoundProperty);
}
else
{
SetNotPermitted();
}
}
BSTR CString .
. ,
, BoundPropertyRequestEdit;
,
IPropertyNotifySink::OnRequestEdit. TRUE,
. FALSE
SetNotPermitted. ThrowError
HRESULT, CTL_E_SETNOTPERMITTED.

www.books-shop.com


BoundPropertyRequestEdit, dispid . IDE
, dispid , .
( dispidDataBoundProperty),
dispid . , ,
dispid . , ,
dispid.

. ,
CString, SetModifiedFlag
, BoundPropertyChanged.
, .
OnDraw ,
m_strDBProp .

void CBoundCtrl::OnDraw(CDC* pdc,


const CRect& rcBounds, const CRect& rcInvalid)
{
pdc->FillRect(rcBounds,
CBrush::FromHandle((HBRUSH)GetStockObject(WHITE_BRUSH)));
pdc->TextOut(rcBounds.left + 3, rcBounds.top + 3, m_strDBProp);
}


: ,
. ,
, ( ). ,
, (0, 0).
. !

,
DataBoundProperty. ,
. 15-1.

www.books-shop.com

.15-1. Bound
, :
1.
2.
3.

.
IDD_PROPPAGE_BOUND.
, &Data Bound Property.
a (&) ,
( ). ,
.
4. .
5. Ctrl .
Add Member Variable, Member Variables
ClassWizard.
6. (, m_strDBProp). Category
Value CString.
7. ,
(DataBoundProperty).
8. OK .
! CD-ROM, \CODE\CHAP15\BOUND.

15.3
, .
, Bound
(
View|Notification Log, ). . 15-2
Bound .

www.books-shop.com

.15-2. Bound
Notification Log
OnRequestEdit OnChanged .
,
OnRequestEdit,
OnChanged. Notification Log
DataBoundProperty .
:

00_BoundControl: DataBoundProperty; OK to change? (YES)


00_BoundControl: DataBoundProperty changed

( Notification Log ,
), (. 15-3),
:

00_BoundControl: DataBoundProperty; OK to change (NO)


,
. ,
, .

www.books-shop.com

.15-3. Bound ,

15.4
, , ,
. , ,

.
. ,
(, Properties
Visual Basic). , ,
( )? ,
. , ,
(,
). , Visual
Basic 4.0 Microsoft Visual FoxPro 3.0, OnChanged
.

15.5
, , ,
, .
, Visual
Basic Visual C++ 4.2 .
(advanced data binding). Visual Basic,
, OLE DB
. ,
, ,
. -,
, .
, - MSRDC ODBC
ODBC.
, ICursor.

, ,
( ). Microsoft
,

www.books-shop.com

, 1996 . Microsoft World Wide Web


Microsoft Developer Network (MSDN).

www.books-shop.com

16

, ?
, ?
, , ,
( , ). ( !)
, .
, .
MFC , .
,
. MFC,

. IClassFactory2
. MFC IClassFactory2,
( )
++.
, World Wide Web,
, Web-.

16.1
ActiveX . ,
. ,
? -

, .
, ,
, .

, ,
, .
, , , .
,
.
.
.
,
, ,
. , ,
, .

www.books-shop.com

ActiveX .
MFC .
,
VBX, Microsoft Visual Basic. ,

, . ,
ActiveX MFC,
.

16.2
ActiveX
ActiveX
, IClassFactory2.
ActiveX, , ActiveX,
. IClassFactory2,
, IClassFactory,
. , ActiveX API
ActiveX, .
API ( CoCreateInstance OleCreate)
IClassFactory, IClassFactory2,
ActiveX. Microsoft
API,
IClassFactory2, .

. , IClassFactory
, .
IClassFactory2 IClassFactory,
. GetLicInfo
:
, ?
? RequestLicKey
runtime- (
). CreateInstanceLic CreateInstance, ,
CreateInstance .
GetLicInfo, RequestLicKey CreateInstanceLic ,
. ,
( ) .
,
( ,
).
IClassFactory2 BSTR.
, , BSTR
, -.
, .
:

;
;
runtime- ,
(, Make EXE File Visual Basic);
.

,
IClassFactory2! (),
, () ,
.
( , MFC),
, .

www.books-shop.com

,
IClassFactory2::CreateInstanceLic , NULL.
,
.
,
.
, ,
CreateInstanceLic CreateInstance.
, -
.
IClassFactory, ,
.
, IClassFactory::CreateInstance .
runtime- , ,
IClassFactory2::GetLicInfo , runtime-
. , IClassFactory2::RequestLicKey
, . ? runtime-
,
, ,
. , , .
, ,
IClassFactory2::CreateInstanceLic .
NULL, ,
, . ,
. , ,
.
, IClassFactory IClassFactory2,
. IClassFactory ,
,
. , , , IClassFactory,
,
.

16.3 MFC
MFC , .
OLE ControlWizard,
.LIC. ,
:

Copyright (C) 1997 < >


< > , Microsoft Visual C++ (
C++) .
,
.
,
. !

16.4
, OLE ControlWizard.
License. , ,
Runtime License . .
, ,
ODL-,
. , licensed. ,

%RRNVVKRS

piracy@books-shop.com

LICENSECTL.H
.
DECLARE_OLECREATE_EX, :

BEGIN_OLEFACTORY(CLicenseCtrl)
// guid
virtual BOOL VerifyUserLicense();
virtual BOOL GetLicenseKey(DWORD, BSTR FAR*);
END_OLEFACTORY(CLicenseCtrl)
BEGIN_OLEFACTORY END_OLEFACTORY C++,
IClassFactory2;
COleObjectFactoryEx, MFC,
COleObjectFactory. ,
VerifyUserLicense GetLicenseKey,
. ,
DECLARE_OLECREATE_EX.
, LICENSECTL.CPP, ,
, 16-1.
16-1. , OLE ControlWizard

///////////////////////////////////////////////////////////////
//
static const TCHAR BASED_CODE _szLicFileName[] =
_T("license.lic");
static const WCHAR BASED_CODE _szLicString[] =
L"Copyright (c) 1996 Microsoft";
/////////////////////////////////////////////////////////////
// CLicenseCtrl::CLicenseCtrlFactory::VerifyUserLicense //
BOOL CLicenseCtrl::CLicenseCtrlFactory::VerifyUserLicense()
{
return AfxVerifyLicFile(AfxGetInstanceHandle(), _szLicFileName,
_szLicString);
}
//////////////////////////////////////////////////////////////
// CLicenseCtrl::CLicenseCtrlFactory::GetLicenseKey // runtime-
BOOL CLicenseCtrl::CLicenseCtrlFactory::GetLicenseKey(
DWORD dwReserved,
BSTR FAR* pbstrKey)
{
if (pbstrKey == NULL)
return FALSE;

*pbstrKey = SysAllocString(_szLicString);
return (*pbstrKey != NULL);

,
. LICENSE.LIC (OLE ControlWizard
, , LIC).
, MFC , .

www.books-shop.com

Copyright
(c) 1996 Microsoft (, ,
Microsoft). .
VerifyUserLicFile.
MFC GetLicenseKey,
. VerifyUserLicense ,
, .
, OLE ControlWizard
GetLicenseKey.
: BSTR .
License CD-ROM,
\CODE\CHAP16\LICENSE. .
, ,
, OLE ControlWizard. ,
LIC-, , .
(, Visual Basic)
, . ,
Visual Basic
, License (,
, ), File|Make
EXE File. , LIC
,
, ,
Visual Basic IClassFactory::CreateInstanceLic.

16.5
, MFC .
; , ,
. ,
. ,
, . ,
Microsoft
Windows NT. , , , .
,
,
. ,

, . :
COM. ,
, ,
( ).
GetLicenseKey .
MFC , .
VerifyLicenseKey COleObjectFactory.
, .
IClassFactory2::GetLicInfo, ,
.
, BSTR .
, GetLicenseKey,
IClassFactory2::RequestLicKey, BSTR
.
, , OLE ControlWizard,

.
, (,
, ).

www.books-shop.com

,
OLE ControlWizard _szLicString. :

ILOVECOM
GetLicenseKey 16-2.
16-2. GetLicenseKey,

BOOL CLicenseCtrl::CLicenseCtrlFactory::GetLicenseKey(
DWORD dwReserved, BSTR FAR* pbstrKey)
{
if (pbstrKey == NULL)
return FALSE;
CString strLicense = _T("PATCH");
strLicense += _szLicString + 5;
*pbstrKey = strLicense.AllocSysString();
return (*pbstrKey != NULL);
}
16-2 . CString,
PATCH.
, ,
(COM). AllocSysString CString (,
SysAllocString, API?!) BSTR.
,
, ,
ILOVECOM.
, , ,
.
, , .
.
VerifyUserLicense .
, OLE
ControlWizard. VerifyUserLicense
IsLicenseValid. ,
CreateInstance CreateInstanceLic.
VerifyUserLicense MFC AfxVerifyLicFile,
,
. . ,
AfxVerifyLicFile, 16-3.
16-3. VerifyUserLicense,

BOOL CLicenseCtrl::CLicenseCtrlFactory::VerifyUserLicense()
{
// ...
BOOL bVerified = FALSE;
// , DLL
TCHAR szPathName[_MAX_PATH];
::GetModuleFileName(AfxGetInstanceHandle(), szPathName,
_MAX_PATH);
LPTSTR pszFileName = _tcsrchr(szPathName, \\) + 1;
_tcscpy(pszFileName, _szLicFileName);

www.books-shop.com

unsigned int nLen = wcslen(_szLicString);


LPTSTR pszBuf = new TCHAR[nLen+3];
WCHAR *pwszBuf = new WCHAR[nLen+3];
try
{
// ,
CStdioFile file(szPathName, CFile::modeRead |
CFile::typeText);
file.ReadString(pszBuf, nLen + 2);
if (pszBuf[nLen] == \n)
{
pszBuf[nLen] = \0;
}
// ?
if (_tcslen(pszBuf) == nLen)
{
// Unicode
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, pszBuf, nLen,
pwszBuf, nLen + 3);
// ?
if (wcsncmp(pwszBuf, _szLicString, 5) != 0)
{
// ?
if (wcsncmp(pwszBuf + 5, _szLicString + 5, 3) == 0)
{
bVerified = TRUE;
}
}
}

}
catch(...)
{
throw;
}
delete [] pszBuf;
return bVerified;

, - ,
AfxVerifyLicFile.
, . ,
, DLL- ,
. ,
. (\n)
, .
\n (, , ),
.
, ,
,
. ,
,
. ,
. ,
, . ,
, , .
, , TRUE,
FALSE.
, .

, ,

www.books-shop.com

. ,
.
,
IClassFactory2::CreateInstance MFC
VerifyLicenseKey COleObjectFactoryEx.
, CreateInstanceLic, ,
. ,
. VerifyLicenseKey
LICENSECTL.H ( GetLicenseKey),
LICENSECTL.CPP , 16-4.
16-4. VerifyLicenseKey,
IClassFactory2::CreateInstanceLic

BOOL CLicenseCtrl::CLicenseCtrlFactory::VerifyLicenseKey(BSTR
bstrKey)
{
BOOL bVerified = FALSE;
// ?
if (wcslen(bstrKey) == wcslen(_szLicString))
{
// ?
if (wcsncmp(bstrKey, _szLicString, 5) != 0)
{
// ?
if (wcsncmp(bstrKey + 5, _szLicString + 5, 3) == 0)
{
bVerified = TRUE;
}
}
}
return bVerified;
}
VerifyLicenseKey VerifyUserLicense,
. , VerifyLicenseKey
.

,
BSTR . ,
, ,
.

CD-ROM,
\CODE\CHAP16\LICENSE2.

16.6
.
.
/
. ,
MFC,
. ,
.

www.books-shop.com

License : 1
, 2,
, .
LicenseLevel, FALSE
TRUE .
Standard Professional ,
About . ,
Professional Features Enabled, ,
LicenseLevel TRUE, FALSE.
LicenseLevel
. ,
,
.

16.7 License

, .
:

Copyright (c) 1997 Adam Denning (Standard Edition)

Copyright (c) 1997 Adam Denning (Professional Edition)


, .
( License),
.
:

static const WCHAR BASED_CODE _szLicStringStdEdition[] =


L"Copyright (c) 1996 Microsoft Corporation (
Standard Edition)";
static const WCHAR BASED_CODE _szLicStringProEdition[] =
L"Copyright (c) 1996 Microsoft Corporation (
Professional Edition)";
16-5.
16-5.

///////////////////////////////////////////////////////////////
// CLicenseCtrl::CLicenseCtrlFactory::VerifyUserLicense //
BOOL CLicenseCtrl::CLicenseCtrlFactory::VerifyUserLicense()
{
BOOL bLicensed = FALSE;
if (AfxVerifyLicFile(AfxGetInstanceHandle(), _szLicFileName,
_szLicStringStdEdition))
{
bLicensed = TRUE;
m_bProEdition = FALSE;
}
else if (AfxVerifyLicFile(AfxGetInstanceHandle(),
_szLicFileName,
_szLicStringProEdition))
{

www.books-shop.com

bLicensed = TRUE;
m_bProEdition = TRUE;

}
return bLicensed;
}

//////////////////////////////////////////////////////////////
// CLicenseCtrl::CLicenseCtrlFactory::GetLicenseKey // runtime-
BOOL CLicenseCtrl::CLicenseCtrlFactory::GetLicenseKey(DWORD
dwReserved, BSTR FAR* pbstrKey)
{
if (pbstrKey == NULL)
return FALSE;
if (m_bProEdition)
{
*pbstrKey = SysAllocString(_szLicStringProEdition);
}
else
{
*pbstrKey = SysAllocString(_szLicStringStdEdition);
}
return (*pbstrKey != NULL);
}
BOOL CLicenseCtrl::CLicenseCtrlFactory::VerifyLicenseKey(BSTR
bstrKey)
{
BOOL bLicensed = FALSE;
if (bstrKey != NULL)
{
if (wcscmp(_szLicStringProEdition, bstrKey) == 0)
{
bLicensed = TRUE;
m_bProEdition = TRUE;
}
else if (wcscmp(_szLicStringStdEdition, bstrKey) == 0)
{
bLicensed = TRUE;
m_bProEdition = FALSE;
}
}
return bLicensed;
}
, ,

( COM). ,
, :

BEGIN_OLEFACTORY(CLicenseCtrl)
// guid
virtual BOOL VerifyUserLicense();
virtual BOOL GetLicenseKey(DWORD, BSTR FAR*);
virtual BOOL VerifyLicenseKey(BSTR);
// Runtime-
BOOL m_bProEdition;
END_OLEFACTORY(CLicenseCtrl)
m_bProEdition.
OnDraw ,
. Ellipse

www.books-shop.com

,
:

pdc->TextOut(rcBounds.left + 3, rcBounds.top + 3,
factory.m_bProEdition ? "Professional" : "Standard");
COleControl factory,
(, DECLARE_OLECREATE_EX BEGIN_OLEFACTORY)
.
About.
Current License Held,
, . ,
Professional, IDC_LICLEVEL.
ClassWizard, -
About. ClassWizard , About
-, CDialog.
OK CAbout. m_strLevel,
IDC_LICLEVEL. .
AboutBox :

void CLicenseCtrl::AboutBox()
{
CAbout dlgAbout(this);
dlgAbout.m_strLevel = factory.m_bProEdition ?
"Professional" : "Standard";
dlgAbout.DoModal();
}
, ,
CAbout CDialog.

. m_strLevel CAbout
, , IDC_LICLEVEL
CAbout::InitDialog. ,
LICENSECTL.CPP #include ABOUT.H.
LicenseLevel.
ClassWizard , BOOL
/. 16-6.
16-6. LicenseLevel

BOOL CLicenseCtrl::GetLicenseLevel()
{
return factory.m_bProEdition;
}
void CLicenseCtrl::SetLicenseLevel(BOOL bNewValue)
{
if (factory.m_bProEdition)
{
factory.m_bProEdition = FALSE;
SetModifiedFlag();
InvalidateControl();
}
else
{
SetNotSupported();
}
}

www.books-shop.com

. ,
. ,
, ,
. ,
SetNotSupported.
LicenseLevel ,
.
LicenseLevel. License
CD-ROM, \CODE\CHAP16\LICENSE3.

16.8 Web-
,
, Visual Basic Visual C++.
Web- . Microsoft
-
, .
.
Microsoft ,
, IClassFactory2.
, HTML, . . ,
.

HTML-, ;
Visual Basic.
HTML (, Microsoft FrontPage) Visual
Basic .
( , plug-in) VBRUN, runtime-
Visual Basic.

, Web-,
, /
, HTML-
,
. (
LPK), .
LPK-,
, .
, , HTML .
LPK- PARAM
<OBJECT>:

<OBJECT
CLASSID="clsid:5220cb21-c88d-11cf-b347-00aa00a28331"
>
<PARAM NAME="LPKPath" VALUE="ThisPage.LPK"
</OBJECT>
CLSID ActiveX SDK, 1996 ,
.
SDK .
, LPKPath
URL URL , URL,
. ? URL
, (
, ) LPK-. /
LPK-, . ,
, , .

www.books-shop.com

,
.
Microsoft Internet Explorer HTML-.
- ,
, .
HTML- , , .
LPK-
. , Netscape Navigator
NCompass ActiveX, .
<OBJECT> ,
<EMBED>:

<OBJECT
CLASSID="clsid:5220cb21-c88d-11cf-b347-00aa00a28331"
>
<PARAM NAME="LPKPath" VALUE="ThisPage.LPK"
<EMBED SR="ThisPage.LPK"
</OBJECT>

16.9 LPK-
LPK- ,
/CLSID. ,
CLSID. CLSID UUENCODE Base 64
, .
LPK- :

: LPK License Package.


,
,
.
GUID, LPK- .

UUENCODE.
GUID LPK- ( , LPK-).
DWORD .
, CLSID,
Unicode.
LPK-. , (
UUDECODE !).

LPK License Package


/////////////////////////////////////////////////////////////////////
// WARNING: The information in this file
// is protected by copyright law
// and international treaty provisions.
// Unauthorized reproduction or
//
// distribution of this file, or any portion of it,
// may result in severe
// criminal and civil penalties
// and will be prosecuted to the maximum
//

%RRNVVKRS

piracy@books-shop.com

// extent possible under the law.


// Further you may not reverse engineer,
// decompile, or disassemble the file.
//
/////////////////////////////////////////////////////////////////////
{3d25aba1-caec-11cf-b34a-00aa00a28331}
Ya35X1sM0BG37wCAx3r4gI=
BQAAAA=
oZ9YBVbDzhG/AQCqAFVZWgAAAAA
=
io3aWGqdGxCvwEIQECqNpxcAAAAgAHEAaABqACAAWgB0AHUAUQBoAGEOwBq
AGQAZgBuAFsAaQBhAGUAdAByACAA
ILfDqFoLGxCyLgCqADey/CQAAABBADYA
RABBADgANQA4ADAALQA1ADkARAA2AC0AMQAwADEAQgAtAEEAMwBDADkALQAwADgAM
AAwADIAQgAyAEYANAA5AEYAQgA=
hcgs99xaGxClbACqADZo3CoAAABBAE4ASQ
BMAEkAQwAyADcAMAA2ACAALQAgAC0AIABDAG8AcAB5AHIAaQBnAGgAdAgACgAYwA
pACAAMQA5ADkANQAgAEQAZQBzAGEAdwBhAHIAZQA=
YOfu+n4RGxCJMwgAKy9P
WiQAAABEADEAQgAyADAAQQA0ADAALQA1ADkARAA1AC0AMQAwADEAQgAtAEEAMwBDA
DkALQAwADgAMAAwADIAQgAyAEYANAA5AEYAQgA=

16.10 LPK-
HTML
Visual Basic. , LPK-
. .
HTML- ,
Notepad ( Visual Notepad++), ,
ActiveX SDK. LPK_Tool
, ,
LPK-. . 16-1 ( !) LPK_Tool.

www.books-shop.com

.16-1. LPK_Tool

www.books-shop.com

17

ISimpleFrameSite
, .
, .
/, ActiveX
.
-?
, , ?
, (
, ) ;
,
. (, Microsoft Visual
Basic 4.0) . ,
,
,
.
, ISimpleFrameSite,
, . ,
,
. ,
. Visual Basic ,
.
, .

17.1 ISimpleFrameSite
MFC, ISimpleFrameSite
, EnableSimpleFrame
(, ). ,
, OLEMISC_SIMPLEFRAME.

, OLE ControlWizard .
, ,
. 18
.

, , :

OLEMISC_SIMPLEFRAME;
ISimpleFrameSite ;
NULL,
;
()
,
, ISimpleFrameSite.

,
, . IUnknown,

www.books-shop.com

PreMessageFilter PostMessageFilter.
, .
PreMessageFilter ,
. PostMessageFilter ,
,
.
MFC ,
COleControl::WindowProc,
.
, , WPARAM LPARAM ,
. ,
PreMessageFilter
. PostMessageFilter,
.
PreMessageFilter.
, ISimpleFrameSite.
.
, .

, . ,
(, Visual Basic 4.0 ),
, ,
, .
,
WM_PAINT
, ,
.
Visual Basic 4.0 ,
, Visual Basic
( /
HWND, OLE ,
).
( )
( ). ,
,
WM_PAINT. , .
. ,
,
. ,
,
. , ,
, . ,

HWND .

,
.

www.books-shop.com

18

VBX
Windows
, -
Visual Basic, VBX. , , VBX
32-
, Intel. Microsoft ActiveX.
, VBX
ActiveX. . -,
, VBX
ActiveX. -, ,
VBX .
, : Visual Basic 4.0
Visual Basic VBX,
, ActiveX. ,
VBX-, .
, Microsoft Visual ++ 16- ,
VBX, ActiveX (
16- 32- ). ,
.
,
, . VBX
ActiveX .
, .
,
Microsoft Windows,
, -
. , ,
ActiveX. (
).


VBX ? VBX
Windows, ,
.

18.1 VBX
VBX ActiveX VBX
, ActiveX .
, !
16- OLE CDK ,
,
ActiveX :

www.books-shop.com

,
VBX ( , )
ActiveX;
!

VBX OLE ControlWizard, 32 . Visual C++ ( , 4.2)


16- Visual C++ 1.52c. 16- OLE ControlWizard
. , VBX,
16- ,
32- . , 16- CDK 32-
, , , .

OLE ControlWizard
VBX 16/32- . ,
32- OLE ControlWizard , !
, ,
, .
,
.
ActiveX, .

18.2 OLE ControlWizard


16- OLE ControlWizard
VBX ActiveX.
, ,
. VBX
ActiveX.
ActiveX.
ActiveX, , ODL-
, VBX. ,
, ,
. 18-1 ODL-,
Visual Basic - OLE,
MSOLE2.VBX. 18-2 ,
18-3 . ,
VBX1
.
18-1. ODL-, MSOLE2.VBX

// vbx1.odl:
// OLE Custom Control
// Make Type Library (mktyplib)
// (vbx1.tlb),
// vbx1.ocx
#inc1ude <olectl.h>
[ uuid(14A99183-A8BF-11CE-99BF-88AA8847D4FD), version(1.0),
helpstring("Vbx1 OLE Custom Control modu1e"), control ]
library Vbx1Lib
{
importlib(STDOLE_TLB);
importlib(STDTYPE_TLB);

www.books-shop.com

//

CVbx1Ctrl

[ uuid(14A99181-ASBF-11CE-99BF-88AA8847D4FD),
helpstring("Dispatch interface for Vbx1 Contro1"), hidden ]
dispinterface _DVbx1
{
properties:
// - ClassWizard .
// .
//((AFX_ODL_PROP(CVbx1Ctrl)
[id(1)] BSTR Class;
[id(2)] short OLEType;
[id(3)] BSTR SourceDoc;
[id(4)] BSTR SourceItem;
[id(5)] short UpdateOptions;
[id(6)] BSTR HostName;
[id(7)] short SizeMode;
[id(8)] short AutoActivate;
[id(9)] boolean AutoVerbMenu;
[id(10)] boolean AppIsRunning;
[id(11)] IPictureDisp* Picture;
[id(12)] IDispatch* Object;
[id(13)] long Data;
[id(14)] BSTR DataText;
[id(15)] BSTR Format;
[id(17)] short ObjectAcceptFormatsCount;
[id(19)] short ObjectGetFormatsCount;
[id(20)] short OLETypeA1lowed;
[id(21)] boolean PasteOK;
[id(24)] short ObjectVerbsCount;
[id(25)] short Verb;
[id(26)] short FileNumber;
[id(27)] short Action;
[id(28)] short MiscFlags;
[id(29)] long OleObjectB1ob;
[id(38)] long cxTHk;
[id(31)] long cyTHk;
[id(32)] boolean fFFHk;
[id(33)] short DisplayType;
[id(34)] long LpOleObject;
[id(DISPID BACKCOLOR),bindable,requestedit] OLE_COLOR
BackColor;
[id(DISPID_BORDERSTYLE),bindab1e,requestedit] short
BorderStyle;
[id(DISPID_ENABLED),bindable,requestedit] boolean
Enabled;
[id(DISPID_HWND)] short hWnd;
//}}AFX_ODL _PROP
methods:
// - ClassWizard
// .
//
// .
//((AFX_ODL_METHOD(CVbx1Ctrl)
[id(16), propget] BSTR ObjectAcceptFormats
(short index);
[id(16), propput] void ObjectAcceptFormats(short Index,
BSTR strObjectAcceptFormats);
[id(18), propget] BSTR ObjectGetFormats(short index);
[id(18), propput] void ObjectGetFormats(short index,
BSTR strObjectGetFormats);

www.books-shop.com

[id(22), propget] BSTR ObjectVerbs(short index);


[id(22), propput] void ObjectVerbs(short 1ndex, BSTR
strObjectVerbs);
[id(23), propget] long ObjectVerbF1ags(short index);
[id(23), propput] void ObjectVerbF1ags(short index,
long l0bjectVerbFlags);
//}}AFX_ODL_METHOD
[id(DISPID_ABOUTBOX)] void AboutBox();
};
//

CVbx1Ctrl

[ uuid(14A99182-A8BF-11CE-99BF-88AA8847D4FD),
helpstring("Event interface for Vbx1 Control") ]
dispinterface _DVbx1Events
{
properties:
//
methods:
// - ClassWizard
// .
// .
//{{AFX_ODL_EVENT(CVbx1Ctrl)
[id(1)] void Resize(float* HeightNew, float* WidthNew);
[id(2)] void Updated(short* Code);
[id(DISPID CLICK)] void Click();
[id(DISPID DBLCLICK)] void DblClick();
[id(DISPID KEYDOWN)] void KeyDown(short* KeyCode,
short Shift);
[id(DISPID KEYPRESS)] void KeyPress
(short* KeyAscii);
[id(DISPID KEYUP)] void KeyUp(short* KeyCode, short
Shift);
[id(DISPID MOUSEDOWN)] void MouseDown(short Button,
short Shift, OLE_XPOS_PIXELS X, OLE_YPOS_PIXELS Y);
[id(DISPID HOUSEMOVE)] void MouseMove(short Button,
short Shift, OLE_XPOS_PIXELS X, OLE_YPOS_PIXELS Y);
[id(DISPID MOUSEUP)] void MouseUp(short Button, short
Shift, OLE_XPOS_PIXELS X, OLE_YPOS_PIXELS Y);
//}}AFX_ODL_EVENT
};
// CVbx1Ctrl
[ uuid(14A99188-ABBF-11CE-99BF-88AA884704FD),
helpstring("Vbx1 Control"), control ]
coclass Vbx1
{
[defau1t] d1spinterface _DVbx1;
[default, source] dispinterface _DVbx1Events;
};
//{{AFX_APPEND_ODL}}
};
18-2. , 16- OLE

ControlWizard MSOLE2.VBX
// vbx1ctl.h: OLE CVbx1Ctrl
/////////////////////////////////////////////////////////

www.books-shop.com

// CVbx1Ctrl : vbx1ctl.cpp
class CVbx1Ctrl : public COleControl
{
DECLARE DYNCREATE(CVbx1Ctrl)
//
public:
CVbx1Ctrl();
//
//
virtua1 void OnDraw(
CDC* pdc, const CRect& rcBounds, const CRect&
//
virtual void DoPropExchange(CPropExchange* pPX);
//
virtual void OnResetState();
//
protected:
~CVbx1Ctrl( );
DECLARE_OLECREATE_EX(CVbx1Ctrl)
DECLARE_OLETYPELIB(CVbx1Ctrl)
DECLARE_PROPPAGEIDS(CVbx1Ctrl)
//
DECLARE_OLECTLTYPE(CVbx1Ctrl)
//
//

// guid
// GetTypeInfo
//
//

// VBX
BOOL PreCreateWindow(CREATESTRUCTS cs);
//
CString m_strClass;
CString m_strSourceDoc;
CString m_strSourceItem;
short m_enumUpdateQptions;
CString m_strHostName;
short m_enumSizeMode;
CPictureHolder m_cPicPicture;
CString m_strFormat;
short m_iFileNumber;
long m_cxcxTHk;
long m_cycyTHk;
BOOL m_bfFFHk;
short m_enumDisplayType;
//
//{{AFX_MSG(CVbx1Ctrl)
// - ClassWizard
// .
//
// !
//}}AFX_MSG
DECLARE MESSAGE MAP( )
//
//{{AFX_DISPATCH(CVbx1Ctrl)
// - ClassWizard
// .
//

www.books-shop.com

// !
afx_msg BSTR GetC1ass();
afx_msg void SetClass(LPCTSTR);
afx_msg short GetOLEType();
afx_msg void SetOLEType(short);
afx_msg BSTR GetSourceDoc();
afx_msg void SetSourceDoc(LPCTSTR);
afx_msg BSTR GetSourceItem();
afx_msg void SetSourceltem(LPCTSTR);
afx_msg short GetUpdateOptions();
afx_msg void SetUpdateOptions(short);
afx_msg BSTR GetHostName();
afx_msg void SetHostName(LPCTSTR);
afx_msg short GetSizeMode();
afx_msg void SetSizeMode(short);
short m enumAutoActivate;
BOOL m bAutoVerbMenu;
afx_msg BOOL GetAppIsRunning();
afx_msg void SetAppIsRunning(BOOL);
afx_msg LPPICTUREDISP GetPicture();
afx_msg void SetPicture(LPPICTUREDISP);
afx_msg LPDISPATCH GetObject();
afx_msg void SetObject(LPDISPATCH);
afx_msg long GetData();
afx_msg void SetData(long);
afx_msg BSTR GetDataText();
afx_msg void SetDataText(LPCTSTR);
afx_msg BSTR GetFormat();
afx_msg void SetFormat(LPCTSTR);
afx_msg BSTR GetObjectAcceptFormats(short index);
afx_msg void SetObjectAcceptFormats(short index, LPCTSTR);
afx_msg short GetObjectAcceptFormatsCount();
afx_msg void SetObjectAcceptFormatsCount(short);
afx_msg BSTR GetObjectGetFormats(short 1ndex);
afx_msg void SetObjectGetFormats(short Index, LPCTSTR);
afx_msg short GetObjectGetFormatsCount();
afx_msg void SetObjectGetFormatsCount(short);
short m enumOLETypeAllowed;
afx_msg BOOL GetPasteOK();
afx_msg void SetPasteOK(BOOL);
afx_msg BSTR GetObjectVerbs(short index);
afx_msg void SetObjectVerbs(short index, LPCTSTR);
afx_msg long GetObjectVerbFlags(short index);
afx_msg void SetObjectVerbF1ags(short index, long);
afx_msg short GetObjectVerbsCount();
afx_msg void SetObjectVerbsCount(short);
short m_iVerb;
afx_msg short GetFileNumber();
afx_msg void SetFileNumber(short);
afx_msg short GetAction();
afx_msg void SetAction(short);
short m_iMiscFlags;
afx_msg long GetOleObjectBlob();
afx_msg void Set0le0bjectB1ob(1ong);
afx_msg long GetcxTHk();
afx_msg void SetcxTHk(long);
afx_msg long GetcyTHk();
afx_msg void SetcyTHk(long);
afx_msg BOOL GetfFFHk();
afx_msg void SetfFFHk(BOOL);
afx_msg short GetD1splayType();
afx_msg void SetDisplayType(short);
afx_msg long GetLpOleObject();
afx_msg void SetLpOleObject(long);
%RRNVVKRS

piracy@books-shop.com

//}}AFX_DISPATCH
DECLARE DISPATCH MAP()
afx_msg void AboutBox();
//
//{{AFX_EVENT(CVbx1Ctrl)
// - ClassWizard
// .
//
// !
void FireResize(float FAR* HeightHew, float FAR* WidthNew)
{ FireEvent(eventidResize, EVENT PARAM( VTS_PR4 VTS_PR4),
HeightHew, WidthNew); }
void FireUpdated(short FAR* Code)
{ FireEvent(eventidUpdated, EVENT PARAM( VTS_PI2), Code); }
//}}AFX_EVENT
DECLARE EVENT MAP()
//
public:
enum {
//{{AFX_DISP ID(CVbx1Ctrl)
// - ClassWizard
// .
//
// !
dispidClass = 1L,
dispidOLEType = 2L,
disp1dSourceDoc = 3L,
dispidSourceItem = 4L,
dispidUpdateOptions = 5L,
dispidHostHame = 6L,
dispidSizeMode = 7L,
dispidAutoActivate = 8L,
dispidAutoVerbMenu = 9L,
dispidAppIsRunning = 10L,
dispidPicture = 11L,
dispidObject = 12L,
dispidData = 13L,
dispidDataText = 14L,
dispidFormat = 15L,
dispfdObjectAcceptFormats = 16L,
dispidObjectAcceptFormatsCount = 17L,
dispidObjectGetFormats = 18L,
dispidObjectGetFormatsCount = 19L,
dispidOLETypeAllowed = 20L,
dispidPasteOK = 21L,
dispidObjectVerbs = 22L,
dispfdObjectVerbFlags = 23L,
dispidObjectVerbsCount = 24L,
dispidVerb = 25L,
dispidFileNumber = 26L,
dispidAction = 27L,
dispidMiscFlags = 28L,
dispid0leObjectBlob = 29L,
dispidCxTHk = 30L,
dispidCyTHk = 31L,
dispidFFFHk = 32L,
dispidDisplayType = 33L,
dispidLpOleObject = 34L,
eventidResize = 1L,

www.books-shop.com

eventidUpdated = 2L
//}}AFX_DISP_ID
};
};
18-3. , 16- OLE
ControlWizard MSOLE2.VBX

// vbx1ctl.cpp : OLE CVbx1Ctrl


#include "stdafx.h"
#include "vbx1.h"
#include "vbx1ctl.h"
#include "vbx1ppg.h"
#ifdef _DEBUG
#ifdef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
IMPLEMENT_DYNCREATE(CVbx1Ctrl, COleContro1)
//////////////////////////////////////////////////////////////
//
BEGIN MESSAGE HAP(CVbx1Ctrl, COleContro1)
//{{AFX MSG MAP(CVbx1Ctrl)
// - ClassWizard
// .
//
// !
//}}AFX NSG MAP
ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
END MESSAGE MAP()
/////////////////////////////////////////////////////////////
//
BEGIN DISPATCH MAP(CVbx1Ctrl, COleControl)
//{{AFX DISPATCH MAP(CVbx1Ctrl)
// - ClassWizard
// .
//
// !
DISP_PROPERTY_EX(CVbx1Ctrl, "Class",
GetClass, SetClass, VT_BSTR)
DISP_PROPERTY_EX(CVbx1Ctrl, "OLEType", GetOLEType,
SetOLEType, VT_12)
DISP PROPERTY_EX(CVbx1Ctrl, "SourceDoc", GetSourceDoc,
SetSourceDoc, VT_BSTR)
DISP_PROPERTY EX(CVbx1Ctrl, "SourceItem", GetSourceItem,
SetSourceItem, VT_BSTR)
DISP_PROPERTY EX(CVbx1Ctrl, "UpdateOptions",
GetUpdateOptions,
SetUpdateOptions, VT_12)
DISP_PROPERTY EX(CVbx1Ctrl, "HostName", GetHostName,
SetHostName, VT_BSTR)
DISP_PROPERTY EX(CVbx1Ctrl, "S1zeMode", GetSizeMode,
SetSizeMode, VT_12)
DISP_PROPERTY(CVbx1Ctrl, "AutoActivate", m_enumAutoActivate,
VT_12)
DISP_PROPERTY(CVbx1Ctrl, "AutoVerbMenu", m_bAutoVerbMenu,
VT 800L)

www.books-shop.com

DISP_PROPERTY_EX(CVbx1Ctrl, "AppIsRunning", GetAppIsRunning,


SetAppIsRunning, VT_BOOL)
DISP_PROPERTY_EX(CVbx1Ctrl, "Picture", GetPicture, SetPicture,
VT_PICTURE)
DISP_PROPERTY_EX(CVbx1Ctrl, "Object", GetObject, SetObject,
VT_DISPATCH)
DISP_PROPERTY_EX(CVbx1Ctrl, "Data", GetData, SetData, VT_14)
DISP_PROPERTY_EX(CVbx1Ctrl, "DataText", GetDataText,
SetDataText, VT BSTR)
DISP_PROPERTY_EX(CVbx1Ctrl, "Format", GetFormat, SetFormat,
VT_BSTR)
DISP_PROPERTY_PARAM(CVbx1Ctrl, "ObiectAcceptFormats",
GetObjectAcceptFormats, SetObjectAcceptFormats, VT_BSTR,
VTS_12)
DISP_PROPERTY_EX(CVbx1Ctrl, "ObjectAcceptFormatsCount",
GetObjectAcceptFormatsCount, SetObjectAcceptFormatsCount,
VT_12)
DISP_PROPERTY_PARAM(CVbx1Ctrl, "ObjectGetFormats",
GetObjectGetFormats, SetObjectGetFormats,
VT_BSTR, VTS_12)
DISP_PROPERTY_EX(CVbx1Ctrl, "ObjectGetFormatsCount",
GetObjectGetFormatsCount, SetObjectGetFormatsCount,
VT_12)
DISP_PROPERTY(CVbx1Ctrl, "OLETypeAllowed",
m_enumOLETypeAllowed, VT_12)
DISP_PROPERTY_EX(CVbx1Ctrl, "PasteOK", GetPasteOK, SetPasteOK,
VT_BOOL)
DISP_PROPERTY_PARAM(CVbx1Ctrl, "ObjectVerbs", GetObjectVerbs,
SetObjectVerbs, VT_BSTR, VTS_12)
DISP_PROPERTY_PARAM(CVbx1Ctrl, "ObjectVerbF1ags",
GetObjectVerbFlags, SetObjectVerbFlags, VT_14, VTS_12)
DISP_PROPERTY_EX(CVbx1Ctrl, "ObjectVerbsCount",
GetObjectVerbsCount, SetObjectVerbsCount, VT_12)
DISP_PROPERTY(CVbx1Ctrl, "Verb", m iVerb, VT_12)
DISP_PROPERTY EX(CVbx1Ctrl, "FileNumber", GetFileNumber,
SetFileNumber, VT_12)
DISP_PROPERTY_EX(CVbx1Ctrl, "Action", GetAction, SetAction,
VT_12)
DISP_PROPERTY(CVbx1Ctrl, "MiscFlags", m iMiscFlags, VT_12)
DISP_PROPERTY_EX(CVbx1Ctrl, "OleObjectBlob",
GetOleObjectBlob, SetOleObjectBlob, VT_14)
DISP_PROPERTY_EX(CVbx1Ctrl, "cxTHk", GetcxTHk,
SetcxTHk, VT_14)
DISP_PROPERTY_EX(CVbx1Ctrl, "cyTHk", GetcyTHk,
SetcyTHk, VT_14)
DISP_PROPERTY_EX(CVbx1Ctrl, "fFFHk", GetfFFHk,
SetfFFHk, VT_BOOL)
DISP_PROPERTY_EX(CVbx1Ctrl, "DisplayType", GetDisplayType,
SetDisplayType, VT_12)
DISP_PROPERTY_EX(CVbx1Ctrl, "LpOleObject", GetLpOleObject,
SetLpOleObject, VT_14)
DISP_STOCKPROP_BACKCOLOR()
DISP_STOCKPROP_BORDERSTYLE()
DISP_STOCKPROP_ENABLED()
DISP_STOCKPROP_HWND()
DISP_DEFVALUE(CVbx1Ctrl, "Action")
//}}AFX_DISPATCH_MAP
DISP_FUNCTION_ID(CVbx1Ctrl, "AboutBox", DISPID_ABOUTBOX,
AboutBox, VT_EMPTY, VTS_NONE)
END_DISPATCH MAP()
////////////////////////////////////////////////////////////
//

www.books-shop.com

BEGIN_EVENT_MAP(CVbx1Ctrl, COleContro1)
//{{AFX EVENT MAP(CVbx1Ctrl)
// - ClassWizard
// .
//
// !
EVENT_CUSTOM("Resize", FireResize, VTS_PR4 VTS_PR4)
EVENT_CUSTOM("Updated", FireUpdated, VTS_PI2)
EVENT_STOCK_CLICK()
EVENT_STOCK_DBLCLICK()
EVENT_STOCK_KEYDOWN()
EVENT_STOCK_KEYPRESS()
EVENT_STOCK_KEYUP()
EVENT_STOCK_MOUSEDOWN()
EVENT_STOCK_MOUSEMOVE()
EVENT_STOCK_MOUSEUP()
//}}AFX EVENT MAP
END EVENT MAP()
////////////////////////////////////////////////////////////
//
// .
// !
BEGIN PROPPAGEIDS(CVbx1Ctrl, 1) PROPPAGEID(CVbx1PropPage::guid) END
PROPPAGEIDS(CVbx1Ctrl)
//////////////////////////////////////////////////////////
// GUID
IMPLEMENT_OLECREATE_EX(CVbx1Ctrl, "VBX1.Vbx1Ctrl.1",
0x14a99100, 0xa8bf, 0x11ce, 0x99, 0xbf, 0x8, 0xaa, 0x0, 0x47,
0xd4, 0xfd)
/////////////////////////////////////////////////////////////
//
IMPLEMENT_OLETYPELIB(CVbx1Ctrl, _tlid, _wVerMajor, _wVerMinor)
///////////////////////////////////////////////////////////
//
const IID BASED_CODE IID_DVbx1 =
{ 0x14a99101, 0xa8bf, 0x11ce, { 0x99, 0xbf, 0x0, 0xaa,
0x0, 0x47, 0xd4, 0xfd } };
const IID BASED_CODE IID_DVbx1Events =
{ 0x14a99102, 0xa8bf, 0x11ce, { 0x99, 0xbf, 0x0, 0xaa,
0x0, 0x47, 0xd4, 0xfd } };
//////////////////////////////////////////////////////////
//
static const DWORD BASED_CODE _dwVbx10leMisc =
OLEMISC_ACTIVATEWHENVISIBLE |
OLEMISC_SETCLIENTSITEFIRST |
OLEMISC_INSIDEOUT | OLEMISC_CANTLINKINSIDE |
OLENISC_RECOMPOSEONRESIZE;
IMPLEMENT_OLECTLTYPE(CVbx1Ctrl, IDS_VBX1, _dwVbx1OleMisc)
////////////////////////////////////////////////////////////
// CVbx1Ctrl::CVbx1CtrlFactory::UpdateRegistry // CVbx1Ctrl
BOOL CVbx1Ctrl::CVbx1CtrlFactory::UpdateRegistry(BOOL bRegister)
{
if (bRegister)
return AfxOleRegisterControlC1ass(

www.books-shop.com

AfxGetInstanceHandle(),
m_clsid,
m_lpszProgID,
IDS_VBX1,
IDB_VBX1,
FALSE,
//
dwVbx1OleMisc,
_tlid,
_wVerMagor,
_wVerMinor);
else
return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
/////////////////////////////////////////////////////////
// CVbx1Ctrl::CVbx1Ctrl - CVbx1Ctrl::CVbx1Ctrl()

{
InitializeIIDs(&IID_DVbx1, &IID_DVbx1Events);

//
/////////////////////////////////////////////////////////////
// CVbx1Ctrl::~CVbx1Ctrl
CVbx1Ctrl::~CVbx1Ctrl()
{
//
}
//////////////////////////////////////////////////////////////
// CVbx1Ctrl::OnDraw
void CVbx1Ctrl::OnDraw(
CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
{
//
pdc->FillRect(rcBounds,
CBrush::FromHandle((HBRUSH)GetStockObject
(WHITE_BRUSH)));
pdc->E11ipse(rcBounds);
}
/////////////////////////////////////////////////////////////
// CVbx1Ctrl::DoPropExchange -
void CVbx1Ctrl::DoPropExchange(CPropExchange* pPX);
(
ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
COleControl:: DoPropExchange(pPX);
// PX_
PX_String(pPX, _T("Class"), m_strC1ass);
PX_String(pPX, _T("SourceDoc"), m_strSourceDoc);
PX_String(pPX, _T("SourceItem"), m_strSourceItem);
PX_Short(pPX, _T("UpdateOpt1ons"), m_enumUpdateOptions);
PX_String(pPX, _T("HostName"), m_strHostName);
PX_Short(pPX, _T("SizeMode"), m_enumSizeMode);
PX_Short(pPX, _T("AutoActivate"), m_enumAutoActivate);
PX_Bool(pPX, _T("AutoVerbMenu"). m_bAutoVerbMenu):
PX_Short(pPX, _T("OLETypeA1lowed"), m_enumOLETypeA11owed);
PX_Short(pPX, _T("Verb"), m_iVerb);
PX_Short(pPX, _T("MiscFlags"), m_fMiscFlags);
PX_Bool(pPX, _T("fFFHk"), m_bfFFHk),.
PX_Short(pPX, _T("DisplayType"), m_enumDisplayType);

www.books-shop.com

/////////////////////////////////////////////////////////////////
// CVbx1Ctrl::OnResetState -
//
void CVbx1Ctrl::OnResetState()
{
COleControl::OnResetState(); //
// DoPropExchange
//
m_strClass = "";
m_strSourceDoc = "";
m_strSourceItem ="";
m_enumUpdateOptions = 0;
m_strHostName = "";
m_enueSizeHode = 0;
m_enumAutoActivate = 0;
m_bAutoVerbMenu = FALSE;
m_cPicPicture.CreateEmpty();
m_strFormat = "";
m_enumOLETypeAllowed = 0;
m_iVerb = 0;
m_iFileNumber = 0;
m_lHiscFlags = 0;
m_cxcxTHk = 0;
m_cycyTHk = 0;
m_bfFFHk = FALSE;
m_enumDisplayType = 0;
///////////////////////////////////////////////////////////
// CVbx1Ctrl::AboutBox - About
void CVbx1Ctrl::AboutBox()
{
CDialog dlgAbout(IDD_ABOUTBOX_VBX1);
dlgAbout.DoModal();
}
///////////////////////////////////////////////////////////////
CVbx1Ctrl::PreCreateWindowBOOL
CVbx1Ctrl::PreCreateWindow(CREATESTRUCT& cs)
{
//
cs.style |= WS_BORDER;
return COleControl::PreCreateWindow(cs);
}
////////////////////////////////////////////////////////////
// , VBX
BSTR CVbx1Ctrl::GetClass()
{
return SysA1locString(m_strC1ass);
}
void CVbx1Ctrl::SetClass(LPCTSTR pszClass)
{
m_strClass = pszClass;
}
short CVbx1Ctrl::GetOLEType()
{
// PF_fNoShow , (AmbientUserMode
//== FALSE)
//
return 0;
}

www.books-shop.com

void CVbx1Ctrl::SetOLEType(short enumOLEType)


{
// PF_fNoRuntimeW , (Amb1entUserMode
//== TRUE)
//
// DT_ENUM
// }
BSTR CVbx1Ctrl::GetSourceDoc()
{
return SysAllocString(m_strSourceDoc);
}
void CVbx1Ctrl::SetSourceDoc(LPCTSTR pszSourceDoc)
{
m_strSourceDoc = pszSourceDoc;
}
BSTR CVbx1Ctrl::GetSourceItem()
{
return SysAllocString(m strSourceItem);
}
void CVbx1Ctrl::SetSourceItem(LPCTSTR pszSourceItem)
{
m_strSourceItem = pszSourceItem;
}
short CVbx1Ctrl::GetUpdateOptions()
{
return m_enumUpdateOptions;
}
void CVbx1Ctrl::SetUpdateOptions(short enumUpdateOptions)
{
// DT_ENUM
//
//m_enumUpdateOptions = enumUpdateOptions;
}
BSTR CVbx1Ctrl::GetHostName()
{
return SysAllocString(m strHostName);
}
void CVbx1Ctrl::SetHostName(LPCTSTR pszHostName)
{
m strHostName = pszHostName;
}
short CVbx1Ctrl::GetSizeMode()
{
return m_enumSizeMode;
}
void CVbx1Ctrl::SetSizeMode(short enumSizeMode)
{
// DT_ENUM
// m_enumSizeNode = enumSizeMode;
}
BOOL CVbx1Ctrl::GetAppIsRunning()

www.books-shop.com

{
// PF_fNoShow , (AmbientUserNode
//== FALSE)
//
return FALSE;
}
void CVbx1Ctrl::SetAppIsRunning(BOOL bAppIsRunning)
{
// PF_fHoRuntimeW , (AmbientUserMode
//== TRUE)
//
}
LPPICTUREDISP CVbx1Ctrl::GetPicture()
{
// PF_fNoShow , (AmbientUserMode
//== FALSE)
return m cPicPicture.GetPictureDispatch();
}
void CVbx1Ctrl::SetPicture(LPPICTUREDISP pPicPicture)
{
// PF_fNoRuntimeW , (AmbientUserMode
// == TRUE)
m_cPicture.SetPictureDispatch(pPicPicture);
}
LPDISPATCH CVbx1Ctrl::GetObject()
{
// PF_fNoShow , (AmbfentUserMode
//== FALSE)
//
return NULL;
} void CVbx1Ctrl::SetObject(LPDISPATCH pDispObject)
{
// PF_fNoRuntimeW , (AmbientUserMode
//== TRUE)
//
}
long CVbx1Ctrl::GetData()
{
// PF_fNoShow , (AmbientUserMode
//== FALSE) //
return 0;
}
void CVbx1Ctrl::SetData(long 1Data)
{
//
}
BSTR CVbx1Ctrl::GetDataText()
{
// PF_fNoShow , (AmbientUserMode
//== FALSE)
//
return NULL;
}
void CVbx1Ctrl::SetDataText(LPCTSTR pszDataText)
{
//
}
BSTR CVbx1Ctrl::GetFormat()
{

www.books-shop.com

// PF_fNoShow , (AmbientUserMode
//== FALSE)
return SysAllocString(e strFormat);
}
void CVbx1Ctrl::SetFormat(LPCTSTR pszFormat)
{
m_strFormat = pszFormat;
}
BSTR CVbx1Ctrl::GetObjectAcceptFormats(short index)
{
// PF_fNoShow , (AmbientUserMode
//== FALSE)
//
return NULL;
}
void CVbx1Ctrl::SetObjectAcceptFormats(short index,
LPCTSTR pszObjectAcceptFormats)
{
// PF_fNoRuntimeW , (AmbientUserMode
//== TRUE)
//
}
short CVbx1Ctrl::GetObjectAcceptFormatsCount()
{
// PF_fNoShow , (AmbientUserMode
//== FALSE)
//
return 0;
}
void CVbx1Ctrl::SetObjectAcceptFormatsCount(
short iObjectAcceptFormatsCount)
{
// PF_fNoRuntimeW , (AmbientUserMode
//== TRUE)
//
}
BSTR CVbx1Ctrl::GetObjectGetFormats(short index)
{
// PF_fNoShow , (AmbientUserMode
//== FALSE)
//
return NULL;
}
void CVbx1Ctrl::SetObjectGetFormats(short index
LPCTSTR pszObjectGetFormats)
{
// PF_fNoRuntimeW ,
// (AmbientUserMode
//== TRUE)
//
}
short CVbx1Ctrl::GetObjectGetFormatsCount()
{
// PF_fNoShow , (AmbientUserMode
//== FALSE) // return 0;
}
void CVbx1Ctrl::SetObjectGetFormatsCount(
short iObjectGetFormatsCount)

www.books-shop.com

{
// PF_fNoRuntimeW , (AmbientUserMode
//== TRUE)
//
}
BOOL CVbx1Ctrl::GetPasteOK()
{
// PF_fNoShow , (AmbientUserMode
//== FALSE)
// return FALSE;
}
void CVbx1Ctrl::SetPasteOK(BOOL bPasteOK)
{
// PF_fNoRuntimeW , (AmbientUserMode
//== TRUE)
//
}
BSTR CVbx1Ctrl::GetObjectVerbs(short index)
{
// PF_fNoShow , (AmbientUserMode
//== FALSE)
//
return NULL;
}
void CVbx1Ctrl::SetObjectVerbs(short index,
LPCTSTR pszObjectVerbs)
{
// PF_fNoRuntimeW ,
// (AmbientUserMode
//== TRUE)
//
}
long CVbx1Ctrl::Get0bjectVerbFlags(short index)
{
// PF_fNoShow , (AmbientUserMode
//== FALSE)
//
return 0;
}
void CVbx1Ctrl::SetObjectVerbFlags(short index, long
l0bjectVerbF1ags)
{
// PF_fNoRuntimeW , (AmbientUserMode
//== TRUE)
//
}
short CVbx1Ctrl::GetObjectVerbsCount()
{
// PF_fNoShow , (AmbientUserMode
//== FALSE)
//
return 0;
void CVbx1Ctrl::SetObjectVerbsCount(short iObjectVerbsCount)
{
// PF_fNoRuntimeW , (AmbientUserMode
//== TRUE)
%RRNVVKRS

piracy@books-shop.com

//
}
short CVbx1Ctrl::GetFi1eNumber()
{
// PF_fNoShow , (AmbientUserMode
//== FALSE)
return m_iFileNumber;
}
void CVbx1Ctrl::SetFileNumber(short lFileNumber)
{
m_iFileNumber = iF11eNumber;
}
short CVbx1Ctrl::GetAction()
{
// PF_fNoRuntimeR/PF_fNoShow
//
return 0;
}
void CVbx1Ctrl::SetAction(short iAction)
{
// }
long CVbx1Ctrl::Get0le0bjectBlob()
{
// PF_fNoRuntimeR/PF_fNoShow
//
return 0;
}
void CVbx1Ctrl::SetOleObjectBlob(long l0leObjectBlob)
{
// PF_fNoRuntimeW , (AmbientUserMode
//== TRUE)
//
}
long CVbx1Ctrl::GetcxTHk()
{
// PF_fNoShow , (AmbientUserMode
//== FALSE)
return m_cxcxTHk;
}
void CVbx1Ctrl::SetcxTHk(long cxcxTHk)
{
m cxcxTHk = cxcxTHk;
}
long CVbx1Ctrl::GetcyTHk()
{
// PF_fNoShow , (AmbientUserMode
//== FALSE)
return m cycyTHk;
}
void CVbx1Ctrl::SetcyTHk(long cycyTHk)
{
m cycyTHk = cycyTHk;
}

www.books-shop.com

BOOL CVbx1Ctrl::GetfFFHk()
{
// PF_fNoShow , (AmbientUserMode
//== FALSE)
return m_bfFFHk;
}
void CVbx1Ctrl::SetfFFHk(BOOL bfFFHk)
{
m_bfFFHk = bfFFHk;
}
short CVbx1Ctrl::GetDisplayType()
{
return m_enumDisplayType;
}
void CVbx1Ctrl::SetDisplayType(short enumDisplayType)
{
// DT_ENUM
//
//
m_enumDisp1ayType = enumDisplayType;
}
long CVbx1Ctrl::GetLpOleObject()
{
// PF_fNoShow , (AmbientUserMode
//== FALSE)
//
return 0;
}
void CVbx1Ctrl::SetLpOleObject(long 1LpOleObject)
{
// PF_fNoRuntimeW , (AmbientUserMode
//== TRUE)
//
}
/////////////////////////////////////////////////////////////////////
// CVbx1Ctrl
, - . ,
, OLE ControlWizard ,
VBX
ActiveX. , SetLpOleObject 18-3 ,
, VBX PF_fNoRuntimeW (
, ,
). ActiveX,
UserMode; TRUE (
), . ,
SetNotSupported,
Automation.
, ,
, . , DoPropExchange
, VBX
.

18.3 VBX
VBX ActiveX :

www.books-shop.com

1.
2.
3.

, VBX
VBGetModelInfo.
ActiveX 16- OLE ControlWizard.
Control Options (. 18-1) Use VBX Control As
Template VBX Select VBX Control.

.18-1. Control Options 16- OLE ControlWizard


4.

Use VBX Control As Template VBX


Browse .
5. VBX- ,
Control Name.
6. , (,
Windows).
7. , , OK .
8. 32- , Visual C++ 4.x
. (, OC25)
, ,
32- OLE ControlWizard.
9. ,
VBX.

. VBX Visual Basic


, MODELINFO. Visual Basic
, VBGetModelInfo. ,
Visual Basic (
MODELINFO,
). MODELINFO MODEL,
NULL.
MODEL ,
ActiveX (,
).
, , , .
, Windows
API CreateWindow. PreCreateWindow,
.
VBX WS_BORDER.
. 18-1 MODEL, OLE
ControlWizard VBX .

www.books-shop.com

18-1. MODEL, OLE ControlWizard


(
VBAPI.H)

MODEL_fArrows


( , Home
PgDn) SendMessage
PreTranslateMessage .
SendMessage
CallWindowProc.

MODEL_fChildrenOk 8

(. 17).

MODEL_fDesInteract 64


. UI (, , Visual Basic),
(,
OLE Edit).

MODEL_fFocusOk

,
.
( - ), , ,
,
OLEMISC_ ACTSLIKELABEL.

256

, VBX .

ActiveX,
VBX,
, .
VBX
.

16

VBX VBM_ INITIALIZE.


ActiveX
,
(
OnResetState).

MODEL_fGraphical

MODEL_fInitMsg

MODEL_fInvisAtRun 128

,
, OLE ControlWizard
OLEMISC_INVISIBLEATRUNTIME.
VBX ,
, ActiveX .
,
ActiveX.

MODEL_fLoadMsg

32

, VBX
.
ActiveX ,
.

ActiveX

VBM_ISMNEMONIC.
3.

MODEL_fMnemonic

CoClass .
, CoClass ODL- ,
npszClassName MODEL. ActiveX
VBX, Visual Basic
VBX ActiveX.
Windows,
npszParentClassName MODEL -
PreCreateWindow. nDefProp
MODEL , , nValueProp
. ActiveX .

www.books-shop.com

VBX OLE ControlWizard nValueProp


DISP_DEFVALUE. ActiveX
, VBX, nDefEvent .

18.4 ,
VBX ,
, (programmer-defined structure).
, ,
, VBX.
. OLE ControlWizard
,
. - OLE
, :

short m_iMiscFlags;
, ,
/.
:

CString m_strClass;

VBX. VBX ,
, () ,
.
.
VBX Visual Basic ,
.
OnResetState
. runtime C _memset .

18.5
VBX ,
Windows, VBX,
ActiveX. (, WM_PAINT)
ActiveX. ClassWizard,
- . , (,
Visual Basic) ActiveX
; , , WM_CREATE,
.
ClassWizard, .
Windows, VBX
Visual Basic, VBN_xxx. ActiveX
OCM_xxx.
, ClassWizard -
. ClassWizard
Windows, VBX.
VBX VBDefControlProc,
, ,
ClassWizard. , ClassWizard
WM_SIZE (OnSize) ,
. VBX WM_SIZE VBDefControlProc
, ClassWizard
ActiveX.

www.books-shop.com

18.6 VBM-
Visual Basic VBX , VBM-. ,
ActiveX , ActiveX
Visual Basic .
VBX VBM-.
, . ,
Automation.
. , Visual Basic ,
, VBX
VBM_CHECKPROPERTY. ActiveX
, , !
COM ActiveX , VBM-
.
Visual Basic : ,
ActiveX, , Visual Basic.
Visual Basic 3.0
VBM_DATA_ GET , .

Visual Basic 4.0
Visual Basic.

18.7
, - , -
! , ,
VBX ,
ActiveX. ActiveX ; ,
VBX .

18.8 ,

VBX ActiveX.
.
VBX ,
. , Refresh, ActiveX.
ClassWizard
. , , VBX,
ActiveX ,
. , ( !)
ActiveX.
Align, ,
. ,
Align ,
OLEMISC_ALIGNABLE. BorderStyle
,
. , VBX
PROPINFO_STD_BORDERSTYLEON
1 ( ).
VBX Caption Text . ActiveX
, , .
, MousePointer MouseIcon .
ActiveX,
.

www.books-shop.com

ActiveX ,
VBX. VBX (, FontBold
FontName), ActiveX Font,
. OLE ControlWizard
, Font Fontxxx,
VBX. ,
Font.
ActiveX , VBX.
DATASTRUCT,
, .
, VBX ,
.
short,
, .

18.9 Visual Basic API


VBX Visual Basic API,
VBAPI.H.
: , Visual Basic
C , MFC CString ( ,
Visual Basic, Automation BSTR). ,
MFC,
Automation, Automation SAFEARRAY.
, API,
ActiveX. , API

(DDE).
, Visual Basic COM, ActiveX.
, IVBFormat, IVBDDE IVBFiles. :
, . ?
Visual Basic, , ,
, Visual Basic for Applications (VBA).
Visual Basic (, , VBA),
.
, COM- , ,
(, ). ,
QueryInterface , ,
, QueryInterface , c -
. ,
QueryInterface ,
. , ,
Visual Basic, , ,
NULL. Visual Basic
.

18.10
, .
, . Microsoft
OLE CDK. VBX,
MODELINFO, OLE ControlWizard Visual C++.
, .
, !
. VBX, VBX
(common controls).
; -

www.books-shop.com

Get Set. , .
, , VBX
C++ , .
, , ,
. (About),
AboutBox.
, OLE ControlWizard ,
. ,
256 , . , 256
. , 15 ,
15- .

( 1995 ) Microsoft
VBX ActiveX Microsoft Developer Network (MSDN) .
. ,
MSDN.

18.11 Windows
, , ?
? ,
Windows ,
. OLE ControlWizard
Subclass Windows Control. ,
Windows, Win32.
, , ,
, ,
.
, OLE ControlWizard, ,
ActiveX,
. .
:

//
BOOL PreCreateWindow(CREATESTRUCT& cs);
BOOL IsSubclassedControl();
LRESULT OnOcmCommand(WPARAM wParam, LPARAM lParam);
18-4 .
18-4. , OLE ControlWizard ActiveX,

/////////////////////////////////////////////////////////////////////////////
// CSubclassCtrl::PreCreateWindow
// - CreateWindowEx
BOOL CSubclassCtrl::PreCreateWindow(CREATESTRUCT& cs)
{
cs.lpszClass = _T("EDIT");
return COleControl::PreCreateWindow(cs);
}
//////////////////////////////////////////////////////////////
// CSubclassCtrl::IsSubclassedControl -

www.books-shop.com

BOOL CSubclassCtrl::IsSubclassedControl()
{
return TRUE;
}
/////////////////////////////////////////////////////////////
// CSubclassCtrl::OnOcmCommand -
LRESULT CSubclassCtrl::OnOcmCommand(WPARAM wParam, LPARAM lParam)
{
#ifdef _WIN32
WORD wNotifyCode = HIWORD(wParam);
#else
WORD wNotifyCode = HIWORD(lParam);
#endif
// wNotifyCode
return 0;
}
, 18-4. PreCreateWindow,
, MFC, .
,
MFC. Edit,
Windows.
IsSubclassedControl , ,
. ,
TRUE.
OnOcmCommand OCM-, ,
, MFC.
,
.
Windows , COM (,
). ,
Windows ( MessageReflect
TRUE), MFC
. Microsoft
(
).
, OnOcmCommand .
switch, OCM-
.
.
ClassWizard OCM_COMMAND.
(, BN_CLICKED ).
,
OCM_MEASUREITEM, OCM_ COMPAREITEM OCM_DRAWITEM,
. ,
, .
ClassWizard OCM-,
.
, , OnDraw.
, OnDraw
DoSuperclassPaint COleControl ,
:

///////////////////////////////////////////////////////////////

www.books-shop.com

// CSubclassCtrl::OnDraw -
void CSubclassCtrl::OnDraw(CDC* pdc,
const CRect& rcBounds, const CRect& rcInvalid)
{
DoSuperclassPaint(pdc, rcBounds);
}
,
WM_PAINT
, .
,
. . ,
,
, .
:
,
OR cs.style cs.dwExStyle CREATESTRUCT,
PreCreateWindow. , ,
, ES_LOWERCASE.

18.12 Children
14, , Children c
. , ,
,
(, Visual Basic ) . .18-2.

.18-2. Children,

14 , ,
. ,
Children!
Children ? ,

.

%RRNVVKRS

piracy@books-shop.com

, , Children ( 2) 14
, (
Children ), Children
Automation. ,
. , Children ,
,
. Children ,
, Children.
,
Children.
, :

Children ,
Children ,
.
Children (,
Visual Basic).

, , Children
. ,
.
( 18-5) ( 18-6). ,
RESOURCE.H,
. CD-ROM
\CODE\CHAP18\CHILDRN3.
18-5. Children

// ChildCtl.h : OLE CChildrenCtrl


////////////////////////////////////////////////////////////
// CChildrenCtrl : ChildCtl.cpp
class CChildrenCtrl : public COleControl
{
DECLARE_DYNCREATE(CChildrenCtrl)
//
public:
CChildrenCtrl();
//
// ,
// ClassWizard
//{{AFX_VIRTUAL(CChildrenCtrl)
public:
virtual void OnDraw(CDC* pdc, const CRect& rcBounds,
const CRect& rcInvalid);
virtual void DoPropExchange(CPropExchange* pPX);
virtual void OnResetState();
protected:
virtual void OnDrawMetafile(CDC* pDC, const CRect& rcBounds);
//}}AFX_VIRTUAL
virtual void OnFontChanged();
//
protected:
~CChildrenCtrl();
DECLARE_OLECREATE_EX(CChildrenCtrl)
DECLARE_OLETYPELIB(CChildrenCtrl) //
DECLARE_PROPPAGEIDS(CChildrenCtrl)//
//
DECLARE_OLECTLTYPE(CChildrenCtrl) //
//

// guid
GetTypeInfo

www.books-shop.com

//
//
//{{AFX_MSG(CChildrenCtrl)
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
//}}AFX_MSG
afx_msg void OnValidate();
DECLARE_MESSAGE_MAP()
//
//{{AFX_DISPATCH(CChildrenCtrl)
afx_msg LPFONTDISP GetEditFont();
afx_msg void SetEditFont(LPFONTDISP newValue);
afx_msg BSTR GetEditText();
afx_msg void SetEditText(LPCTSTR lpszNewValue);
//}}AFX_DISPATCH
DECLARE_DISPATCH_MAP()
afx_msg void AboutBox();
//
//{{AFX_EVENT(CChildrenCtrl)
void FireBeforeValidation()
{FireEvent(eventidBeforeValidation,EVENT_PARAM(VTS_NONE));}
void FireValidated(BOOL Success)
{FireEvent(eventidValidated,EVENT_PARAM(VTS_BOOL), Success);}
//}}AFX_EVENT
DECLARE_EVENT_MAP()
CButton m_btnValidate;
CEdit m_editEntry;
CRect m_rBtn;
CRect m_rEdit;
CFontHolder m_fontEdit;
CWnd m_HiddenWnd;
CString m_strEditText;
void ChangeEditFont();
int CreateChildren(CWnd *pThis);
void DrawButton(CDC *pdc, const CRect &rcBounds);
void DrawEditbox(CDC *pdc, const CRect &rcBound);
CWnd * CreateHiddenWindow();
BEGIN_INTERFACE_PART(EditFontNotify, IPropertyNotifySink)
INIT_INTERFACE_PART(CChildrenCtrl, EditFontNotify)
STDMETHOD(OnRequestEdit)(DISPID);
STDMETHOD(OnChanged)(DISPID);
END_INTERFACE_PART(EditFontNotify)
//
public:
enum {
//{{AFX_DISP_ID(CChildrenCtrl)
dispidEditFont = 1L,
dispidEditText = 2L,
eventidBeforeValidation = 1L,
eventidValidated = 2L,
//}}AFX_DISP_ID
};
};
#define IDC_VALIDATE 1
#define IDC_ENTRY 2

. ,
. :

www.books-shop.com

m_HiddenWnd CWnd ,
Children.
m_strEditText CString.
,
.

18-6. Children

// ChildCtl.cpp : OLE CChildrenCtrl


#include "stdafx.h"
#include "Children.h"
#include "ChildCtl.h"
#include "ChildPpg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
IMPLEMENT_DYNCREATE(CChildrenCtrl, COleControl)
/////////////////////////////////////////////////////////////
//
BEGIN_MESSAGE_MAP(CChildrenCtrl, COleControl)
//{{AFX_MSG_MAP(CChildrenCtrl)
ON_WM_CREATE()
//}}AFX_MSG_MAP
ON_OLEVERB(AFX_IDS_VERB_PROPERTIES,OnProperties)
ON_BN_CLICKED(IDC_VALIDATE, OnValidate)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////
//
BEGIN_DISPATCH_MAP(CChildrenCtrl, COleControl)
//{{AFX_DISPATCH_MAP(CChildrenCtrl)
DISP_PROPERTY_EX(CChildrenCtrl, "EditFont", GetEditFont,
SetEditFont, VT_FONT)
DISP_PROPERTY_EX(CChildrenCtrl, "EditText", GetEditText,
SetEditText, VT_BSTR)
DISP_DEFVALUE(CChildrenCtrl, "EditText")
DISP_STOCKPROP_BACKCOLOR()
DISP_STOCKPROP_FONT()
DISP_STOCKPROP_FORECOLOR()
//}}AFX_DISPATCH_MAP
DISP_FUNCTION_ID(CChildrenCtrl, "AboutBox", DISPID_ABOUTBOX,
AboutBox, VT_EMPTY, VTS_NONE)
END_DISPATCH_MAP()
//////////////////////////////////////////////////////////////
//
BEGIN_EVENT_MAP(CChildrenCtrl, COleControl)
//{{AFX_EVENT_MAP(CChildrenCtrl)
EVENT_CUSTOM("BeforeValidation",
FireBeforeValidation, VTS_NONE)
EVENT_CUSTOM("Validated", FireValidated, VTS_BOOL)
//}}AFX_EVENT_MAP
END_EVENT_MAP()
/////////////////////////////////////////////////////////////
//
// .
// !
BEGIN_PROPPAGEIDS(CChildrenCtrl, 3)

www.books-shop.com

PROPPAGEID(CChildrenPropPage::guid)
PROPPAGEID(CLSID_CColorPropPage)
PROPPAGEID(CLSID_CFontPropPage)
END_PROPPAGEIDS(CChildrenCtrl)
///////////////////////////////////////////////////////////////
// GUID
IMPLEMENT_OLECREATE_EX(CChildrenCtrl, "CHILDREN.ChildrenCtrl.1",
0xb0f95364, 0x125e, 0x11d0, 0xb7, 0xef, 0, 0x80, 0xc7,
0x7a, 0xf8, 0x82)
///////////////////////////////////////////////////////////////
//
IMPLEMENT_OLETYPELIB(CChildrenCtrl, _tlid, _wVerMajor, _wVerMinor)
///////////////////////////////////////////////////////////////
//
const IID BASED_CODE IID_DChildren =
{ 0xb0f95362, 0x125e, 0x11d0, { 0xb7, 0xef, 0, 0x80, 0xc7,
0x7a, 0xf8, 0x82 } };
const IID BASED_CODE IID_DChildrenEvents=
{ 0xb0f95363, 0x125e, 0x11d0, { 0xb7, 0xef, 0, 0x80, 0xc7,
0x7a, 0xf8, 0x82 } };
//////////////////////////////////////////////////////////////
//
static const DWORD BASED_CODE _dwChildrenOleMisc =
OLEMISC_ACTIVATEWHENVISIBLE |
OLEMISC_SETCLIENTSITEFIRST |
OLEMISC_INSIDEOUT |
OLEMISC_CANTLINKINSIDE |
OLEMISC_RECOMPOSEONRESIZE;
IMPLEMENT_OLECTLTYPE(CChildrenCtrl, IDS_CHILDREN,
_dwChildrenOleMisc)
static const FONTDESC _fontdescEdit =
{ sizeof(FONTDESC), L"Arial", FONTSIZE(10), FW_NORMAL,
ANSI_CHARSET, FALSE, FALSE, FALSE };
/////////////////////////////////////////////////////////////
// CChildrenCtrl::CChildrenCtrlFactory::UpdateRegistry // CChildren1Ctrl
BOOL CChildrenCtrl::CChildrenCtrlFactory::UpdateRegistry(
BOOL bRegister)
{
// ,
// .
// MFC TechNote 64.
// ,
//
// 6- afxRegApartmentThreading 0.
if (bRegister)
return AfxOleRegisterControlClass(
AfxGetInstanceHandle(),
m_clsid,
m_lpszProgID,
IDS_CHILDREN,
IDB_CHILDREN,
afxRegApartmentThreading,
_dwChildrenOleMisc,
_tlid,
_wVerMajor,
_wVerMinor);
else
return AfxOleUnregisterClass(m_clsid, m_lpszProgID);

www.books-shop.com

}
//////////////////////////////////////////////////////////////
// CChildrenCtrl::CChildrenCtrl -
CChildrenCtrl::CChildrenCtrl() : m_fontEdit(&m_xFontNotification)
{
InitializeIIDs(&IID_DChildren, &IID_DChildrenEvents);
m_rBtn = CRect(3, 3, 103, 27);
m_rEdit = CRect(3, 30, 103, 60);
SetInitialSize(m_rBtn.right + m_rBtn.left,
m_rEdit.bottom + m_rBtn.top);}
/////////////////////////////////////////////////////////////
// CChildrenCtrl::~CChildrenCtrl -
CChildrenCtrl::~CChildrenCtrl()
{
if (m_HiddenWnd.GetSafeHwnd())
{
m_HiddenWnd.DestroyWindow();
}
}
/////////////////////////////////////////////////////////////
// CChildrenCtrl::OnDraw -
void CChildrenCtrl::OnDraw(
CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
{
CBrush cbBack(TranslateColor(GetBackColor()));
pdc->FillRect(rcBounds, &cbBack);
// ,
//
if (GetSafeHwnd() == 0)
{
if (m_editEntry.GetSafeHwnd() == NULL &&
m_btnValidate.GetSafeHwnd() == NULL)
{
// ,
if (CreateChildren(0) == -1)
{
return;
}
}
// ,
//
// .
// DC ,
// .
DrawButton(pdc, rcBounds);
DrawEditbox(pdc, rcBounds);
}
}
////////////////////////////////////////////////////////////
// CChildrenCtrl::DoPropExchange -
void CChildrenCtrl::DoPropExchange(CPropExchange* pPX)
{
ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
COleControl::DoPropExchange(pPX);
PX_Font(pPX, _T("EditFont"), m_fontEdit, &_fontdescEdit);
if (pPX->IsLoading())
{

www.books-shop.com

ChangeEditFont();
PX_String(pPX, _T("EditText"), m_strEditText);
if (m_editEntry.GetSafeHwnd())
{
m_editEntry.SetWindowText(m_strEditText);
}
}
else
{
if (m_editEntry.GetSafeHwnd())
{
m_editEntry.GetWindowText(m_strEditText);
}
PX_String(pPX, _T("EditText"), m_strEditText);
}
}
//////////////////////////////////////////////////////////////
// CChildrenCtrl::OnResetState -
void CChildrenCtrl::OnResetState()
{
COleControl::OnResetState();//
// DoPropExchange
//
}
/////////////////////////////////////////////////////////////
// CChildrenCtrl::AboutBox - About
void CChildrenCtrl::AboutBox()
{
CDialog dlgAbout(IDD_ABOUTBOX_CHILDREN);
dlgAbout.DoModal();
}
/////////////////////////////////////////////////////////////
// CChilrenCtrl
LPFONTDISP CChildrenCtrl::GetEditFont()
{
return m_fontEdit.GetFontDispatch();
}
void CChildrenCtrl::SetEditFont(LPFONTDISP newValue)
{
m_fontEdit.InitializeFont(&_fontdescEdit, newValue);
ChangeEditFont();
SetModifiedFlag();
}
int CChildrenCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (COleControl::OnCreate(lpCreateStruct) == -1)
return -1;
return CreateChildren(this);
}
void CChildrenCtrl::OnValidate()
{
FireBeforeValidation();
m_editEntry.GetWindowText(m_strEditText);
BOOL bRet = m_strEditText.Find(_T(" ")) == -1;
FireValidated(bRet);
}

www.books-shop.com

void CChildrenCtrl::OnFontChanged()
{
ChangeEditFont();
COleControl::OnFontChanged();
}
void CChildrenCtrl::ChangeEditFont()
{
if (m_editEntry.GetSafeHwnd())
{
m_editEntry.SendMessage(WM_SETFONT,
(WPARAM)m_fontEdit.GetFontHandle(),
TRUE);
}
}
STDMETHODIMP_(ULONG) CChildrenCtrl::XEditFontNotify::AddRef()
{
METHOD_MANAGE_STATE(CChildrenCtrl, EditFontNotify)
return 1;
}
STDMETHODIMP_(ULONG) CChildrenCtrl::XEditFontNotify::Release()
{
METHOD_MANAGE_STATE(CChildrenCtrl, EditFontNotify)
return 0;
}
STDMETHODIMP CChildrenCtrl::XEditFontNotify::QueryInterface(
REFIID iid, LPVOID *ppvObj)
{
METHOD_MANAGE_STATE(CChildrenCtrl, EditFontNotify)
if (IsEqualIID(iid, IID_IUnknown) ||
IsEqualIID(iid, IID_IPropertyNotifySink))
{
*ppvObj = this;
AddRef();
return NOERROR;
}
return ResultFromScode(E_NOINTERFACE);
}
STDMETHODIMP CChildrenCtrl::XEditFontNotify::OnChanged(DISPID)
{
METHOD_MANAGE_STATE(CChildrenCtrl, EditFontNotify)
pThis->ChangeEditFont();
return NOERROR;
}
STDMETHODIMP CChildrenCtrl::XEditFontNotify::
OnRequestEdit(DISPID)
{
return NOERROR;
}
BSTR CChildrenCtrl::GetEditText()
{
if (m_editEntry.GetSafeHwnd())
{
m_editEntry.GetWindowText(m_strEditText);
return m_strEditText.AllocSysString();
}
else
{

www.books-shop.com

ThrowError(CTL_E_ILLEGALFUNCTIONCALL, IDS_NOEDITCTRL);
return NULL;
}
}
void CChildrenCtrl::SetEditText(LPCTSTR lpszNewValue)
{
if (m_editEntry.GetSafeHwnd())
{
m_editEntry.SetWindowText(lpszNewValue);
SetModifiedFlag();
}
else
{
ThrowError(CTL_E_ILLEGALFUNCTIONCALL, IDS_NOEDITCTRL);
}
}
void CChildrenCtrl::OnDrawMetafile(CDC* pDC,
const CRect& rcBounds)
{
COleControl::OnDrawMetafile(pDC, rcBounds);
DrawButton(pDC, rcBounds);
DrawEditbox(pDC, rcBounds);
}
int CChildrenCtrl::CreateChildren(CWnd *pThis)
{
// NULL,
//
if (pThis == 0)
{
pThis = CreateHiddenWindow();
if (pThis == 0)
{
return -1;
}
}
// ,
if (m_btnValidate.GetSafeHwnd())
{
m_btnValidate.SetParent(pThis);
}
else
{
CString s;
s.LoadString(IDS_BUTTONCAPTION);
if (m_btnValidate.Create(s, BS_PUSHBUTTON | WS_VISIBLE,
m_rBtn,
pThis,
IDC_VALIDATE) == FALSE)
{
MessageBox(_T("Could not create button"));
return -1;
}
}
if (m_editEntry.GetSafeHwnd())
{
m_editEntry.SetParent(pThis);
}
else
{
if (m_editEntry.Create(ES_AUTOHSCROLL | WS_BORDER |

www.books-shop.com

WS_VISIBLE,
m_rEdit,
pThis,
IDC_ENTRY) == FALSE)
{
MessageBox(_T("Could not create edit box"));
return -1;
}
m_editEntry.SetWindowText(m_strEditText);
}
ChangeEditFont();
return 0;
}
void CChildrenCtrl::DrawButton(CDC *pdc, const CRect& rcBounds)
{
CPen pBlack(PS_SOLID, 1, COLORREF(RGB(0, 0, 0)));
CPen pDark(PS_SOLID, 1, ::GetSysColor(COLOR_BTNSHADOW));
CPen pLite(PS_SOLID, 1, ::GetSysColor(COLOR_BTNHIGHLIGHT));
CPen *pOld = pdc->SelectObject(&pBlack);
CRect rBox = m_rBtn;
rBox += CPoint(rcBounds.left, rcBounds.top);
CString s;
s.LoadString(IDS_BUTTONCAPTION);
CBrush
pdc ->
pdc ->
pdc ->
pdc ->
pdc ->
pdc ->
pdc ->
pdc ->
pdc ->
pdc ->
pdc ->
pdc ->

bFace(::GetSysColor(COLOR_BTNFACE));
FillRect(rBox, &bFace);
MoveTo(rBox.left, rBox.bottom);
LineTo(rBox.right - 1, rBox.bottom);
LineTo(rBox.right - 1, rBox.top - 2);
SelectObject(&pDark);
MoveTo(rBox.left + 1, rBox.bottom - 1);
LineTo(rBox.right - 2, rBox.bottom - 1);
LineTo(rBox.right - 2, rBox.top - 1);
SelectObject(&pLite);
MoveTo(rBox.left, rBox.bottom - 1);
LineTo(rBox.left, rBox.top - 1);
LineTo(rBox.right - 1, rBox.top - 1);

rBox.InflateRect(-1, -1);
int nMode = pdc -> SetBkMode(TRANSPARENT);
pdc -> DrawText(s, -1, rBox,
DT_CENTER | DT_VCENTER | DT_SINGLELINE);
pdc -> SelectObject(pOld);
pdc -> SetBkMode(nMode);
}
void CChildrenCtrl::DrawEditbox(CDC *pdc, const CRect& rcBounds)
{
CPen pBlack(PS_SOLID, 1, COLORREF(RGB(0, 0, 0)));
CBrush bWhite(COLORREF(RGB(255, 255, 255)));
CPen *pOld = pdc -> SelectObject(&pBlack);
CBrush *bOld = pdc -> SelectObject(&bWhite);
CRect rBox = m_rEdit;
rBox += CPoint(rcBounds.left, rcBounds.top);
CString s;
m_editEntry.GetWindowText(s);
pdc -> Rectangle(&rBox);
rBox.InflateRect(-1, -1);
CFont *fOld = pdc ->
SelectObject(CFont::FromHandle(m_fontEdit.GetFontHandle()));
pdc -> DrawText(s, -1,

www.books-shop.com

rBox,
DT_LEFT | DT_VCENTER | DT_NOPREFIX |
DT_SINGLELINE);
pdc -> SelectObject(pOld);
pdc -> SelectObject(bOld);
pdc -> SelectObject(fOld);
}
CWnd * CChildrenCtrl::CreateHiddenWindow()
{
if (m_HiddenWnd.GetSafeHwnd() == 0)
{
m_HiddenWnd.CreateEx(0, AfxRegisterWndClass(0),
"", 0, 0, 0, 0, 0, 0, 0);
}
return &m_HiddenWnd;}
,
. OnDraw Children
, , .
CreateChildren 0.
CreateChildren, 0
. ,
DrawButton DrawEditBox ( ).
DoPropExchange 14.
, ,
DoPropExchange (,
DoPropExchange ). ,
,
m_strEditText. , .
DoPropExchange ,
( ) .
, .
OnCreate, WM_CREATE,
, , CreateChildren this
Children.
OnValidate m_strEditText ()
, GetEditText,
EditText. OnDrawMetafile ,
DrawButton DrawEditBox. ,
,
, OnDrawMetafile !
CreateChildren , 0. ,
.
CreateHiddenWindow ( ,
). , Children .
, Children
( ),
( WM_CREATE
Children),
. Children ,
.
CreateHiddenWindow, . ,
:
Children, DrawButton. ,
m_strEditText,
, DoPropExchange.
DrawButton .
, Windows
wParam WM_PAINT,
. ,

%RRNVVKRS

piracy@books-shop.com

. ,
DC. ,
. ,
Windows 95, . ,
COLOR_BTNTEXT.
, . ,
DrawButton ,
COLOR_ BTNFACE , .
(IDS_BUTTONCAPTION,
) DrawText, &
.
DrawEditbox , .
:
( !); DT_NOPREFIX DrawText,
& ,
RGB-
GDI, ::GetStockObject. ,
.
CreateHiddenWindow. ,
. ,
CWnd::CreateEx. CreateEx,
, , (pop-up)
(overlapped). CWnd::Create .
AfxRegisterWndClass ( ,
), CreateEx 0!
WS_VISIBLE , 00 .
, ,
Children (
, , ,
), , -
, File|Save Property Set.
, TMP.DFL.
, File|Load
Property Set. , ,
. ! ( . 18-3.) ,
,
.

www.books-shop.com

.18-3.UI- Children , (
)

www.books-shop.com

19

16/32-
Microsoft, ,
, 32-.
, 32-
, 16- ( Intel).
32- ,
,
32- .
Microsoft Windows 3.x ,
.
Windows 95,
Windows 16- . 32 .
, .
,
, ,
.
, 1999 16-
, ,
32- .
.
32- ,
32- Windows.
32- ,
Windows 95 Windows NT 4.0 32-
Microsoft Visual Basic 4.0. ,
16-, 32- Windows,
.
16- , 16- .
, ActiveX 32- . Microsoft Visual C++ 4.0
MFC ( 4.0) ActiveX
, 32- . COM
, (, OLE
OLE), , 16- .
,
(COM), 32 .
, 16- ? ,
,
32- .
, .
16- 32- ,
32- ,
16- . , .

19.1 -
-
ActiveX Windows

www.books-shop.com

Intel-. , Visual C++, Windows NT RISC (, PowerPC, DEC Alpha MIPS R4400), MFC,
. ,

Windows NT RISC- (, ).
ATL Intel-,
Microsoft . ,
- Java , ,
Java , Java VM (
) COM. Microsoft
Win32 Intel-. Microsoft MetroWerks
Macintosh- VM, .
, Microsoft VM
UNIX, VM COM Windows 3.1 (
).
Java Windows ( Java), Microsoft
Sun .
COM VM.
Visual C++ 4.0 Mac , Intel PC,
PowerPC 680x0 Macintosh
MFC, Macintosh
Win32.
WLM (Windows Libraries for Macintosh),
Win32 Macintosh. PowerMac COM OLE,
Automation . WLM
Mac ActiveX. Microsoft MetroWerks , Macintosh
ActiveX WLM.
Microsoft Windows (
COM ActiveX 32- ) MFC,
. 1996
, MFC Win32
UNIX-. UNIX COM ActiveX.
, UNIX
ActiveX, Windows-
.
( 1996 )
, - . ,
.
( ),
( RISC-
8- ,
,
).

19.2 32- 16-


, ActiveX 32 16- . ,
Microsoft,
. , Visual C++ 16- (1.52)
32- ( 4.2, 1997 5.0)
. , 16- ,
MFC ( OLE CDK),
MFC ,
OCX 96 ActiveX.
, .
, COM ActiveX 32 . , 16- ,
OCX 96.

www.books-shop.com

ActiveX SDK, .
COM- (DCOM).
16- Microsoft Internet Explorer 3.0 Windows 3.1.
, .
,
32- 16- .

19.3
,
.
.
( ,
) . ,
, ,
. , 8- (, Z80)
, 64 . 16- (, 8086 80286)
, 16- ( 2) . Intel 80386 ,
32- .
C++ ,
.
16- Windows ( ,
, Windows 3.x)
1- , .
, , .
, ( !) .
!

, - 3 . Visual C++
64- (8-) ,
-
C++ (, ).
ActiveX , , !
, 1-
, .
Microsoft C++ #pragma pack.

19.4 Unicode, ANSI MCBS


3 Unicode, . , Unicode
16- . ANSI
8 . MCBS ( , multi-byte character set)
, .
32- COM, ,
Unicode. Windows NT Unicode,
API, , :
Unicode, ANSI-, -
Unicode. Unicode- , , Windows NT ANSI. Windows 95 MCBS/ANSI,
Unicode API Windows NT. ,
, Unicode ANSI MCBS.
Windows 95 32- COM,
Unicode. , Windows 95 ActiveX COM Unicode.
MFC : Unicode,
ANSI/MCBS. Windows NT, ,

www.books-shop.com

, Win32. Unicode ANSI


Windows NT , ANSI-
Windows NT , Unicode.
COM Windows 95 32- , ,
Unicode, .
Windows Unicode,
ANSI Unicode API. ,
.
16- Windows,
, , 16-
Windows, COM MFC ANSI MCBS. Visual C++
1.51 , 32- Visual C++,
Unicode , :

_T("This is a string")

, 16- Visual C++ .


Unicode ,
. Unicode
, .

. , .

19.5
16-
. , 16- 16 ,
32 32- . , 32-
(, ) 16- ,
. 32 , 16-,
. 32- ,
, 16- . 32-
(
), 16- .
.
32- , 16 .
, .
MFC Windows ,
.

19.6 API
Microsoft Windows API 32- ,
. - ,
, . ,
Windows, wParam lParam. 32-
32 , 16- wParam 16 .
16- Windows , lParam
16- , (, WM_COMMAND)
wParam lParam , 32-
. , .
, .
MFC.
API, Windows
32- ( 16 ), 32 32- .
16- API, 16-
, ,

www.books-shop.com

. MFC
,
API, 32- 16-,
Win32 .
MoveTo, MoveToEx.
, API, 32-
, 16- Windows.
,
, , COM.

19.7 Windows
Windows 16- 32- .
,
Windows 95 Windows NT 4.0 1996 ,
16- .
, INI-
Windows 3.x.
.
, ,
, , ; ,
, Windows 95 Windows NT 3.51 (
Win32s 1.30).
32- ,
Windows 95 . .
, Microsoft Windows-.
16- .
, .
. , Windows 95 Windows NT
. ,
(, ),
. 16- ,
.
, -
. Win32 ( Win32s)
, 16- Windows
.
.
Win32 , 16-
. - 16-
.

19.8
Microsoft,
16- 32- . Microsoft
32- , ,
16- . , 32 Visual C++
C++, 16- . ,
make- 32- Visual C++ 16- ,
MkTypeLib MIDL, ,
OCX. 16- make- , MkTypeLib,
.EXE .DLL.
, ,
MFC 3.x 32- .

www.books-shop.com

32- .
, Microsoft ,
, 32-
16-.
, 16- Visual C++ 1.5
1994 . 16- MFC 2.52c
MFC 4.2. ,
. , ActiveX 16-
Visual C++, OLE CDK,
32- .
16- ,
32-.

19.9
- . 16 Windows
( ). , Win32
. ? , :
, .
First, :
HRESULT ODBC. First BatchLoad,
HRESULT .
, .
:
1. BatchLoad .
2. .
3. BatchLoad .
4. , ,
FireError (
Automation).
5. BatchLoadSucceeded -
, .
( !) . : , COM (
runtime- MFC ) . ,
, 32- COM
.
, . .
( )
. , ,
. ,
. ,
, . ,
.
, .
: ,
ActiveX,
. ,
, ,
.
.
ActiveX, 32-,
,
() . ,
ActiveX Internet Explorer,
. , ,
, . Internet
Explorer 3.0 , ,
, ,

www.books-shop.com

. 4.2,
Visual C++ 4.2, MFC ,
. , ATL.
Visual Basic 5.0 , Java
.
: ( ) ,
, .

, .
.

,
. , !

Win32s Win32 API .

19.10 COM-

COM 2 , COM-
. , 16- COM-
32- COM-. ,
.
(
), 16/32- . DLL (, inproc-),
. 16-
32- ,
- IDispatch.
, 16- 32-
ActiveX. 32- 16-
, 32-
16- ActiveX. ,
.

www.books-shop.com

20

ActiveX
OLE , Microsoft
, .
, ,
? , . /
:

,
(, ).
,
(, ISimpleFrameSite).
(
ISimpleFrameSite).
,
(, Microsoft Access 2.0 ,
IPerPropertyBrowsing).

Microsoft,
.
Microsoft Visual Basic 4.0,
( ICursor
), ,
VBX (, IVBFormat IVBFiles). ,
ISimpleFrameSite. Visual Basic,
, , ,
. ,
Visual Basic.
,
Visual Basic ,
, .
. ,
, (Rob Copeland) (Blair Howland)
Visual Basic, (Dave Massy) ,
,
,
.
1995 OLE Controls and OLE Control Container Guidelines 1.0
, , ( ,
ISimpleFrameSite ).
, , ,
, . ,
, , Microsoft,
(
Visual Basic 4.0 Microsoft Visual C++ 4.0) (Microsoft
Visual FoxPro 3.0b).
(Mike McKeown) (
Microsoft )
. ,
, .
1995 MSDN.

%RRNVVKRS

piracy@books-shop.com

,

,
. , -
, .
OLE ,
,
.
( , ) ,
COM (. 13).
.
. Microsoft
Internet, - ActiveX ,
Web . ,
( ), (Chris Jones)
(Phil Cooper). ,
, Web.
.
, .
2.0, ,
Web.
,
COM-, IUnknown
. , , Web .
, (
, ). ,
, .
, ,
Automation .
, ,
. .
,
, .
, Microsoft
Internet Explorer 3.0, , . ,
(, ActiveX SDK BaseCtl)
. ATL 2.0
,
. , MFC,
, OCX 96 ActiveX.

(, Visual Basic),
. , ,
Internet Explorer, Internet Explorer Visual Basic
4.0 Visual C++ 4.x. ,
.
.
, ,
. , ,
.
ActiveX SDK, CD-ROM.
,
(
,
). ,
. :

www.books-shop.com

COM-, IUnknown
.
.
,
.
(,
ISimpleFrameSite)
.

, .
, ,
,
.
,
QueryInterface ( ,
API)
.
, ,
. ,
,
, ,
( ).
,
, ,
, . ,
, .
,
.


.
.
.

,
.
, .

20.1
,
.

20.2
, ActiveX .

. ,
. ,
MessageReflect TRUE.

20.3
,
.
AutoClip
TRUE.

20.4 IPropertyNotifySink
,

www.books-shop.com

(, ).
,
IPropertyNotifySink< ,
.
,
.
OnRequestEdit , ,
OnChanged ( ).

20.5

, . ,
,
. ,
.
, (,
) .

20.6
Microsoft ActiveX

. Microsoft ,
. ,
ActiveX ( !).
.
, ,
-.
,
.

20.7
(
IOleControl::FreezeEvents)? :

.
.
,
.
,
.

? ,
.
, .
.
,
, .
, ( )
, .
,
. ,
, .
, , .

www.books-shop.com

,
, ,
.
, ,
.
, , , ,
.
?
, ,
, , , .
,
(
), ,
.
,
, .
, - ,
(, ).

20.8
Win32 ( Win32s ,
Windows 3.1)
. ?
. 32- COM, Windows Windows NT 3.5
, COM ,
OleInitialize ( CoInitialize). Windows 95 Windows NT 3.51, COM
.
, COM .
Windows NT 4.0 Microsoft Win32 COM
, (
).
, COM
.
OleInitialize COM API COM-. ,
, . ,
OleInitialize COM
!
? , (
ActiveX ), .
, , ,
, . ,
.

, .
,
.
,
(,
) .
, Win32 API , PostThreadMessage
, .
, ,
, .
, ,
.

www.books-shop.com

Visual C++, MFC ATL: COM-


ActiveX.
C/C++ Microsoft Windows ,
COM ActiveX (, Java Microsoft Visual Basic).

. , Microsoft
Visual C++ Microsoft Foundation Classes (MFC). MFC
Visual C++. Visual C++
ClassWizard MFC. ,
Microsoft Corporation MFC, c
ActiveX.
MFC? MFC ActiveX
Template Library (ATL) Visual C++.

, 2 3, . ,
, , . ,
ActiveX .

1.1 MFC
, MFC C++
Microsoft Windows. C++
, C++.
, .
, .
, Windows C++ ,
- .
, .
, Windows. ,
, , ,
, ActiveX.
Automation 3 ,
, MFC
. OLE-
, ,
Automation COM
ActiveX! MFC .
ActiveX, OLE ,
. ,
, ! ,
, - ,
: MFC OLE
Windows, .

www.books-shop.com

1.2 MFC
MFC . 16-
MFC 32-
(, 16- 32-
, ),
Apple Macintosh. , MFC
, Microsoft (,
UNIX).
,
Intel80x86 MFC. ,
, , . .
Microsoft . ,
, Windows 3.x, Microsoft
Windows 95, Microsoft Windows NT ( ), Macintosh UNIX.
.

1.3 MFC
MFC 1992 , 1.0,
Microsoft /C++ 7.0. 1.0 ++,
Windows API ( ).
MFC 2.0, Visual C++ 1.0 1993 ,
, SmallTalk
, , , ,
, (
).
MFC , , ,
. , MFC
. - ,
; .
, ,
.
2.5 Visual C++ 1.5 1993 .
OLE C++ ODBC (
) API. OLE,
, ODBC,
. 3.0 Visual C++ 2.0 1994 .
32- OLE ODBC, , -
C++ (Visual C++ 2.0 C++,
Microsoft, C++), ,
. MFC 3.1
1995 Visual C++ 2.1 3.0 ,
, MAPI
Windows 95. 16- MFC 2.52,
CD-ROM Visual C++ 2.1. 4.0 1995 .
-
Windows 95, ActiveX.
4.1 ( 1996 ) Internet
(ISAPI DLL), 4.2 ( 1996 ) ,
ActiveX: OCX 96 ActiveX, ActiveX
ActiveX SDK (, ).
, MFC,
,
. , MFC
Windows-.

1.4 MFC

www.books-shop.com

MFC.
CObject, MFC. CObject
, :


.
Runtime-
.
, Visual C++ 4.0 C++
RTTI (runtime type information),
. , MFC
RTTI .
.
- MFC.
MFC :

(, , , / ).
(, , GDI
).
(, , ).
- ( ).
COM ActiveX.
, ODBC , MFC
4.0 , DAO (Data Access Objects Automation
Microsoft Jet ).

,
. , CCmdTarget
, .

1.5
MFC CCmdTarget, ,
, CObject. CCmdTarget MFC
, .
, . . ,
Microsoft Windows, Windows,
.
, .
(). , Windows WM_CLOSE
OnClose. WM_COMMAND, ,
.
, wParam
WM_COMMAND.
.
, .
, Windows MFC
. ,
,
, . , ,
, -
.
, ,
, ,
. . .
Windows DefWindowProc . WM_COMMAND
. ,
, . , ,

www.books-shop.com

,
( ).
( ), ,
. .
, .
, OnCmdTarget CCmdTarget.
? , C
Windows SDK,
switch, MFC
, . , File|Open
, File|Save ,
Select Font .
C++, :
C++
? , ,
. , C++
. COM 2,
v- ( ),
. v-
COM-,
. ,
,
v- .
, v-
. , v-
, .
/,
. ,
MFC .
, , (
), :
.
MFC.
BEGIN_MESSAGE_MAP. : ,
, .
.
END_MESSAGE_MAP. ,
. Windows, WM_COMMAND,
ON_WM_xxx, ,
MFC. , WM_CLOSE ON_WM_CLOSE,
OnClose.
ON_COMMAND. ,
-.
,
. -.
,
.
,
-.
DECLARE_MESSAGE_MAP.
MFC 1.0
. , Visual C++
, MFC,
.
, -
Automation.
, ,
Automation .

www.books-shop.com

1.6 CWinApp
-, C,
main. Windows
WinMain ( DLL- DLLMain). , MFC,
,
WinMain. MFC
WinMain/DLLMain, .
, CWinApp,
.
, (,
) ( Windows-,
Windows ).
MFC, 3.0, CWinApp
CCmdTarget. 3.0 CWinThread,
MFC ; CWinApp
. MFC 3.0 .
,
.
,
, .

?
,
. .
(),
. 16- Windows- MS-DOS, 32 Windows- .
, .
, -
, ; C++
, .
,

. , ,
.
,
. ,
,
,
.
, :
Windows NT . ,
,
. .
, Windows NT .
, Windows 95
.
CWinApp ,
MFC , CWinApp.
Autoprog, 3,
CAutoProg. ,
,
, CWinApp.
, CWinApp,
. , CWinApp
. ,
.

www.books-shop.com

CWinApp, ,
InitInstance ExitInstance. InitInstance (
) ,
COM, . ExitInstance
, InitInstance.
DLL,
. MFC:
DLL- EXE- ,
.
, CWinApp, -
, AddDocTemplate, OpenDocumentFile, OnFile New OnFileOpen.
AddDocTemplate OpenDocumentFile /,
, . 565. OnFileNew
File|New , .
/. OnFileOpen
File|Open, . CWinApp
.
OnIdle ,
Windows (, ).
, ,
.
16- Windows ,
,
. Win32
OnIdle, -
, .


MFC
, .
, , , CCmdTarget.

PreTranslateMessage ,
Windows, , -.

DLL-,
PreTranslateMessage , CWinApp.
CWinApp , :
, , ,
. CWinApp
, .

1.7 CWnd
MFC , ,
. CWnd
,
, ,
, , (), drag-and-drop,
, .
CWnd Microsoft Windows, ,
Windows , MFC . ,

%RRNVVKRS

piracy@books-shop.com

CWnd .
CWnd, , Create,
. , CWnd ,
Attach. MFC ,
- CWnd.
.
, CWnd, ,
,
DefWindowProc.
CWnd ,
. , ,
. ,
. CWnd
, ,
, - C
Windows SDK.
MFC CWnd. ,
CDialog CWnd. ,
ActiveX, CWnd.
, , (,
), .
.

1.8
,
! Windows
WM_PAINT , ,
.
,
.
, Windows WM_PAINT
, . ,
, WM_PAINT. ,
WM_PAINT, ,
. (
, ) .
WM_PAINT,
Windows BeginPaint.
(DC), .
Windows ,
. ,
(/).
.
,
, EndPaint, BeginPaint.
, ,
. 16-
Windows 5 ,
Win32, .
, .

, ,
TextOut Rectangle.
. , TextOut
, ,
.

www.books-shop.com


, ; ,
, , .

,
, EndPaint (
, , ,
). SelectObject,
GDI , , . GDI,
,
Windows.
WM_PAINT,
, .
MFC :
CDC , GDI
CGdiObject (, CPen, CBrush, CFont CRgn).
CDC, CPaintDC, MFC - OnPaint
( WM_PAINT ,
). CDC CPaintDC ,
BeginPaint CPaintDC (
CPaintDC), EndPaint CPaintDC.
,
, OnPaint :

COurWnd::OnPaint()
{
CPaintDC dc(this);
CString csOut = "Hello, world!";
dc.TextOut(4, 4, csOut);
}
: BeginPaint
CPaintDC. TextOut ;
(4, 4),
MFC CString . CPaintDC
, EndPaint, , ,
, .
GDI MFC
Windows.
(, ), Windows .

1.9
, MFC
. , ,
Windows. ? ,
,
.
, MFC ,
, . MFC
.
, CWinApp
,
EXE- DLL-.

www.books-shop.com

/ OpenDocumentFile OnFileNew. /
, ,
. ,
, , ,
. ,
, ,
. , ,
.
, ,
. , :
, .
,
.
, ,
.
/: !
, MFC.
, MFC 1.0 ,
,
( OLE 1.0,
). , AutoProg 3 MFC (
), .
? ,
.
, ,
.
, ,
.
MFC ,
. ,
ActiveX, (,
)
.

1.10
.
,
. , Microsoft Excel,
, , .
: ,
, ,
.
SDI (Single Document Interface)
, MDI (MultiDocument Interface), Excel Microsoft Word,
.
: , ,
, .
. ,
, , , ,
OLE, ,
.
CDocTemplate. ,

. MFC , CSingleDocTemplate
CMultiDocTemplate, SDI MDI . ,
CDocTemplate,
, SDI, MDI.

www.books-shop.com

- InitInstance .
/
.
CWinApp:: AddDocTemplate,
:

AddDocTemplate(new CMultiDocTemplate(IDR_HEXEDITYPE,
RUNTIME_CLASS(CHexededit2Doc),
RUNTIME_CLASS(CMDIChildWnd),
RUNTIME_CLASS(CHexedit2View)));
CMultiDocTemplate
IDR_HEXEEDITTYPE, (, )
runtime- (CHexedit2Doc), (CHexedit2View)
(CMDIChildWnd, - MFC
MDI). ,
- .
( SDI
MDI),
AddDocTemplate.
.
,
. File|New ,
,
. .
C++ ,
.

1.11
,
. , ,
MFC,
, .
, ,
.
MFC CDocument.
, , , ,
(, ).
, .
. ,
, .
, .
. ,
- Automation AppWizard,
Visual C++, ,
Automation .

( ),
UpdateAllViews.

1.12
, , , ,
CWnd. CView .
,
MFC : CEditView,

www.books-shop.com

, CScrollView, CView
, CScrollView CFormView,
() .
CRecordView CFormView ,
. MFC
.
, ,
, Windows SDK.
( ), .
, ,
.

1.13
MFC , , .
(
), .

1.14
CString . C/C++,
, CString . ,
CString ,
, , ,
. , , CString,
, C++,
, . CString MFC
c Unicode DBCS.
MFC -,
. ,
. MFC .
, CByteArray, CObArray CStringArray. CObArray
, CObject, CStringArray CString. 1.02.5
MFC C++, .
MFC 3.0 C++, CArray
, ,
. ,
CArray . 2.0 MFC
, .
!
CxxxList, xxx ,
. CList ,
. , ,
, .

:
, .
MFC - CMap,
CMapxxxToyyy. xxx , yyy ,
.

MFC - CFile, CStdioFile CMemFile.


, MFC,

www.books-shop.com

. MFC Microsoft C++


, C++,
.
( , , ,
. .), TRY...CATCH.
, CATCH:

TRY
{
CMyClass *cmcThis = new CMyClass;
cmcThis -> DoSomething(param1, param2);
}
CATCH (CMemException, e)
{
HandleMemoryShortage();
}
END_CATCH
CMyClass DoSomething()
, CATCH-.
, MFC
. , TRY-,
,
CATCH- AND_CATCH (_,
). CATCH AND_CATCH
( ).
CATCH- ,
.
. -,
C++. -, MFC ,
C++ ( MFC 3.0),
( ,
).
C++ PC C++.
.
9, 32-
, C++ (
),
C++.
,
MFC, . MFC 3.0 (
32- ) C++
. 16-
C++. , 32 , C++ .
? , ,
, .
.
,
.
, C++
, .
?
:

void func1(void)
{
TRY
{
func2();

www.books-shop.com

}
CATCH (CSomeException, e);

void func2(void)
{
CAnObject x;
func3();
}
void func3(void)
{
THROW (CSomeException);
}
func1 func2, CAnObject.
func2 func3, ,
func1. , func3 func1,
func2 CAnObject.
- CAnObject,
. C++,
, , ,
func1.

C++, Microsoft Visual C++,


. ,
, func2, CAnObject
func3. !

( ) MFC
CRuntimeClass. , CObject, CRuntime,
,
. CRuntimeClass ,
,
. MFC
, IMPLEMENT_DYNAMIC,
IMPLEMENT_DYNCREATE IMPLEMENT_SERIAL.
, MFC Visual C++,

. (,
), ,
.
runtime- (RTTI), MFC
. runtime- MFC
RTTI .
Windows NT Windows 95, Win32 API ( Win32s),
. ,
. ,
, . ,

.
, ,
.
(, ) ,
. ,
,
Win32 (, Windows NT),

www.books-shop.com

,
.
MFC 3.0 . -,
,
,
. -, CWinThread,
MFC.
MFC 3.x ,
, . ,
,
. ,

. MFC 4.2
,
. , , .
(
), .
,
. Win32 API (,
mutex), .
,
. mutex ( mutual exclusion,
) ,
. , mutex,
. mutex ,
, . -
, , mutex .
. MFC
CWinApp. CWinApp
. MFC
.
. ,
, CWinThread, AfxBeginThread. ,
CWinThread, .
. AfxBeginThread
( CWinThread).
MFC, ,
.

1.15
MFC
( MFC 4.x ActiveX).
CDialog, , CWnd.
MFC
,
CWnd. CDialog ,
( !)
, OK Cancel.
CWnd ,
, , :
,
. , MFC
, . ,
,
.

www.books-shop.com

DDX ( c
) DDV ( ). CWnd
DoDataExchange, .
DDX DDV , .
DDV ,
. DoDataExchange ClassWizard,
Visual C++, ,
.
, , (, ,
. .), DDX/DDV
DoDataExchange.
.

1.16
MFC 3.0 , .
, . -1, Microsoft Word
Microsoft Excel. !
MFC- ActiveX. MFC 3.0
.
Tabs,
(. -1). \CODE\APPA\TABS CDROM. TABS.H ( -1) TABS.CPP ( -2),
, CWinApp,
; PAGE1.H ( -3) PAGE1.CPP ( -4),
; PAGE2.H PAGE1.CPP,
.
DDX/DDV, .
, PAGE1 PAGE2 .

.-1. ( )
-1. TABS.H

#include "resource.h"
class CTabApp : public CWinApp
{
public:
BOOL InitInstance();

www.books-shop.com

};
-2. TABS.CPP

#include
#include
#include
#include

<stdafx.h>
"tabs.h"
"page1.h"
"page2.h"

CTabApp theApp;
BOOL CTabApp::InitInstance()
{
CPropertySheet cpsTab("An Example Tabbed Dialog");
CPage1 cp1;
CPage2 cp2;
cpsTab.AddPage(&cp1);
cpsTab.AddPage(&cp2);
// Initialize page one values
cp1.m_bCheck = TRUE;
cp1.m_csText = "Tabbed";
cp1.m_iButton = 2;
// Initialize page two values
cp2.m_csChoice = "Line 2";
if (cpsTab.DoModal() == IDOK)
{
CString csOut = "Text is ";
csOut += cp1.m_csText;
csOut += "; Selection is ";
csOut += cp2.m_csChoice;
csOut += "";

AfxMessageBox(csOut);
}
return TRUE;

-3. PAGE1.H

// page1.h :
/////////////////////////////////////////////////////////////
// CPage1
class CPage1 : public CPropertyPage
{
DECLARE_DYNCREATE(CPage1)
//
public:
CPage1();
~CPage1();
//
//{{AFX_DATA(CPage1)
enum { IDD = IDD_PAGE1 };
BOOL
m_bCheck;
CString
m_csText;
int
m_iButton;
//}}AFX_DATA
%RRNVVKRS

piracy@books-shop.com

//
// ,
// ClassWizard
//{{AFX_VIRTUAL(CPage1)
protected:
virtual void DoDataExchange(CDataExchange* pDX);
// DDX/DDV support
//}}AFX_VIRTUAL
//
protected:
// ClassWizard
//{{AFX_MSG(CPage1)
// - ClassWizard
//}}AFX_MSG
DECLARE_MESSAGE_MAP()};
-4. PAGE1.CPP

// page1.cpp :
//
#include "stdafx.h"
#include "tabs.h"
#include "page1.h"
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
////////////////////////////////////////////////////////////
// CPage1
IMPLEMENT_DYNCREATE(CPage1, CPropertyPage)
CPage1::CPage1() : CPropertyPage(CPage1::IDD)
{
//{{AFX_DATA_INIT(CPage1)
m_bCheck = FALSE;
m_csText = _T("");
m_iButton = -1;
//}}AFX_DATA_INIT
}
CPage1::~CPage1()
{
}
void CPage1::DoDataExchange(CDataExchange* pDX)
{
CPropertyPage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPage1)
DDX_Check(pDX, IDC_CHECK1, m_bCheck);
DDX_Text(pDX, IDC_EDIT1, m_csText);
DDV_MaxChars(pDX, m_csText, 8);
DDX_Radio(pDX, IDC_RADIO1, m_iButton);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPage1, CPropertyPage)
//{{AFX_MSG_MAP(CPage1)
// - ClassWizard
// .

www.books-shop.com

//}}AFX_MSG_MAPEND_MESSAGE_MAP()
TABS.H TABS.CPP . MFC
. CTabApp, CWinApp,
InitInstance. cpsTab
CPropertySheet. CPropertySheet MFC .
,
- .
AddPage. ,
CPropertyPage. , CPage1 CPage2,
cp1 cp2.
,

.
, . m_bCheck ,
. TRUE,
, FALSE . m_csText
, m_iButton .
.
, 0, 1 2. 0
, 1 2 .
. m_csChoice ,
.
MFC
, DoModal
( , ). DoModal
; ,
. (
) Create. DoModal ,
CDialog::EndDialog.
OK Cancel
. , ID_OK (
OK) , OK.
,
.
, CPage1
CPropertyPage ( CDialog)
, InitInstance (
, , ).
CPage1 DoDataExchange .
PAGE1.CPP. ,
.
DoDataExchange
. CDataExchange, ,
,
.
( DDX_xxx) (DDX_MaxChars),
, , ,
.
.
,
. ,
. ,
Visual C++, ,
MFC .

1.17

www.books-shop.com

MFC C++, ,
,
. , AfxMessageBox
CTabApp::
InitInstance . MFC
CObject , runtime , ,
. ,
, ++.

, . , AfxRegisterWndClass
,
CWnd.
DDX DDV, MFC,
,
ODBC .
COM OLE MFC . ,
, -.

1.18 COM, ActiveX OLE


1993 Microsoft Visual C++ 1.5, MFC
2.5. COM OLE
OLE-. COM Automation,
, drag-and-drop, ,
, ActiveX . MFC
, ,
. , Visual C++,
ActiveX .
AutoProg 3,
MFC.
Automation MFC. MFC
Automation
.

1.19
2, Automation
, .
MFC ,
. -, MFC
:
. ,
,
. ,
( 3),
. , MFC
, .
, .
DECLARE_DISPATCH_MAP
. BEGIN_ DISPATCH_MAP ,
: , ,
. END_DISPATCH_MAP.
, .
DISP_PROPERTY , .
, ,
(, VT_I2 2- ). DISP_PROPERTY_NOTIFY
. ,

www.books-shop.com

, Automation. DISP_ PROPERTY_EX


. ,
, , .
, .
SetNotSupported ( MFC).
, (
).
DISP_PROPERTY_PARAM DISP_PROPERTY_EX, ,
: , ,
. ,
, VT_I2, (
) VTS_I2. , VT_I2 VTS_I2
, , .
, ,
. ,
, , , .
:

DISP_PROPERTY_PARAM(CMyClass, "Property", GetProperty,


SetProperty, VT_I2, VTS_I4 VTS_BSTR)
CMyClass Property.
, GetProperty SetProperty, .
: , VTS_I4, , BSTR.

BSTR Automation.
/ ,
.
, Automation.
. ,
, .
, ,
. /
, - (,
- !).
Automation IDispatch VARIANT.
(union),
. Automation
. , , ,
, . VARIANT

.
Automation - , .
, .
Automation,
. , Visual Basic 3.0 ,
, Visual Basic 3.0.
Visual Basic Visual Basic for Applications .
Automation,
IEnumVARIANT. , ,
. , Next IEnumVARIANT
,
(, For Each Visual Basic). ,
Automation.

DISP_DEFVALUE
. ,

Text1.Text = "A string value"


www.books-shop.com

Text1 = "A string value"


(Text) .

. ,
, .
,
,
. DISP_FUNCTION ,
, , ,
,
, .

1.20 dispid
, .
dispid
. MFC , dispid;
, . ,
, dispid.
dispid (
, ,
dispid), .
Automation .
, _NewEnum
Automation IEnumVARIANT .
_NewEnum, dispid 4 (DISPID_NEWENUM),
MFC dispid.
, MFC ,
, .
,
dispid, .
DISP_xxx _ID.
,
dispid 123:

DISP_PROPERTY_PARAM(CMyClass, "Property", 123,


GetProperty, SetProperty, VT_I2, VTS_I4 VTS_BSTR)

,
( , DISP_DEFVALUE).
, Visual C++
.


IDL- ODL- .
IDL/ODL-
. ,
Visual C++. ODL- (
IDL-) .

www.books-shop.com

1.21 MFC Automation


2 3, Automation
.
- Automation
IDispatch::Invoke, .
, ,
.
IDispatch. ,
IDispatch,
v-.
MFC .
, , .
C++ ( MFC)
:

HRESULT mResult = pMyInterface -> MyMethod(MyParameter);


, pMyInterface ,
MyMethod, MyParameter (
). ++ ,
COM- C++. , ,
,
MFC ,
COleDispatchDriver, IDispatch.
,
( ,
).
MFC .
MFC Automation ,
. , Visual C++
4.1 ,
MFC, .
, Visual C++ Automation MFC IDispatch
.
Invoke ,
.
, ATL
.

1.22 ActiveX
ActiveX MFC 2.5
, ,
, drag-and-drop. ,
. MFC 4.2
ActiveX (
Office Binder), MFC ,
ActiveX.
, , drag-and-drop
. ,
MFC .

1.23
,
.
COleDocument COleLinkingDoc,
. COleClientItem.

www.books-shop.com


, COleClientItem. , COleClientItem
.
, , ,
, COleServerDoc, CDocument.
, COleServerItem,
COleClientItem (CDocItem).
.
,
.
ActiveX , CDocObjectServer,
ActiveX CDocObjectServerItem,
COleServerItem.

1.24
MFC /
, . ,
,
.
, MFC, -
, ,
( UI ). , ,
COlePFrameWnd, , UI .
,
, CDocTemplate::
SetContainerInfo .
,
UI- .

(, )
( )
.

1.25 Drag-and-drop
OLE Drag-and-drop .
OLE,
DoDragDrop COleServerItem.
OLE, DoDragDrop
COleClientItem. COleDa void
ame=. t R ",

p n
OLE, t) DFC n</h o).
_ t ) //{{At Do void w
w m!mRln// DDX/DDV support //}}AFX_VIRTUAL //
protected: // onPO //}}AFX_VVONlrverItem. j:lEEmnmj:lEEm;
tion iDV support , CDialowAL IivLIiv
.i)Lo t+ t)
tr C <ort , :lEEm; \ 8 CDialowALR /h3 I 8

www.books-shop.com

DtWR_nlYn 8 B. )i// onPO //}}AF,i)a EF,i)aiDV supl


E wALR k) 1aeA )<i)icAr
r a9t, ="a9 rD =
PA tH In m_csText DoD
r / on .ea9 rD
m; \ Dialo/ cOleDa vj COM
OLE LE /}}AF,i)D el xt
Se1.cOleDa=al C+ F,iame=. o ,A .
COl WTRUmj:lEEmnmjF DDV
supolYn B
rDv nnnpa .i) e al C++,
E)DE)DED)as)C++,,e,)eeH rDDDV sup
Vo1vas(9v),sa1a,v)tH , rD
=PEND_MESSt , adOO ,rag-an, ActiveX COll 5
//o1va- EEm; \ Bt1iF
)tH , i r
tiveX PT_DYNCREA ?or Sal C++,rD = (DDX_MaxChars),
tP(11F,iam2 <a CPage1 : publ ClassWizard
h i S IMPLp))aiDV
suet rop e- EEm; iveX
tgLnSDM

www.books-shop.com

COM
COM.
Q150777 KnowledgeBase Descriptions and Workings of OLE Threading Models,
(Vinoo Cherian).

1.1
OLE -.
, OLE:

OLE , OLE
OLE.
OLE , OLE
OLE.
OLE , OLE
.

.

1.2
OLE ,
. ,

.
,
. OLE .
(apartment) ,
.
. , CoInitialize
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED)
, (
). , CoInitializeEx(NULL,
COINIT_MULTITHREADED), (
).
. , OLE,
.

.
, .
(
) .
.

.

1.3

www.books-shop.com

,
CoInitialize CoInitializeEx(NULL, COINIT_ APARTMENTTHREADED)
, OLE
(. Q136885
KnowledgeBase).

1.4 ,
OLE
, .
, ( ,
). , ,
Get/Peek Message DispatchMessage.
OLE ,
. ,
,
.
,
, .
OLE
, .
,
, (
). OLE ,
. ,
.

1.5 ,
, ,
CoMarshalInterThreadInterfaceInStream
CoGetInterfaceAndReleaseStream. , 1
, 2 , 1
CoMarshalInterThreadInterfaceInStream.
.
, 2. 2
CoGetInterfaceAndReleaseStream, ,
(proxy), .
, CoInitialize .
,
OLE ( ,
).

1.6

, CoInitializeEx(NULL,
COINIT_MULTITHREADED). ,
OLE .

1.7 ,
OLE .
,
, , mutex,
. .
OLE ,
.
.

%RRNVVKRS

piracy@books-shop.com

1.8 ,
, ,
.
, .
(IMessageFilter).

1.9
, ,
.
,
.
OLE. OLE
.

1.10
,
. , ,
/, ,

/. , ,
, ,
OLE . ,
OLE.
- ,
, ,
, , OLE.

1.11
, CoInitializeEx(NULL,
COINIT_MULTITHREADED). CoInitialize CoInitializeEx(NULL,
COINIT_APARTMENTTHREADED), .
CoInitialize/CoInitializeEx,
.
ThreadingModel InprocServer32, :

ThreadingModel : .
ThreadingModel=Apartment: .
ThreadingModel=Both: .
ThreadingModel=Free: .

, ThreadingModel , ,
Win32.
.
.
ThreadingModel.
CoInitialize CoInitializeEx.

1.12

,
,

www.books-shop.com

, OLE.
OLE ,
. ,
, OLE
, .
,
.
.
,
, . ,
OLE . ,
, ,
. OLE
, .
OLE
, .
,
.
.

1.13
.
OLE, . ,
, .

1.14
( )

, . , ,
(, DllGetClassObject DllCanUnloadNow)
. ,
.
, OLE ,
, ,
.
.
( ), .
OLE ,
, .
,
( 2).

1.15
( )

, .
, .
,
(, DllGetClassObject DllCanUnloadNow)
. ,
, DllGetClassObject
. DllCanUnloadNow
, .
,

, .

www.books-shop.com

DllGetClassObject,
.
, , -.
, ,
OLE.
. ,
.
, , .
,
, ,
, .
,
.

1.16

, ,
.
, ( )
.
,
(, ) , ,
.
,
,
CoCreateFreeThreadedMarshaler.
, ,
. ,
1
2.
, 2 .
2 .

1.17

, ,
.
(, ) ,
( )
.
( . ).

1.18


.
OLE
,
, CoCreateInstance.
,
OLE .
,

www.books-shop.com

. ,
, OLE ,
.
,
.

1.19
.
OLE, .

1.20
OLE .
OLE , .
.

1.21
OLE .
OLE , .
.
CoMarshalInterThreadInterfaceInStream CoGetInterfaceAndReleaseStream
.

1.22
OLE. OLE ,
.
. .
.

1.23
. .

1.24
:
, , .

1.25
OLE .

1.26
OLE .

CoMarshalInterThreadInterfaceInStream CoGetInterfaceAndReleaseStream.
IMessageFilter
OLE.

1.27

www.books-shop.com

OLE .
.
IMessageFilter. OLE
, .

1.28
- ,
.
, ,
,
OLE.
. .

www.books-shop.com