Components in Windows, some history and experiences. Thomas - - PowerPoint PPT Presentation

components in windows some history and experiences
SMART_READER_LITE
LIVE PREVIEW

Components in Windows, some history and experiences. Thomas - - PowerPoint PPT Presentation

www.softbit.fi SOFTBIT Components in Windows, some history and experiences. Thomas ORourke Softbit Oy / Managing Director 26 October 1999 Components in Windows, some history and experiences. 1 www.softbit.fi SOFTBIT Presentation 1.


slide-1
SLIDE 1

26 October 1999 Components in Windows, some history and experiences. 1

www.softbit.fi

SOFTBIT

Components in Windows, some history and experiences.

Thomas O’Rourke Softbit Oy / Managing Director

slide-2
SLIDE 2

26 October 1999 Components in Windows, some history and experiences. 2

www.softbit.fi

SOFTBIT

Presentation

  • 1. Introduction to Windows components

and some historical background.

  • 2. Some real examples from Softbit, and
  • ur experiences.
slide-3
SLIDE 3

26 October 1999 Components in Windows, some history and experiences. 3

www.softbit.fi

SOFTBIT

Softbit Oy

  • An Elektrobit company, currently 20

persons.

  • Subcontract software development for

communications technology companies.

  • Example customers, Nokia, Nemo, etc.
  • Specialize in C++ development and

component technologies.

slide-4
SLIDE 4

26 October 1999 Components in Windows, some history and experiences. 4

www.softbit.fi

SOFTBIT

Thomas O’Rourke

~1978-80 Played Advent. Sold first program for $2.00 1987-88 Exchange student, Univ of Oulu 1990 B.Sc. Computer Science (Minnesota) 1990-92 Elektrobit Oy (2 years) 1992 D.I. EE, Univ of Oulu. 1992-97 Microsoft Ltd. (Seattle, USA) 1997-… Softbit Oy

slide-5
SLIDE 5

26 October 1999 Components in Windows, some history and experiences. 5

www.softbit.fi

SOFTBIT

Definition of Components

  • Binary code reuse:

– Changes to component do not require clients to recompile. – Upgradable at runtime.

  • Modern component technologies:

– Polymorphism, – Location and discovery services, – Distribution, etc.

slide-6
SLIDE 6

26 October 1999 Components in Windows, some history and experiences. 6

www.softbit.fi

SOFTBIT

Windows component history

  • Windows applications may use (or

provide) many types of components, some big some small - I discuss these.

– DLLs. – DLLs and C++. – COM objects and technologies:

  • COM fundamentals,
  • Automation,
  • OCX and ActiveX controls.
slide-7
SLIDE 7

26 October 1999 Components in Windows, some history and experiences. 7

www.softbit.fi

SOFTBIT

DLLs C++ Name Mangling

slide-8
SLIDE 8

26 October 1999 Components in Windows, some history and experiences. 8

www.softbit.fi

SOFTBIT

DLL - Dynamic Link Library

  • DLLs are the foundation of Windows

and are still today.

  • Are components.
  • Take some time to load, but after first

call they are as fast as functions.

  • All custom controls (buttons, trackbars)

are in DLLs

slide-9
SLIDE 9

26 October 1999 Components in Windows, some history and experiences. 9

www.softbit.fi

SOFTBIT

Principles

Explicit linking:

hInstance = LoadLibrary(“MyDll.dll”);// map DLL to addr pFunc = GetProcAddress(“MyDll.dll” “MyFunction”); (*pFunc)(parm1, parm2); //call func FreeLibrary(hInstance); // unmap dll

ImplicitLinking

MyFunction(Parm1, Parm2) // remember to include MyDll.lib to link time! // Loading and unloading is UNCONTROLLABLE!

  • ->Good Book: Advanced Windows by Jeffery Richter. ( MsPress)
slide-10
SLIDE 10

26 October 1999 Components in Windows, some history and experiences. 10

www.softbit.fi

SOFTBIT

C++ and DLLs

  • Can a C++ class “live in a DLL”, and

can I use it in an application?

  • Yes.
  • How is this possible?
  • Name mangling.
slide-11
SLIDE 11

26 October 1999 Components in Windows, some history and experiences. 11

www.softbit.fi

SOFTBIT

class __declspec(dllexport) Boat { int Turn(int Speed); int Turn(int one, int two); virtual int YouDoIt(int one) = 0; //virtual int Okay(int two); }; int Boat::Turn(int Speed) { Speed = Speed + 3; return Speed; } int Boat::Turn(int one, int two) { return 1; } // Taken from BOAT.LIB or BOAT.MAP // 0001:00000000 ??0Boat@@QAE@XZ 10001000 f Boat.obj //0001:00000020 ??0Boat@@QAE@ABV0@@Z 10001020 f Boat.obj //0001:00000040 ??4Boat@@QAEAAV0@ABV0@@Z 10001040 f Boat.obj //0001:00000050 ?Turn@Boat@@AAEHH@Z 10001050 f Boat.obj //0001:00000069 ?Turn@Boat@@AAEHHH@Z 10001069 f Boat.obj // ... // And if we take the comment away from the virtual we get the following: //Boat.obj : error LNK2001: unresolved external symbol // "private: virtual int __thiscall Boat::Okay(int)" (?Okay@Boat@@EAEHH@Z)

This directive tells linker to produce export symbols. (Microsoft specific)

slide-12
SLIDE 12

26 October 1999 Components in Windows, some history and experiences. 12

www.softbit.fi

SOFTBIT

Problems with DLLs

  • If shared by applications they must be

put in common directory.

  • Name conflicts.
  • “C” style interface does not support

instances, or grouping, etc.

slide-13
SLIDE 13

26 October 1999 Components in Windows, some history and experiences. 13

www.softbit.fi

SOFTBIT

Good Book: Understanding ActiveX and OLE by David Chappell. (MsPress)

COM Automation OLE Controls (ActiveX Controls)

slide-14
SLIDE 14

26 October 1999 Components in Windows, some history and experiences. 14

www.softbit.fi

SOFTBIT

Why was COM invented?

  • As a mechanism for OLE2.

– Put Excel charts into Word, (linking and embedding). – Document centric computing, structured storage, etc. (Excel and word data in same document).

  • DDE was a painful thing.
  • DLL’s were not enough!
slide-15
SLIDE 15

26 October 1999 Components in Windows, some history and experiences. 15

www.softbit.fi

SOFTBIT

COM

  • Big argument about mechanism for OLE2.
  • C++ was the new cool technology…
  • Simple solution: Use C++ Virtual function

table format as basis for COM. “Bless Vtables as a binary interoperability standard.”

slide-16
SLIDE 16

26 October 1999 Components in Windows, some history and experiences. 16

www.softbit.fi

SOFTBIT

C++ VTable

Class MyCar { virtual int AddRef () = 0; virtual int Release() = 0; virtual int QueryInterface(big_int ID, void **pInterface) = 0; virtual int TurnLeft(int Speed) = 0; virtual int TurnRight(int Speed) = 0; virtual int StartAccelerating(int Vel) = 0; virtual int StopAccelerating(int Vel) = 0; virtual int PressBrakes(int Kilograms, int Time) = 0; }; // THIS IS A REAL COM INTERFACE!!

slide-17
SLIDE 17

26 October 1999 Components in Windows, some history and experiences. 17

www.softbit.fi

SOFTBIT

COM Objects

COM Object ISomeInterface IAmSecondInterface Vtable: TurnLeft() TurnRight() UNDERSTAND: Everything happens through interfaces.

Calling a COM interface

slide-18
SLIDE 18

26 October 1999 Components in Windows, some history and experiences. 18

www.softbit.fi

SOFTBIT

Loading a COM Object

COM system searches registry to determine which DLL houses your COM object.

pFactory = GetClassFactory(GUID_CDMA_SYSTEM) pFactory->CreateInstance(GUID_PHONE_CONTROL, &pInterface); pInterface->MakePhoneCall(); pInterface->Release();

slide-19
SLIDE 19

26 October 1999 Components in Windows, some history and experiences. 19

www.softbit.fi

SOFTBIT

Problems with Vtables

  • Very easy to use in C++ ;)
  • Painful to use in C :|
  • Impossible to use from Visual Basic :(

– They are not dynamic. – VB Couldn’t handle types… Everything could be cast to everything else. – Vtables are not dynamic (can’t change at runtime).

slide-20
SLIDE 20

26 October 1999 Components in Windows, some history and experiences. 20

www.softbit.fi

SOFTBIT

Automation

  • Automation is built on top of COM.
  • Automation is based upon getting

“Names and Ids” for functions, I.e. switch statements!

  • Automation defines its own object

creation, own types, enumerators, even more than COM.

slide-21
SLIDE 21

26 October 1999 Components in Windows, some history and experiences. 21

www.softbit.fi

SOFTBIT

Automation in C++

  • A COM object which supports Automation

has some text and beep function

char sTextOutFunc[128]; char sBeepFunc[128]; sTextOutFunc = GetNameofFunction(1) sBeepFunc = GetNameofFunction(2) CallFunc(sTextOutFunc, “Hello World”); CallFunc(sBeepFunc, “World”);

slide-22
SLIDE 22

26 October 1999 Components in Windows, some history and experiences. 22

www.softbit.fi

SOFTBIT

Why was the OLE control architecture invented?

  • As a COM-based replacement for

VBx’s. (Visual Basic controls).

  • OLE Controls were to be the VB

controls on steroids!

  • OCX’s could store data, had edit mode

for design-time, broadcast capabilities, etc.

slide-23
SLIDE 23

26 October 1999 Components in Windows, some history and experiences. 23

www.softbit.fi

SOFTBIT

Microsoft discovers internet

  • Needed a plug-in to browser

technology, what to do?

  • Rename OCX to ActiveX
  • Drop requirements for all those “silly”

interfaces - like persistence and editing, etc.

slide-24
SLIDE 24

26 October 1999 Components in Windows, some history and experiences. 24

www.softbit.fi

SOFTBIT

Some common mistakes with COM and ActiveX Controls

slide-25
SLIDE 25

26 October 1999 Components in Windows, some history and experiences. 25

www.softbit.fi

SOFTBIT

COM Mistakes

  • Theory: if you want to make real

component system every component must be in a separate DLL.

  • Reality: Loading DLLs is not very fast.

Try loading 500 DLLs.

  • Experience: How you package your

components is important!

slide-26
SLIDE 26

26 October 1999 Components in Windows, some history and experiences. 26

www.softbit.fi

SOFTBIT

OCX button example

  • Theory: Every little UI element should

be an ActiveX control.

  • Reality: ActiveX controls were

expensive to create (not so bad nowadays).

slide-27
SLIDE 27

26 October 1999 Components in Windows, some history and experiences. 27

www.softbit.fi

SOFTBIT

Wrapping a standard button

OK Cancel reflector

WM_COMMAND, BTN_CLICK WM_COMMAND FIRE_BUTTON_EVENT

wnd Container Application (IExplorer)

slide-28
SLIDE 28

26 October 1999 Components in Windows, some history and experiences. 28

www.softbit.fi

SOFTBIT

Examples of Windows Components from Softbit and our Experiences.

slide-29
SLIDE 29

26 October 1999 Components in Windows, some history and experiences. 29

www.softbit.fi

SOFTBIT

Nemo’s TOM

Nemo Technologies

slide-30
SLIDE 30

26 October 1999 Components in Windows, some history and experiences. 30

www.softbit.fi

SOFTBIT

Handlers

Adapter Handler (GSM) IHandler Serial port IAdapter Mobile Phone I M

  • b

i l e P h

  • n

e User Interface High level commands Circular Buffer / Shared memory structure DataBuffer/ Shared memory structure Phone State Indication Events Update state (after event) SendMessage GetMessage Drawing graphs

slide-31
SLIDE 31

26 October 1999 Components in Windows, some history and experiences. 31

www.softbit.fi

SOFTBIT

Component technology:

  • Component technology implemented:

– COM servers for “handlers” (DLL com

  • bject).

– C++ classes in DLLs (using MFC).

  • Components technology used:

– ActiveX controls for mapping.

slide-32
SLIDE 32

26 October 1999 Components in Windows, some history and experiences. 32

www.softbit.fi

SOFTBIT

Handlers (Com servers)

  • Simple message interpreters (no UI)
  • Encapsulates specifics of particular

phone system (moving target)

  • Enables multi-site development (for

example in the USA).

slide-33
SLIDE 33

26 October 1999 Components in Windows, some history and experiences. 33

www.softbit.fi

SOFTBIT

C++ Classes

  • Application is made up of:

– One main executable module containing main window, menu, etc. – 4 or 5 DLLs with most functionality

  • SerialPort
  • Graphing
  • MessageRouter
  • ….
slide-34
SLIDE 34

26 October 1999 Components in Windows, some history and experiences. 34

www.softbit.fi

SOFTBIT

ActiveX controls

  • Is messy to use from C++, MFC helps.
  • But… It gets the job done.
  • ActiveX controls are okay for objects

that do some specific functions

– displaying maps – displaying tables from databases, etc.

slide-35
SLIDE 35

26 October 1999 Components in Windows, some history and experiences. 35

www.softbit.fi

SOFTBIT

Experience

  • Architecture is successful.
  • Simplicity of COM servers allowed

many people to work on phone specific protocol stuff.

  • C++ DLL classes assisted:

– Reducing compile dependencies – Allowing replacement if bugs were found.

slide-36
SLIDE 36

26 October 1999 Components in Windows, some history and experiences. 36

www.softbit.fi

SOFTBIT

Demo: A C++ DLL component application

slide-37
SLIDE 37

26 October 1999 Components in Windows, some history and experiences. 37

www.softbit.fi

SOFTBIT

PC-Suite for 9110

  • Framework developed by PumaTech.
  • Contacts plug-in developed at Softbit

– No source-code was ever exchanged!

  • New plug-ins are possible

– Own menus, icons, own helps, etc.

  • NO COM required!
  • Supports dynamic loading, location of

services, etc.

slide-38
SLIDE 38

26 October 1999 Components in Windows, some history and experiences. 38

www.softbit.fi

SOFTBIT

Architecture

  • Uses C++ in DLLs with MFC support!

– Called an “Extension DLL”

  • Uses RUNTIME_TYPE information so

that MFC can create instances as needed.

  • Restriction: only works with MFC

applications, and doesn’t work distributed.

slide-39
SLIDE 39

26 October 1999 Components in Windows, some history and experiences. 39

www.softbit.fi

SOFTBIT

Architecture

Component (DLL) Framework (EXE) MFC (2) (1) (3)

(2) Callback function (3) Windows messages (4) Communicator handling

CView Main Window (3)

See: “Dynamic Runtime Objects: Building Applications Your Users Can Modify at Runtime”, July 1997 Microsoft Systems Journal.

slide-40
SLIDE 40

26 October 1999 Components in Windows, some history and experiences. 40

www.softbit.fi

SOFTBIT

Experience

  • Architecture is successful.
  • MFC Extension classes are nice:

– Messages are passes through MFC message routing mechanisms, – Program in C++, – callbacks are simple.

slide-41
SLIDE 41

26 October 1999 Components in Windows, some history and experiences. 41

www.softbit.fi

SOFTBIT

Experiences Conclusion

slide-42
SLIDE 42

26 October 1999 Components in Windows, some history and experiences. 42

www.softbit.fi

SOFTBIT

C++ or COM?

  • Use C++ DLLs whenever possible to

provide more robust applications, that are easier to develop, debug and maintain.

  • Use COM when you need to develop on

multisites or need to involve external persons.

slide-43
SLIDE 43

26 October 1999 Components in Windows, some history and experiences. 43

www.softbit.fi

SOFTBIT

MFC Extension DLL’s

  • MFC is good. There are a lot of code

examples available on internet.

  • Extension DLL’s make component

writing easy and connects everything up nicely.

slide-44
SLIDE 44

26 October 1999 Components in Windows, some history and experiences. 44

www.softbit.fi

SOFTBIT

COM Experience

  • COM basics are easy and work well.
  • Should your component work in any

arbitrary container? Why?

  • Only use as much of COM as needed.

– Don’t make yourself a giant OLE in place active document server! In place active is junk. No

  • ne can run Excel inside of Word anyway.
slide-45
SLIDE 45

26 October 1999 Components in Windows, some history and experiences. 45

www.softbit.fi

SOFTBIT

Design basics

  • Reduce dependencies

– Avoid “Component soups”, unless necessary. – Consider layers, or façade patterns. – Group common functionality into packages.

  • Isolate pieces

– Isolate moving targets, and buggy spots in code

  • places where you don’t know everything. These

are good candidates for components.

slide-46
SLIDE 46

26 October 1999 Components in Windows, some history and experiences. 46

www.softbit.fi

SOFTBIT

Design = tough questions

  • Consider all the alternatives.
  • DLLs, C++ extension DLLs, Sockets for cross

process instead of DCOM, etc., Java, ...

  • Make your architecture stand up to

scrutiny.

  • Be realistic: understand your customer’s

budget and time constraints - give them the components they need… (not more).

slide-47
SLIDE 47

26 October 1999 Components in Windows, some history and experiences. 47

www.softbit.fi

SOFTBIT

Are components always better?

slide-48
SLIDE 48

26 October 1999 Components in Windows, some history and experiences. 48

www.softbit.fi

SOFTBIT

Thomas O’Rourke +358 400308204 Softbit Oy www.softbit.fi

slide-49
SLIDE 49

26 October 1999 Components in Windows, some history and experiences. 49

www.softbit.fi

SOFTBIT

Additional Notes and Automation example

slide-50
SLIDE 50

26 October 1999 Components in Windows, some history and experiences. 50

www.softbit.fi

SOFTBIT

COM Books

  • “Effective COM”, by Don Box, is my

favorite.

– An objective view of COM – I totally agree with his statements

  • Dual interfaces are JUNK
  • Connection points are STUPID.
  • etc.
slide-51
SLIDE 51

26 October 1999 Components in Windows, some history and experiences. 51

www.softbit.fi

SOFTBIT

Nemo’s SAM

slide-52
SLIDE 52

26 October 1999 Components in Windows, some history and experiences. 52

www.softbit.fi

SOFTBIT

Automation-enable your application

  • User’s can control your application.
  • They can use it to do things you have

not thought of.

  • MFC provides good support for doing

this.

  • User can use it from Visual Basic, etc.
slide-53
SLIDE 53

26 October 1999 Components in Windows, some history and experiences. 53

www.softbit.fi

SOFTBIT

Sam.exe (interprets measurement

  • data. Does conversions,

indexing, highly efficient) Measurement data Visual Basic program Formatted data

Quality Power level Number of dropped calls Average quality per dropped call

Commands

Scenario: User wants to make a custom report in excel.

slide-54
SLIDE 54

26 October 1999 Components in Windows, some history and experiences. 54

www.softbit.fi

SOFTBIT

Exporting all Power Level values from SAM.exe into excel (Excel VB Code)

Dim SAM As AutoApplication Dim ret As Boolean Set SAM = New AutoApplication Set filecollection = SAM.Workspace.Item("files") Set datasetcollection = SAM.Workspace.Item("datasets") Set file = filecollection.Add ret = file.Load(“Filename and path”) Set dataset = datasetcollection.Add ret = dataset.SetFile(file.Id) dataset.Filter(“$EventType = MSP”) For counter = 1 To dataset.Count ActiveSheet.Cells(counter, 1).Value = dataset.GetEventParameters(counter) Next counter dataset.Close file.Close