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

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

Increments or decrements the lock count

Increments or decrements the lock count - раздел Образование, Creating a COM object in ASM   Lockserver Keeps The Class Factory Instanced (Helpful If One ...

 

LockServer keeps the class factory instanced (helpful if one has to make numerous object copies). CreateInstance is the workhorse here, it is used to creates the object's "working" interface. Each class creates a class factory that solely knows how to create that particular class, since CreateInstance does not include a class reference ID. The class ID was specified when we created this class factory interface. Thus, a class factory only knows how to create interfaces of the class of which it is a member. It's sole purpose is to create the desired object class.

 

This indirection is useful if the class needs some special initiation. IClassFactory is necessary to handle aggregation (a topic I will have nothing more to add, and which the component made here does not support). Already, there is a definition for IClassFactory2, which checks licensing for the component.

 

To actually get your COM object, a client calls DllGetClassObject by invoking the CoCreateInstance API function. This API takes care of handling the class factory for you, and return the desired interface pointer. If you just need a plain vanilla object, this is the function to use. The CoGetClassObject API will return a pointer to IClassFactory is your class needs further creation parameters. Internally, CoCreateInstance itself calls CoGetClassObject and instance the class through IClassFactory, so you always need it define a class factory object creation interface.

 

 

Classes, Objects, you and THIS

---------------------------------------------------------------------------------------------------------------------I'm going to digress into some internal implementation details on how C++ handles objects. One can be a proficient C++ programmer and never fully understand this, as it is a level of complexity the compiler handles fully for you. However, the designers of COM took full advantage of the concept, and we need to understand this.

 

The new fundamental concept the ++ in C++ adds to the language is the concept of classes and objects. And object is an instance of a class. Let's explore what this means on a machine level. When we write a conventional program in asm, we depend on the compiler to create code and data segments for us. One area in memory is the code we execute, another holds the data we need. What the ++ in C++ does for you is dynamically reallocate data memory at run time, giving each instance of a class, each small segment of code it's own data segment. In a very real way, the instance of a class IS this data segment. Data specific to each instance (or copy) of the class is stored in this dynamic data area.

 

Perhaps you have heard that C++ passes an extra hidden parameter in function calls on an object, the THIS value. Whoever named this concept not only understood what was required, but had a good sense of humor. When one is writing low level code for an object (something the compiler usually does for you in C++), the first question one will have is "which object am I the code for?"

 

THIS is which object, one is always working with THIS object.

 

THIS is simply a pointer to the data memory area for THIS instance of the class. When an objects class function is called, THIS is silently passed on. When the private data of the object is accessed, the class code area uses THIS to reference where that data is for THIS instance.

 

Why is THIS important? Simply this: a pointer to a COM interface is same thing as the pointer to THIS. My Grammar checker is going nuts at me now, it may not be correct English but this is how THIS works.

 

In use, COM is simply a specification of interfaces. It says nothing about how they are actually implemented in code. In fact, it is written so such details are not defined such that any higher level language that implements these interfaces may be a COM server.

 

I defined my "class" data areas (the "objects") as thus:

 

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

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

Creating a COM object in ASM

aggregate REFIID riid... Reference to the interface identifier... Oid ppvObject Address of output variable that receives...

Если Вам нужно дополнительный материал на эту тему, или Вы не нашли то, что искали, рекомендуем воспользоваться поиском по нашей базе работ: Increments or decrements the lock count

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

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

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

Creating a COM object in ASM
  Copyright © Dec 27, 2000 by Ernest Murphy ernie@surfree.com For educational use only. All commercial use only by written license.   Revised December

MyComObject ENDS
  The first point is I have great latitude in defining this structure. The only element that the COM contract imposes on it is that it contain a DWORD pointer to the vtable of functio

Interface IMyCom : IUnknown
{ [propget, helpstring("property Value")] HRESULT Value([out, retval] long *pVal); [propput, helpstri

Coclass MyCom
{ [default] interface IMyCom; }; };     This file can be used as

RaiseValue PROTO :DWORD, :DWORD
  BIG difference... but for a simple reason. Interfaces written for type libraries are as general as can be, and are directed at clients such as Visual Basic, and VB is designed to ho

Typelib MyCom.tlb
  Making it the first resource element is important, as later on we will be using the LoadTypeLib API function to extract this library, and this function expects to find the library a

HKEY_CLASSES_ROOTTypeLib{A21A8C42-1266-11D4-A324-0040F6D487D9}1.0HELPDIR
(Default) "C:masm32COMMyCom"   One key value here is variable, that is the path and name of the server dll itself. On my system I placed it at &quo

AddRef_MC endp
  AddRef is a bit unusual in that it does not return a HRESULT (failure code), instead it returns the object count. The return value is undefined in the COM contract, but it is tradit

RaiseValue ENDP
    MyCom.dll, the server code ---------------------------------------------------------------------------------------------------------------------To build the

End Sub
  Now you can run the application and test the server by clicking the Raise button. Do be careful, there is no error checking to see if you put a valid number in Text2. What you are s

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