Ignore:
Timestamp:
Sep 24, 1999, 11:49:45 PM (26 years ago)
Author:
davidr
Message:

Ported remaining files pertaining to OLE32 from WINE

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/ole32/ole32.cpp

    r872 r1033  
    1 /* $Id: ole32.cpp,v 1.10 1999-09-08 11:29:28 davidr Exp $ */
     1/* $Id: ole32.cpp,v 1.11 1999-09-24 21:49:43 davidr Exp $ */
    22/*
    33 *
     
    2222
    2323#include "oString.h"
    24 #include "moniker.h"    // RunningObjectTableImpl_***
     24#include "moniker.h"            // RunningObjectTableImpl_***
     25#include "filemoniker.h"        // FileMonikerImpl_***
    2526
    2627// ======================================================================
     
    583584}
    584585
     586// ----------------------------------------------------------------------
     587// GetClassFile
     588// ----------------------------------------------------------------------
     589// This function supplies the CLSID associated with the given filename.
     590HRESULT WIN32API GetClassFile(LPOLESTR filePathName, CLSID *pclsid)
     591{
     592    IStorage *  pstg = 0;
     593    HRESULT     res;
     594    int         nbElm = 0;
     595    int         length = 0;
     596    int         i = 0;
     597    LONG        sizeProgId = 20;
     598    LPOLESTR *  pathDec = 0;
     599    LPOLESTR    absFile = 0;
     600    LPOLESTR    progId = 0;
     601    WCHAR       extention[100] = {0};
     602
     603    dprintf(("OLE32: GetClassFile"));
     604
     605    // if the file contain a storage object the return the CLSID
     606    // writen by IStorage_SetClass method
     607
     608    if((StgIsStorageFile(filePathName)) == S_OK)
     609    {
     610        res = StgOpenStorage(filePathName, NULL, STGM_READ | STGM_SHARE_DENY_WRITE, NULL, 0, &pstg);
     611
     612        if (SUCCEEDED(res))
     613            res = ReadClassStg(pstg, pclsid);
     614
     615        IStorage_Release(pstg);
     616
     617        return res;
     618    }
     619
     620    /* if the obove strategies fail then search for the extension key in the registry */
     621
     622    /* get the last element (absolute file) in the path name */
     623    nbElm = FileMonikerImpl_DecomposePath(filePathName, &pathDec);
     624    absFile = pathDec[nbElm-1];
     625
     626    /* failed if the path represente a directory and not an absolute file name*/
     627    if (lstrcmpW(absFile, (LPOLESTR)"\\"))
     628        return MK_E_INVALIDEXTENSION;
     629
     630    /* get the extension of the file */
     631    length = lstrlenW(absFile);
     632    for(i = length-1; ( (i >= 0) && (extention[i] = absFile[i]) ); i--);
     633       
     634    /* get the progId associated to the extension */
     635    progId = (WCHAR *)CoTaskMemAlloc(sizeProgId);
     636
     637    res = RegQueryValueW(HKEY_CLASSES_ROOT, extention, progId, &sizeProgId);
     638
     639    if (res == ERROR_MORE_DATA)
     640    {
     641        CoTaskMemRealloc(progId,sizeProgId);
     642
     643        res = RegQueryValueW(HKEY_CLASSES_ROOT, extention, progId, &sizeProgId);
     644    }
     645    if (res == ERROR_SUCCESS)
     646        /* return the clsid associated to the progId */
     647        res =  CLSIDFromProgID(progId, pclsid);
     648
     649    for(i = 0; pathDec[i] != NULL; i++)
     650        CoTaskMemFree(pathDec[i]);
     651
     652    CoTaskMemFree(pathDec);
     653
     654    CoTaskMemFree(progId);
     655
     656    if (res == ERROR_SUCCESS)
     657        return res;
     658
     659    return MK_E_INVALIDEXTENSION;
     660}
    585661// ======================================================================
    586662// Private functions.
Note: See TracChangeset for help on using the changeset viewer.