Question

I'm trying to implement a COM's DllRegisterServer method.
So I read this tutorial:
http://www.codeguru.com/cpp/com-tech/activex/tutorials/article.php/c5567/Step-by-Step-COM-Tutorial.htm

and I followed the steps until the part of DllRegisterServer.
This is their implementation:

HRESULT  __stdcall DllRegisterServer(void)
    {
    //
    //As per COM guidelines, every self installable COM inprocess component
    //should export the function DllRegisterServer for printing the 
    //specified information to the registry
    //
    //

    WCHAR *lpwszClsid;
    char szBuff[MAX_PATH]="";
    char szClsid[MAX_PATH]="", szInproc[MAX_PATH]="",szProgId[MAX_PATH];
    char szDescriptionVal[256]="";

    StringFromCLSID(
            CLSID_AddObject,
            &lpwszClsid);

    wsprintf(szClsid,"%S",lpwszClsid);
    wsprintf(szInproc,"%s\\%s\\%s","clsid",szClsid,"InprocServer32");
    wsprintf(szProgId,"%s\\%s\\%s","clsid",szClsid,"ProgId");


    //
    //write the default value 
    //
    wsprintf(szBuff,"%s","Fast Addition Algorithm");
    wsprintf(szDescriptionVal,"%s\\%s","clsid",szClsid);

    HelperWriteKey (
                HKEY_CLASSES_ROOT,
                szDescriptionVal,
                NULL,//write to the "default" value
                REG_SZ,
                (void*)szBuff,
                lstrlen(szBuff)
                );


    //
    //write the "InprocServer32" key data
    //
    GetModuleFileName(
                g_hModule,
                szBuff,
                sizeof(szBuff));
    HelperWriteKey (
                HKEY_CLASSES_ROOT,
                szInproc,
                NULL,//write to the "default" value
                REG_SZ,
                (void*)szBuff,
                lstrlen(szBuff)
                );

    //
    //write the "ProgId" key data under HKCR\clsid\{---}\ProgId
    //
    lstrcpy(szBuff,AddObjProgId);
    HelperWriteKey (
                HKEY_CLASSES_ROOT,
                szProgId,
                NULL,
                REG_SZ,
                (void*)szBuff,
                lstrlen(szBuff)
                );


    //
    //write the "ProgId" data under HKCR\CodeGuru.FastAddition
    //
    wsprintf(szBuff,"%s","Fast Addition Algorithm");
    HelperWriteKey (
                HKEY_CLASSES_ROOT,
                AddObjProgId,
                NULL,
                REG_SZ,
                (void*)szBuff,
                lstrlen(szBuff)
                );


    wsprintf(szProgId,"%s\\%s",AddObjProgId,"CLSID");
    HelperWriteKey (
                HKEY_CLASSES_ROOT,
                szProgId,
                NULL,
                REG_SZ,
                (void*)szClsid,
                lstrlen(szClsid)
                );

    return 1;

    }

where CLSID_AddObject is defined like this:

// {92E7A9C2-F4CB-11d4-825D-00104B3646C0}
static const GUID CLSID_AddObject = 
{ 0x92e7a9c2, 0xf4cb, 0x11d4, { 0x82, 0x5d, 0x0, 0x10, 0x4b, 0x36, 0x46, 0xc0 } };

What I don't understand is: 1. Why do they use StringFromCLSID to get the GUID as string? They already have it and for some reason they convert it to IID? isn't the GUID we give it in the IDL file good enough?
2. Which GUIDs need to be registered? Ther library's GUID? the interfaces' GUIDs? the classes GUIDs? or all of them?

Was it helpful?

Solution

The reason why a GUID is converted to a string is that it's used to form some entries in the Windows Registry. You may see in your example code how the CLSID string gets incorporated into InprocServer32, ProgId, and CLSID entries.

You should register all the GUIDs in the Registry. You may have a look at this page in MSDN for details about COM Registry keys.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top