рефераты конспекты курсовые дипломные лекции шпоры

Реферат Курсовая Конспект

Component Object Library

Component Object Library - раздел Образование, And the CoLib Copyright © Dec 28, 2000 By Ernest Murphy Ernie@surfree.com For Educ...

Copyright © Dec 28, 2000 by Ernest Murphy ernie@surfree.com

For educational use only. All commercial use only by written license.

 

Re-written Dec 28 2000 for the MASM32 package

 

 

Abstract:
--------------------------------------------------------------------------------------------------------------------

A simple COM object is created through a library of reusable functions. The requirements for using this library are discussed.

As this is still a work in progress, there will be minimal explanation given for how the lib works. Release version 1.0. IDispatch is fully working. The requirements for using this library will be given.

 

 

--------------------------------------------------------------------------------------------------------------------

In an earlier article I discussed some code that created the fully functional, albeit very simple COM object MyCom. That may now be used as a guide as to what a server must do. The current project creates MyCom2, which while having an identical set of methods inherits from IDispatch and thus supports a dual interface for either early or late binding. One interesting aspect aspect of this addition is the file sizes. The dll grew from 7168 to 12,288 bytes, a total increase of only 5120 bytes for a significant addition of reusable functionality provided by standard library functions.

 

In writing this library, a simple thought was kept in mind: make it all things to all peoples. Here is a list of the goals of CoLib.lib:

 

· By including CoLib.inc and CoLib.lib, not one line of code or byte of data shall be added to a project. Library functions are added by the linker.

 

· Individual library functions may be excluded from use should you wish to customize particular functions without editing the library.

 

· The 5 DLL exports shall be included and reusable.

 

· Multiple objects may be incorporated in a single DLL.

 

· Each object may contain multiple interfaces.

 

· Aggregation is supported.

 

· IDispatch is supported.

 

· Localization for IDispatch is supported

 

· Registrar scripting is supported using same syntax as the ATL library.

 

· All type libraries included in the resource are automatically registered and unregistered.

 

However, CoLib.inc is a work in progress. The following is a list of known issues and "things yet to do."

 

· The registry exports simply do not work under Windows 2000.

 

· No method is included to allow a lib object to aggregate other objects. This is planned for a future addition.


Finally, the fun part of this is when we get to writing the server code itself. When originally defined the simple COM server MyCom the .asm contained some 632 lines and 23,539 bytes. MyCom2.asm is just 72 lines of assembly and a remarkable 30 lines total in the .code section. Obviously, much of the overhead has been shifted to the library. Let's start by examining this code in Part II

 

 

--------------------------------------------------------------------------------------------------------------------

Here is the complete asm source code for the MyCom2 object. This object is identical to MyCom, except it inherits from IDispatch and thus has a dual interface. Statements defined by the lib are highlighted in blue.

 

 

;-------------------------------------------------------------------------------

; MyCom2.dll copyright 7/15/00 Ernest J Murphy

;

; sample project to illustrate how to use CoLib, a Component Object Library

;

;-------------------------------------------------------------------------------

 

.NOLIST ; keep the list file small, don't add the std libs to it.

.386

.model flat, stdcall

option casemap:none ; case sensitive

 

;-------------------------------------------------------------------------------

include masm32includewindows.inc

include masm32includeuser32.inc

include masm32includekernel32.inc

include masm32includeadvapi32.inc

include masm32includeoleaut32.inc

include masm32includemasm32.inc

include masm32includeole32.inc

 

include masm32comincludeoaidl.inc ; basic COM definitions

include masm32comincludecolib.inc ; the new library

 

include IMyCom2.inc

 

includelib masm32libuser32.lib

includelib masm32libkernel32.lib

includelib masm32libadvapi32.lib

includelib masm32liboleaut32.lib

includelib masm32libole32.lib

includelib masm32libmasm32.lib

 

includelib masm32comcolibcolib.lib ; the new library

 

PUBLIC ClassMap ; need to export ONLY the ClassMap

 

;-------------------------------------------------------------------------------

.LISTALL

.data

 

; describe the classes inside the DLL

ClassMap ClassItem { pCLSID_MyCom2, DISPINTERFACE + SUPPLY_TYPE_INFO,

OFFSET MyCom2TypeLibInfo, OFFSET MyCom2IMap,

CreateMyCom2, NULL, SIZEOF MyCom2Object }

END_CLASS_MAP

 

; describe the MyCom2 object's interfaces

MyCom2IMap InterfaceItem { pIID_IMyCom2, OFFSET vtableIMyCom2 }

END_INTERFACE_MAP

 

; describe the type libraries

MyCom2TypeLibInfo TypeLibInfo { pLIBID_MyCom2, 1, 0 }

 

; describe the MyCom2 object itself (takes 2 steps)

; step 1

MyCom2ObjData STRUCT ; MyCom2 object private data struct

m_Value DWORD 0 ; Value (private data member)

MyCom2ObjData ENDS

 

; step 2

MyCom2Object STRUCT

ObjectData0 ObjectData { } ; base values

MyCom2ObjData0 MyCom2ObjData { } ; custom object data

ObjectEntry0 ObjectEntry { } ; delegated Unknown

ObjectEntry1 ObjectEntry { } ; IMyCom2

MyCom2Object ENDS

 

; fill in the vtable

vtableIMyCom2 IMyCom2 { pvtIDispatch, GetValue, SetValue, RaiseValue }

 

; define the interface IID's

DeclareGuid IID_IMyCom2

DeclareGuid CLSID_MyCom2

DeclareGuid LIBID_MyCom2

 

;-------------------------------------------------------------------------------

.code

CreateMyCom2 PROC this_:DWORD

pObjectData this_, edx ; cast this_ to object data

xor eax, eax ; get variable

mov (MyCom2ObjData ptr [edx]).m_Value, eax ; store new value

ret ; return S_OK

CreateMyCom2 ENDP

 

;-------------------------------------------------------------------------------

GetValue PROC this_:DWORD, pval:DWORD ; GetValue for the IMyCom Interface

pObjectData this_, edx ; cast this_ to object data

mov eax, (MyCom2ObjData ptr [edx]).m_Value ; get object data value

mov ecx, pval ; get ptr to variable for return

mov [ecx], eax ; mov value to variable

xor eax, eax ; return S_OK

ret

GetValue ENDP

 

;-------------------------------------------------------------------------------

SetValue PROC this_:DWORD, val:DWORD ; SetValue for the IMyCom Interface

pObjectData this_, edx ; cast this_ to object data

mov eax, val ; get variable

mov (MyCom2ObjData ptr [edx]).m_Value, eax ; store new value

xor eax, eax ; return S_OK

ret

SetValue ENDP

 

;-------------------------------------------------------------------------------

RaiseValue PROC this_:DWORD, val:DWORD ; RaiseValue for the IMyCom Interface

pObjectData this_, edx ; cast this_ to object data

mov eax, val ; get variable

add (MyCom2ObjData ptr [edx]).m_Value, eax ; add new value to current value

xor eax, eax ; return S_OK

ret

RaiseValue ENDP

 

;-------------------------------------------------------------------------------

end DllMain

 

 

--------------------------------------------------------------------------------------------------------------------

 

Now let's explain what these new library functions do for us:

First, we need to include the lib itself:

– Конец работы –

Эта тема принадлежит разделу:

And the CoLib

Include masm colib oaidl inc... Include masm colib colib inc... Includelib masm colib colib lib new library...

Если Вам нужно дополнительный материал на эту тему, или Вы не нашли то, что искали, рекомендуем воспользоваться поиском по нашей базе работ: Component Object Library

Что будем делать с полученным материалом:

Если этот материал оказался полезным ля Вас, Вы можете сохранить его на свою страничку в социальных сетях:

Все темы данного раздела:

PUBLIC ClassMap ; need to export ONLY the ClassMap
  All the library code is included by the linker as it resolves all the symbols, that is all we need do to fully invoke the library functions.   Our class will

MyCom2IMap InterfaceItem { pIID_IMyCom2, OFFSET vtableIMyCom2 } END_INTERFACE_MAP
END_INTERFACE_MAPis a macro to define a NULL interface to mark the end of the InterfaceMap.   Each object needs type library support. It needs a pointer to t

IMyCom2 Interface
;-------------------------------------------------------------------------- ; sIID_IMyCom2 TEXTEQU <{0F8CE5E41H, 01135H, 011D4H,

Add additional resources here starting at ID number 300
  This should be simple to duplicate. All you are specifying is the type library file and the resistrar script file. Should you have multiple objects, just keep adding the type librar

Interface IMyCom2 : IDispatch
{ [propget, id(0), helpstring("property Value")] HRESULT Value([out, retval] long *pVal); [propput, id(0), helpstring("pro

Coclass MyCom2
{ [default] interface IMyCom2; } }; There isn't much to say here, basically you *MAY* us

NoRemove CLSID
{ ForceRemove {F8CE5E43-1135-11d4-A324-0040F6D487D9} = s 'MyCom2 Class' { ProgID = s 'MyCom.MyCom2.1'

EXPORTS DllCanUnloadNow @1 PRIVATE DllGetClassObject @2 PRIVATE DllRegisterServer @3 PRIVATE DllUnregisterServer @4 PRIVATE
  This file is mostly boilerplate. All you need define is the LIBRARY name, which is optional as you really do not need the .lib file for a COM dll. The export names are always the sa

Хотите получать на электронную почту самые свежие новости?
Education Insider Sample
Подпишитесь на Нашу рассылку
Наша политика приватности обеспечивает 100% безопасность и анонимность Ваших E-Mail
Реклама
Соответствующий теме материал
  • Похожее
  • Популярное
  • Облако тегов
  • Здесь
  • Временно
  • Пусто
Теги