Читайте также:
|
|
6. Гилберт Стивен, Маккарти Билл Программирование на Visual C++ 6. Этюды профессионалов: Пер. с англ. – К.: Издательство “ДиаСофт”, 1999. – 368 с. (+ CD‑диск)
34. Системное программное обеспечение /А.В. Гордеев, А.Ю.Молчанов. – СПб.: Питер, 2001. – 736 с.
6. Дейтел Г. Введение в операционные системы: В 2‑х т.: Пер с англ. – М.: Мир, 1987. – т.1 – 359 с.; т.2 – 398 с.
9. Операционные системы: Деревянко А.С., Солощук М.Н. Учебное пособие. – Харьков: НТУ “ХПИ”, 2003. – 574 с.
11. Таненбаум Э. Современные операционные системы, 1‑е изд. – СПб.: Питер, 2002. – 1040 с.; 2‑е изд. – СПб.: Питер, 2004. – 1040 с.
13. Глушаков С.В., Коваль А.В., Черепнин С.А. Программирование на Visual C++ 6.0: – Харьков, Фолио, 2002. – 726 с.
14. Харт Джонсон М. Системное программирование в среде Win32: Пер. с англ. – М.: Издательский дом “Вильямс”, 2001. – 464 с.
6 Джеффри Рихтер Windows для профессионалов (программирование в Win32 API для Windows NT 3.5 и Windows 95): Пер. с англ. – М.: Издательский отдел “Русская редакция” ТОО “Channel Trading Ltd.”, 1995. – 720 с.
7. Рихтер Дж. Windows для профессионалов: создание эффективных Win32‑приложений с учетом специфики 64‑разрядной версии Windows: Пер. с англ. – СПб: Питер; М.: Издательско‑торговый дом “Русская Редакция”, 2001. – 752 с.
10. Саймон Р. Windows 2000 API. Энциклопедия программиста – К., Диасофт, 2001.– 1088 с. (есть CD)
10а. Саймон Ричард Microsoft Windows API. Справочник системного программиста. Второе издание, дополненное: Пер. с англ. – К.: ООО “ТИД “ДС”, 2004. – 1216 с.
11. Харт Джонсон М. Системное программирование в среде Win32: Пер. с англ. – М.: Издательский дом “Вильямс”, 2001. – 464 с.
12. Системне програмне забезпечення Windows: навч. посібн. / В.І. Панченко та ін.
– Харків: НТУ “ХПІ”, 2009. – 196 с.
13. Методичні вказівки до виконання та оформлення курсового проекту з навч. дисц. “Системне програмне забезпечення”. / Уклад. В.І. Панченко та ін. – Харків: НТУ “ХПІ”, 2010. – 72 с.
MyCom2 and the CoLib
Component Object Library
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 \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\advapi32.inc
include \masm32\include\oleaut32.inc
include \masm32\include\masm32.inc
include \masm32\include\ole32.inc
include \masm32\com\include\oaidl.inc; basic COM definitions
include \masm32\com\include\colib.inc; the new library
include IMyCom2.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\advapi32.lib
includelib \masm32\lib\oleaut32.lib
includelib \masm32\lib\ole32.lib
includelib \masm32\lib\masm32.lib
includelib \masm32\com\colib\colib.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:
Дата добавления: 2014-12-18; просмотров: 113 | Поможем написать вашу работу | Нарушение авторских прав |