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

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

HKEY_CLASSES_ROOTTypeLib{A21A8C42-1266-11D4-A324-0040F6D487D9}1.0HELPDIR

HKEY_CLASSES_ROOTTypeLib{A21A8C42-1266-11D4-A324-0040F6D487D9}1.0HELPDIR - раздел Образование, Creating a COM object in ASM (Default) "c:masm32Commycom"   ...

(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 "C:MASM32COMMYCOMMYCOM.DLL" This was detected when I registered the component, as one other function of DllRegisterServer is to discover where the dll itself is stored by invoking GetModuleFileName.

 

This is a lot of information for one little server. But all we need know to instance our server is pass the ID of {A21A8C43-1266-11D4-A324-0040F6D487D9} and a valid interface ID to CoCreateInstance. We need not know where it the component is, nor place it in a special directory. The CoCreate API's will trace through the registry settings, starting with the CLSID to discover all it needs to know to create the component. Once it has the component, it can load the type library from that to learn more if need be.

 

Fortunately for us, the last 5 registry entries are done for us via the RegisterTypeLib API. In DllRegisterServer we call a series of registry functions to set the first 5 keys and values, then invoke RegisterTypeLib. DllUnregisterServer just winds through this structure and deletes all the entries it made, then invokes UnRegisterTypeLib. When deleting keys, do take care NOT to delete the entire HKEY_CLASSES_ROOTCLSID tree, as you will completely mess up your system and partially uninstall every other activeX component on your system.

 

A type library itself is defined as a "dense black blob" of binary data. The sole property of its internal structure revealed by Microsoft is the first 4 bytes shall be the ASCII code for "MSFT." To learn what is inside, API methods must be employed. Again, this keeps the COM contract language neutral.

 

 

Implementing the Unknown

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

MyCom is a very simple object, it only impliments two interfaces, IUnknown and IMyCom. Since these two interfaces overlap, the returned ppv pointer need not be cast to either interface, and our very simple object structure will suffice. If you continue on to the CoLib (Component Library), you will see a much more involved object structure is required if multiple, non-overlapping interfaces are supported.

 

Object lifetime is handled by the IUnknown interface. These three seemingly simple methods of AddRef, Release, and QueryInterface are quite powerful, and are used such that the functionality of each is never duplicated in another section.

 

This non duplication of function is perhaps the impetus in why IUnknown was named such. When DllGetClassObject is invoked, the object CLSID and a specific interface IID are passed in to define what needs to be created. Think for a second: we are in effect asking DllGetClassObject to perform a QueryInterface on the object before we create it. That is not what happens, since we do not want to duplicate functionality (i.e., two identical QueryInterface implementations, one in the QueryInterface itself, one in DllGetClassObject). If nothing else, we would not want to maintain two sections of code that should have similar output.

 

Instead, when DllGetClassObject is invoked, we simply create the object defined by the CLSID. In effect, we create an unknown object. What is unknown is: Can this object support the interface we require?

 

That question is easily answered. DllGetClassObject will invoke QueryInterface on the unknown object. If it truly supports the interface, this reference is returned. If it does not support it, the object is deleted, and the DllGetClassObject returns a fail code.

 

AddRef is quite simple to implement. Since we have a simple object structure, and "this" is the base address of this structure, we can directly access all members of the object.

 

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

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

Creating a COM object in ASM

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

Если Вам нужно дополнительный материал на эту тему, или Вы не нашли то, что искали, рекомендуем воспользоваться поиском по нашей базе работ: HKEY_CLASSES_ROOTTypeLib{A21A8C42-1266-11D4-A324-0040F6D487D9}1.0HELPDIR

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

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

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

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

Increments or decrements the lock count
  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 "work

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

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
Реклама
Соответствующий теме материал
  • Похожее
  • Популярное
  • Облако тегов
  • Здесь
  • Временно
  • Пусто
Теги