The Wayback Machine - https://web.archive.org/web/20130130172026/http://www.codeguru.com/cpp/com-tech/complus/admin/article.php/c3949/Programming-the-COM-Admin-Objects-in-Visual-C.htm

Programming the COM+ Admin Objects in Visual C++

Environment: Windows 2000, Visual C++ 6, Visual Basic 6

I started exploring programmatic administration of COM+ applications when we came across the requirement of changing the components constructor string via an MMC snapin as well as allow the flexibility to add a predetermined set of roles and allocate users to them at one shot via some installation script.

The project involved a typical WinDNA application with COM+ components holding the business logic in the middle tier. A setup application installed the COM+ application with the components and all their attributes.

Typically every com+ application has the following configurable parameters of which some could be set through the component services tool and some cant :

For details refer MSDN/ Platform SDK/Component Services/COM+/Reference/COM+ Administrators Reference

AccessChecksLevel, Activation, ApplicationAccessChecksEnabled, ApplicationProxy, ApplicationProxyServerName, Authentication, AuthenticationCapability, Changeable, CommandLine, CreatedBy, CRMEnabled, CRMLogFile, Deleteable, Description, EventsEnabled, ID, ImpersonationLevel, Identity, IsSystem, Name, Password, QueuingEnabled, QueueListenerEnabled, RunForever, ShutdownAfter, 3GigSupportEnabled .

For individual Components in the application following parameters are configured:

AllowInprocSubscribers, ApplicationID, CLSID, ComponentAccessChecksEnabled, COMTIIntrinsics, ConstructionEnabled, ConstructorString, CreationTimeout, Description, DLL, EventTrackingEnabled, ExceptionClass, FireInParallel, IISIntrinsics, IsEventClass, JustInTimeActivation, LoadBalancingSupported, MaxPoolSize, MinPoolSize, MultiInterfacePublisherFilterCLSID, MustRunInClientContext, ObjectPoolingEnabled, ProgID, PublisherID, Synchronization, ThreadingModel,Transaction, VersionBuild, VersionMajor, VersionMinor, VersionSubBuild.

The complete list for other related collections like Roles, RolesForComponent, etc could be found in the Platform Sdk doc.

A programmatic approach to configure all the above parameters is provided via the com+ administration objects.

The administration objects provide a way to access and manipulate all of the COM+ configuration data otherwise accessible through the Component Services administration tool. You can use these objects to automate all tasks in COM+ administration. These admin objects let us read and write information stored on the COM+ catalog, the underlying data store that holds all COM+ configuration data.

Throughout MSDN and the platform SDK there was no sample code available for VC++ developers (at least I couldnt find any) So I decided to write one.

Visual studio doesnt come with the header files or IDL files for COMAdmin.dll. So it isnt as easy as including the header file in your project and getting to work with CoCreateInstance for the appropriate interface on the appropriate coclass.

The COM+ 1.0 Type Library in OLEVIEW looks something like this.


Click here for larger image

What I found was that The COM+ admin objects consists of three components(coclasses in idl). Each of them having one main dispinterface as the default interface(as each coclass implemented one interface only). For example, the coclass COMAdminCatalog implemented one interface ICOMAdminCatalog.

coclass COMAdminCatalog {
 [default] interface ICOMAdminCatalog;
};

This component represents the COM+ Catalog Manager.

The reason I guess these components exposed dispinterfaces were because they needed to be accessed via installation scripts run under WSH or through VB.

Talking more about the objects, There are logical collections such as Applications, Components and Roles which map to COMAdminCatalogCollection component.Similarly logical collections like Application, Component and Role map to the COMAdminCatalogObject component.The COMAdminCatalog stands as the root object and it contains the Applications Collection.The Roles and the Components collection could be retrieved from the Applications collection. Similarly the other collections specific to a component say "RolesForComponent" could be retrieved from the Components collection.

Did I hear yukss when I said dispinterfaces. GOSH!! Isn't that a PAIN to program in C++ - GetIdOfNames, DISPIDS, Invoke.

VB developers never have to deal with raw VARIANT structures, setting discriminants, calling SysAllocString to allocate BSTR's. But in C++ we have to !

Does that mean it is difficult to code COM+ admin objects in c++ ?

NO ! the sample code uses the #import directive to incorporate information from the COM+ admin type library.

The sample is a simple Win32 application. With a little smart pointer code, the code looks similar to VB code. :)

All you gotta say is

#import "c:\\winnt\\system32\\com\\Comadmin.dll" no_namespace

The no_namespace directs the compiler not to generate the type library information in a namespace, and hence contents like Interface names need not bebe prefixed with the namespace::

There , and you are all set to use the components without ever knocking on IUnknown's door. All the AddRef(), Release() and QueryInterface happen silently.

For example :

ICOMAdminCatalogPtr spCatalog("COMAdmin.COMAdminCatalog");

The above call is translated to a cocreateinstance call for the COMAdminCatalog component and a pointer to the interface is retrieved.

The rest of the code is similar to VB.

The sample does the following:

  • Creates a HelloWorld COM+ Application called "HelloWorld"
  • Installs a HelloWorld component in to the application
  • Sets the different Roles that the application might need
  • Sets the roles explicitly for every component(one in this case)
  • Sets the ConstructorString for the component

I have included a sample VB activeX dll project HelloWorld.vbp which exposes a method, you could replace that with your own component if you wish to.

CHANGE the default value of the #defines if you wish to override default values for the HelloWorld application.
ESPECIALLY the value of the HELLOWORLD_DLL_PATH to reflect the path where the VB Sample DLL is located.

Please change the path of the component in the #define to reflect the path of the component you wish to include in the COM+ application

Please find attached the demo project with the HelloWorld VB component, that could be used to add to the com+ application.

This article is a result of my experiences with the programming of COM+ admin objects. I assume that the application will be running under adequate user rights.

If the code works, it was written by me. Otherwise, I dont know who the hell wrote it :)

References

  • Platform SDK documentation
  • Ted Pattison's article on COM+ admin objects on MSDN

Downloads

Download demo project with source - 41 Kb

IT Offers

Comments

  • COM+ remote creation cause Run-Time Error 424

    Posted by Legacy on 11/06/2003 12:00am

    Originally posted by: mj

    Hi:

    I have a com+ component installed using a application proxy on a remote computer.

    The problem occurs when you try to initiate the remote component. That is the "Rum-Time Error 424 Object Required" error occurs when following statement is executed:

    Set foo = CreateObject("MyComponent.MyClass1.1")

    where MyComponent.MyClass1.1 is installed as a COM+ application proxy.

    Interestingly, the component is activated is the on the server, i.e., you can see the rolling ball icon in the component services snapin as the result of CreateObject. However, overall CreateObject is not successful.

    Could it be related to the way the application proxy is created. I simply export the COM+ application proxy from the Component Services Snapin and the run the resulted Windows Installer Package on the client machine. Is this the correct of doing it?

    Could it be networking issue? I have a pier-to-pier topolgy. The COM+ security is set to Interactive at this stage. Both computers are logged on by administrators.

    No system error events are logged as the result of the attempt to access the remote server.

    Reply
  • How to using COM .dll file in VC++

    Posted by Legacy on 10/26/2003 12:00am

    Originally posted by: Lucy Tang

    Hi, guys,

    I have no experience to use COM.

    I have an dll file created by COM, PulsCOM.dll, I regester it. I create a client application using VB to use it. it works fine. in VB, I create the object like:
    Dim ptr as PulsCOM.CMaterial
    ptr = new PulsCOM.CMaterial

    Now I want to create a client application using VC++, only with the dll file, it's enough for me to create COM object?

    I wrote codes like the following:

    #import "PulsCOM.dll"

    void main(){
    CMaterialptr obj;
    }

    the error message is "CMaterialptr is undefinition identifier"

    I also use "CMaterial" and "_CMaterial", but have the same error msg. Did I missing some step or some files to use COM dll? From where I can know what is the data type?

    who can help me to answer these questions?
    Please help me as soon as possible

    Reply
  • How to Write COM in SDK (win32)

    Posted by Legacy on 09/17/2003 12:00am

    Originally posted by: hemachandra naidu


    if any one can know how to write COM prgs in
    Platform SDK .Plz send some Examples and decription to my mailID.

    Reply
  • COM+ Application to Register my COM Component (VC++). Please Help .........

    Posted by Legacy on 08/29/2003 12:00am

    Originally posted by: Atif

    Hi Dears
    I have to make a simple COM+ Application programatically to register my ATL COM Component.
    Please guide me to build that in VC++ ........
    I'll be really thankful.
    God bless you.
    Kind Regards.
    Atif

    Reply
  • how to create proxy?

    Posted by Legacy on 07/23/2003 12:00am

    Originally posted by: Sokel

    how to create proxy application programmatically?
    ("AplicationProxy" property is ReadOnly)

    Reply
  • COM+ not pooling or hangs..

    Posted by Legacy on 04/22/2003 12:00am

    Originally posted by: Manuel

    Can anyone help me in this.

    I have a set of components put together in a package. Inside teh package some of the components are pooled and some not.

    This package was working well for the past 2 years. When I installed this in a box which has .NET. The package is not created or objects not pooled is happening.

    Sometime when I delete and create manually the package it works. Again when there is a next production drop same problem.

    Please help me if you know what is the issue.

    Thanks in advance.

    Reply
  • Kozly, gondony!!!

    Posted by Legacy on 04/10/2003 12:00am

    Originally posted by: DDD

    Kozly, gondony!!!

    Reply
  • Does anyone knows how to over the security of COM+ ?

    Posted by Legacy on 04/08/2003 12:00am

    Originally posted by: victorwen

    when I call the server application from the client on the other machine, I can create component object, but when I
    call the methods of the object, the HRESULT is -2147024891, I have tried to set the security context of the server application, but the result is the same.

    Reply
  • Anyone tell me how to using code to change the servername in the mmc com manage

    Posted by Legacy on 03/06/2003 12:00am

    Originally posted by: Darmily

    Anyone tell me how to using code to change the servername in the mmc com manage.

    because i want to export this com to other computer.

    Reply
  • Anyone help me to find faults on windows NT server

    Posted by Legacy on 02/18/2003 12:00am

    Originally posted by: Vishal Shah

    hi!
    i m trying to build an application that will run in background and detect any fault(hardware nand software)
    that will be generated.But i couldn't found any sites or any paper that would help me on this.so if anyone can help me then i will be very grearful to him.

    thanks.
    Vishal.

    Reply
  • Loading, Please Wait ...

Go Deeper

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds