Results 1 to 7 of 7

Thread: Clsid

Threaded View

  1. #7
    Lively Member
    Join Date
    Nov 2005
    Posts
    68

    Re: Clsid

    A dll, ocx,... may have more than one COM object and so more than one CLSID. If you want to find which CLSIDs a library registers you must search the registry. The following code searches for CLSIDs registered by comctl32.ocx.

    Code:
    #include <windows.h>
    #include <string.h>
    
    void SearchRegistry()
    {
    	LONG lr = ERROR_SUCCESS;
    	HKEY hKey = NULL;
    	HKEY hEnumKey = NULL;
    	HKEY hIpsKey = NULL;
    	DWORD dwIndex = 0;
    	char szClsidName[0xff];
    	char szDLLName[0xff];
    	char szProgID[0xff];
    	char * szSearchStr = "C:\\WINDOWS\\SYSTEM32\\COMCTL32.OCX";
    	DWORD dwCount = 0xff;
    	LONG lcnt = 0;
    
    	lr = RegOpenKeyExA(HKEY_CLASSES_ROOT, "CLSID", 0, KEY_READ, &hKey);
    	
    	while (lr = RegEnumKeyA(hKey, dwIndex++, szClsidName, dwCount) == ERROR_SUCCESS)
    	{
    		lr = RegOpenKeyExA(hKey, szClsidName, 0, KEY_READ, &hEnumKey);
    		lr = RegOpenKeyExA(hEnumKey, "InprocServer32", 0, KEY_READ, &hIpsKey);
    		lr = RegQueryValueA(hIpsKey, NULL, szDLLName, &lcnt);
    		if (lr == ERROR_SUCCESS)
    		{
    			_strupr(szDLLName);
    			if (strcmp(szSearchStr, szDLLName) == 0)
    			{
    				printf("CLSID: %s\n", szClsidName);
    				RegCloseKey(hIpsKey);
    				lr = RegOpenKeyExA(hEnumKey, "ProgID", 0, KEY_READ, &hIpsKey);
    				lr = RegQueryValueA(hIpsKey, NULL, szProgID, &lcnt);
    				if (lr == ERROR_SUCCESS)
    					printf("ProgID: %s\n\n", szProgID);
    				else
    					printf("ProgID: not found\n\n");
    			}
    		}
    		RegCloseKey(hIpsKey);
    		RegCloseKey(hEnumKey);
    	}
    	RegCloseKey(hKey);
    }
    
    int main()
    {
    	SearchRegistry();
    	return 0;
    }
    Note that with the above we may not find all the entries for comctl32.ocx since it may be defined with the alternatives "%SystemRoot%\Windows\System32\comctl32.ocx" or "comctl32.ocx" so it would be more appropriate to check the last 12 chars of the string.
    Last edited by bilm_ks; Feb 11th, 2006 at 03:24 PM.
    "bla, bla,... exists number M so for each n > M bla, bla..." Exists? Where is it? (Kronecker said...)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width