GetClassFile

Supplies the CLSID associated with the given filename.

WINOLEAPI GetClassFile(

LPCWSTR szFileName,

//Pointer to filename for which you are requesting a CLSID

CLSID * pclsid

//Pointer to location for returning the CLSID

);

Parameters

szFileName
[in] Points to the filename for which you are requesting the associated CLSID.
pclsid
[out] Points to the location where the associated CLSID is written on return.

Return Values

S_OK
Indicates the CLSID was successfully supplied.
MK_E_CANTOPENFILE
Indicates unable to open the specified filename.
MK_E_INVALIDEXTENSION
Indicates the specified extension in the registry is invalid.

Note This function can also return any file system errors.

Comments

When given a filename, the GetClassFile function finds the CLSID associated with that file. Examples of its use are in OleCreateFromFile, which is passed a file name and requires an associated CLSID, and in the OLE implementation of IMoniker::BindToObject, which, when a link to a file-based document is activated, calls GetClassFile to locate the object application that can open the file.

GetClassFile uses the following strategies to determine an appropriate CLSID:

  1. If the file contains a storage object, as determined by a call to the StgIsStorageFile function, GetClassFile returns the CLSID that was written with the IStorage::SetClass method.

  2. If the file is not a storage object, the GetClassFile function attempts to match various bits in the file against a pattern in the registry. A pattern in the registry can contain a series of entries of the form:
regdb key = offset, cb, mask, value 
 
HKEY_CLASSES_ROOT 
	FileType 
	  {12345678-0000-0001-C000-000000000095} 
	    0 = 0, 4, FFFFFFFF, ABCD1234 
	    1 = -4, 4, , FEFEFEFE 
 

See Also

WriteClassStg