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

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

Creating a COM object in ASM

Creating a COM object in ASM - раздел Образование, Creating a COM object in ASM   Copyright © Dec 27, 2000 By Ernest Murphy Ernie@surfree.com...

 

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

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

 

Revised December 27 for inclusion with MASM32

 

Sample code for this article is available at: .../COM/examples/MyCom

 

The Build DLL setting used for Quick Editor is at .../COM/BIN/BLDDLL.BAT

 

 

Abstract:

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

The COM (Component Object Model) is based on a non-specific implementation standard (neither platform nor language is specified), but real world constraints of real computers add practical considerations to this standard.

 

Here, a simple yet fully functional COM object in-process server for the WinTel platform will be created. It will be tested in a Visual Basic environment to assure it's compliance to the standard.

 

---------------------------------------------------------------------------------------------------------------------The programs discussed in here is designed be assembled with the MASM32 package. The Visual Basic client was written in VB6, which still sets its form version as 5. If one edits the VB5 version to VB4 it might work in earlier versions, but this has not been tested. It should also work in any VBA application, but again this has not been tested.

 

I will make no attempt to explain the basics of the Component Object Model nor the COM contract here. I'm going to assume you are familiar with both, and such details as the vtable, the vtable pointer and such. If you are not so familiar, I suggest you check the previous articles here, or the best source of explanation is Dale Rogerson's "Inside COM" (see bibliography).

 

Since COM objects must run not in some textbook but on real computers, they must follow certain implementation standards specific to that computer and operating system. For a WinTel in-process server, there already exists a well-defined standard to load a blob of code and unload it when no longer needed: the humble dynamic link library.

 

From one view, all an in-process COM server consists of is a .DLL with a set of 5 well defined exports. These are:

 

DllMain: This is the first routine in any dll. It is called when the library is loaded. It should check that the client (the calling app) wants an in-process server, and fail if not. (COM supports other instancing choices, but this app does not.)

 

DllRegisterServer: The registry holds data on every COM object installed on the system. This routine self-registers the component in the registry. It is how regsvr32.exe can register a component, regsvr32 just calls this export and displays the return value.

DllUnregisterServer: When no longer needed, a component should be able to unregister itself. Again, regsvr32.exe will call this export to clean out the registry.

 

DllCanUnloadNow: Global variables in the server keep track of any objects created, and also if a lock was placed on the server (explained in IClassFactory.LockServer). The client app will periodically call this export to check if the server is no longer needed and then unload it.

 

DllGetClassObject: Finally the magic COM export. This export takes 3 parameters, the GUID of the component to be created, the GUID of that component's interface to be created, and a pointer to the object thus created. If either the component or the interface requested are not supported, this routine fails.

 

The first 4 exports are straightforward. DllGetClassObject is the new strange thing, and needs further comment.

 

By now, one thing you should have noticed is that COM is about nothing if it isn't about indirection. That indirection gives the power to the methods. In practice, the object returned from DllGetClassObject is not the object we seek: it is a "class factory" object. A class factory object is one that knows how to instance (create) another class. This first lever of indirection allows the details of the object's creation to be specified. If it simply and directly returned a pointer to the object, then the object already exists, thus we cannot set and control any parameters in its constructor.

 

DllGetClassObject returns a IClassFactory interface. IClassFactory inherits from IUnknown (of course, every interface does), as has these two member functions:

 

HRESULT CreateInstance(

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

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

Creating a COM object in ASM

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

Если Вам нужно дополнительный материал на эту тему, или Вы не нашли то, что искали, рекомендуем воспользоваться поиском по нашей базе работ: Creating a COM object in ASM

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

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

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

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

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