July 16, 2001 tools

MeowMoniker

If you’re into COM Monikers, here’s one that I like.

July 15, 2001 fun

Can I still be evil?

July 15, 2001 tools

Basic Monikers

Wish there was a moniker that did CoCreateInstance just like the Class Moniker calls CoGetClassObject? Wish you were able to compose the Class Moniker with a host name? Then you’ll want the BasicMonikers project, which bundles together the New moniker and the Host moniker. Sample syntax follows:

dm.newmk.1:Excel.Application
dm.newmk.1:00024500-0000-0000-C000-000000000046:
dm.hostmk.1:frodo:!dm.newmk.1:00024500-0000-0000-C000-000000000046:
dm.hostmk.1:frodo:!clsid:00024500-0000-0000-C000-000000000046:
July 14, 2001 tools

regsvr.reg

July 14, 2001

regsvr.reg is a regedit script file that adds Register COM Server and Unregister COM Server to the context menu for DLLs, OCXs and EXEs under Win95+ and NT4+. In addition, it’s also been updated to add Register TypeLib and Unregister TypeLib commands to .tlb, .odl, .dll, .ocx and .exe files, using VC6′s new regtlib tool.

July 13, 2001 tools

ATL Composition

July 13, 2001

I’ve developed a set of macros to support implementing interfaces using nested composition in ATL (the one common way of implementing interfaces they neglected). The benefit of composition is that it is easy to implement multiple interfaces with methods with the same name but that require different behavior, e.g.

interface IArtist : IUnknown {
     HRESULT Draw();
}

interface ICowboy : IUnknown {
     HRESULT Draw();
}

The benefit of this particular implementation is that it has no object size overhead. Interfaces implemented using nested composition have no greater overhead than using multiple-inheritance. Feel free to download atlcompose.h for your own use.

July 12, 2001 tools

STL Enumerator Iterator

Have you ever been jealous of the VB programmer who could write this:

sub EnumVariants(col as Collection)
    dim v as variant for each v in col
        ' Do something with v
    next v
end sub

when we poor C++ programmers have to write this:

void EnumVariants(IEnumVARIANT* pevar)
{
    HRESULT hr;
    enum { CHUNKSIZE = 100 };
    VARIANT rgvar[CHUNKSIZE] = { 0 };
    do {
        ULONG cFetched;

        hr = pevar->Next(CHUNKSIZE, rgvar, &cFetched)
        if( SUCCEEDED(hr) ) {
            if( hr == S_OK ) cFetched = CHUNKSIZE;
            for( ULONG i = 0; i < cFetched; i++ )
            {
                // Do something with rgvar[i]
                VariantClear(&rgvar[i]);
            }
        }
    }
    while (hr == S_OK);
}

Well no more! I’ve built an enumeration iterator class that holds IEnumXxx and exposes an STL-compatible iterator:

template <typename EnumItf, const IID* pIIDEnumItf,
          typename EnumType, typename CopyClass = _Copy<EnumType> >
class enum_iterator;

It uses the same copy policy classes as ATL for convenience. Now you can write:

void EnumVariants(IEnumVARIANT* pevar)
{
    typedef enum_iterator<IEnumVARIANT, &IID_IEnumVARIANT, VARIANT> EVI;
    for( EVI i = EVI(pevar); i != EVI(); ++i )
    {
        VARIANT&    v = *i;
        // Do something with v
    }
}

or you can use the typedefs for the standard enumerators:

void EnumVariants(IEnumVARIANT* pevar)
{
    for( variant_iterator i = variant_iterator(pevar);
         i != variant_iterator();
         ++i )
    {
        VARIANT&    v = *i;
        // Do something with v
    }
}

or you can use STL algorithms (this is my personal favorite):

struct DoSomethingWithVariant
{
    void operator()(const VARIANT& v)
    {
        // Do something with v
    }
};

void EnumVariants(IEnumVARIANT* pevar)
{
    for_each(enum_variant(pevar),
             enum_variant(),
             DoSomethingWithVariant());    
}

Feel free to download the enum_iterator class for your own use. You’ll also need a supporting file, atlcopies.h.

July 12, 2001 tools

Client-Side Enumeration Iterator

July 12, 2001

Have you ever been jealous of the VB programmer who could write this:

sub EnumVariants(col as Collection)
    dim v as variant for each v in col
        ' Do something with v
    next v
end sub

If so, you may be interested in the STL-style IEnumXxx iterator I’ve built. You’ll also need a supporting file, atlcopies.h.

July 11, 2001 tools

GitHelp

July 11, 2001

githelp.hdefines a set of wrappers for implementing inter-thread marshaling using the GIT instead of streams. githelp.cpp provides the non-inline implementation. For another spin on GIT usage, check out Don Box’s GitLip.


← Newer Entries Older Entries →