Implementing the DllRegisterServer Method

I am trying to implement the COM method of DllRegisterServer.
So I read this lesson:
http://www.codeguru.com/cpp/com-tech/activex/tutorials/article.php/c5567/Step-by-Step-COM-Tutorial.htm

and I followed the steps to the DllRegisterServer part.
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 as follows:

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

I do not understand: 1. Why do they use StringFromCLSID to get the GUID as a string? Do they already have this, and for some reason do they convert it to IID? is this not the GUID that we give in the IDL file well enough?
2. What GUIDs should be registered? The GUID of the library? GUID of interfaces? GUID classes? or all of them?

+4
source share
1 answer

The reason the GUID is converted to a string is because it was used to form some entries in the Windows registry. You can see in your example code how the CLSID string is included in the InprocServer32 , ProgId and CLSID ProgId .

You must register all GUIDs in the registry. You can see this page on MSDN for more information on COM registry keys.

+1
source

Source: https://habr.com/ru/post/1442944/


All Articles