Commit 2514c014 authored by Rob Shearman's avatar Rob Shearman Committed by Alexandre Julliard

ole32: Move GetClassFile to moniker.c and move OleRun to ole2.c.

parent 8e014524
......@@ -2001,108 +2001,6 @@ HRESULT WINAPI CoResumeClassObjects(void)
}
/***********************************************************************
* GetClassFile (OLE32.@)
*
* Retrieves the class ID associated with the given filename.
*
* PARAMS
* filePathName [I] Filename to retrieve the class ID for.
* pclsid [O] Address that receives the class ID for the file.
*
* RETURNS
* Success: S_OK.
* Failure: Any HRESULT code.
*/
HRESULT WINAPI GetClassFile(LPCOLESTR filePathName,CLSID *pclsid)
{
IStorage *pstg=0;
HRESULT res;
int nbElm, length, i;
LONG sizeProgId;
LPOLESTR *pathDec=0,absFile=0,progId=0;
LPWSTR extension;
static const WCHAR bkslashW[] = {'\\',0};
static const WCHAR dotW[] = {'.',0};
TRACE("%s, %p\n", debugstr_w(filePathName), pclsid);
/* if the file contain a storage object the return the CLSID written by IStorage_SetClass method*/
if((StgIsStorageFile(filePathName))==S_OK){
res=StgOpenStorage(filePathName,NULL,STGM_READ | STGM_SHARE_DENY_WRITE,NULL,0,&pstg);
if (SUCCEEDED(res))
res=ReadClassStg(pstg,pclsid);
IStorage_Release(pstg);
return res;
}
/* if the file is not a storage object then attemps to match various bits in the file against a
pattern in the registry. this case is not frequently used ! so I present only the psodocode for
this case
for(i=0;i<nFileTypes;i++)
for(i=0;j<nPatternsForType;j++){
PATTERN pat;
HANDLE hFile;
pat=ReadPatternFromRegistry(i,j);
hFile=CreateFileW(filePathName,,,,,,hFile);
SetFilePosition(hFile,pat.offset);
ReadFile(hFile,buf,pat.size,&r,NULL);
if (memcmp(buf&pat.mask,pat.pattern.pat.size)==0){
*pclsid=ReadCLSIDFromRegistry(i);
return S_OK;
}
}
*/
/* if the above strategies fail then search for the extension key in the registry */
/* get the last element (absolute file) in the path name */
nbElm=FileMonikerImpl_DecomposePath(filePathName,&pathDec);
absFile=pathDec[nbElm-1];
/* failed if the path represente a directory and not an absolute file name*/
if (!lstrcmpW(absFile, bkslashW))
return MK_E_INVALIDEXTENSION;
/* get the extension of the file */
extension = NULL;
length=lstrlenW(absFile);
for(i = length-1; (i >= 0) && *(extension = &absFile[i]) != '.'; i--)
/* nothing */;
if (!extension || !lstrcmpW(extension, dotW))
return MK_E_INVALIDEXTENSION;
res=RegQueryValueW(HKEY_CLASSES_ROOT, extension, NULL, &sizeProgId);
/* get the progId associated to the extension */
progId = CoTaskMemAlloc(sizeProgId);
res = RegQueryValueW(HKEY_CLASSES_ROOT, extension, progId, &sizeProgId);
if (res==ERROR_SUCCESS)
/* return the clsid associated to the progId */
res= CLSIDFromProgID(progId,pclsid);
for(i=0; pathDec[i]!=NULL;i++)
CoTaskMemFree(pathDec[i]);
CoTaskMemFree(pathDec);
CoTaskMemFree(progId);
if (res==ERROR_SUCCESS)
return res;
return MK_E_INVALIDEXTENSION;
}
/***********************************************************************
* CoCreateInstance [OLE32.@]
*
* Creates an instance of the specified class.
......
......@@ -734,6 +734,66 @@ RunningObjectTableImpl_EnumRunning(IRunningObjectTable* iface,
return hr;
}
/* Virtual function table for the IRunningObjectTable class. */
static const IRunningObjectTableVtbl VT_RunningObjectTableImpl =
{
RunningObjectTableImpl_QueryInterface,
RunningObjectTableImpl_AddRef,
RunningObjectTableImpl_Release,
RunningObjectTableImpl_Register,
RunningObjectTableImpl_Revoke,
RunningObjectTableImpl_IsRunning,
RunningObjectTableImpl_GetObject,
RunningObjectTableImpl_NoteChangeTime,
RunningObjectTableImpl_GetTimeOfLastChange,
RunningObjectTableImpl_EnumRunning
};
/***********************************************************************
* RunningObjectTable_Initialize
*/
HRESULT WINAPI RunningObjectTableImpl_Initialize(void)
{
TRACE("\n");
/* create the unique instance of the RunningObjectTableImpl structure */
runningObjectTableInstance = HeapAlloc(GetProcessHeap(), 0, sizeof(RunningObjectTableImpl));
if (!runningObjectTableInstance)
return E_OUTOFMEMORY;
/* initialize the virtual table function */
runningObjectTableInstance->lpVtbl = &VT_RunningObjectTableImpl;
/* the initial reference is set to "1" ! because if set to "0" it will be not practis when */
/* the ROT referred many times not in the same time (all the objects in the ROT will */
/* be removed every time the ROT is removed ) */
runningObjectTableInstance->ref = 1;
list_init(&runningObjectTableInstance->rot);
InitializeCriticalSection(&runningObjectTableInstance->lock);
DEBUG_SET_CRITSEC_NAME(&runningObjectTableInstance->lock, "RunningObjectTableImpl.lock");
return S_OK;
}
/***********************************************************************
* RunningObjectTable_UnInitialize
*/
HRESULT WINAPI RunningObjectTableImpl_UnInitialize(void)
{
TRACE("\n");
if (runningObjectTableInstance==NULL)
return E_POINTER;
RunningObjectTableImpl_Release((IRunningObjectTable*)runningObjectTableInstance);
RunningObjectTableImpl_Destroy();
return S_OK;
}
/***********************************************************************
* GetRunningObjectTable (OLE32.@)
*
......@@ -767,105 +827,119 @@ GetRunningObjectTable(DWORD reserved, LPRUNNINGOBJECTTABLE *pprot)
}
/******************************************************************************
* OleRun [OLE32.@]
* MkParseDisplayName [OLE32.@]
*/
HRESULT WINAPI MkParseDisplayName(LPBC pbc, LPCOLESTR szUserName,
LPDWORD pchEaten, LPMONIKER *ppmk)
{
FIXME("(%p, %s, %p, %p): stub.\n", pbc, debugstr_w(szUserName), pchEaten, *ppmk);
if (!(IsValidInterface((LPUNKNOWN) pbc)))
return E_INVALIDARG;
return MK_E_SYNTAX;
}
/***********************************************************************
* GetClassFile (OLE32.@)
*
* Set the OLE object to the running state.
* Retrieves the class ID associated with the given filename.
*
* PARAMS
* pUnknown [I] OLE object to run.
* filePathName [I] Filename to retrieve the class ID for.
* pclsid [O] Address that receives the class ID for the file.
*
* RETURNS
* Success: S_OK.
* Failure: Any HRESULT code.
*/
HRESULT WINAPI OleRun(LPUNKNOWN pUnknown)
HRESULT WINAPI GetClassFile(LPCOLESTR filePathName,CLSID *pclsid)
{
IRunnableObject *runable;
HRESULT hres;
IStorage *pstg=0;
HRESULT res;
int nbElm, length, i;
LONG sizeProgId;
LPOLESTR *pathDec=0,absFile=0,progId=0;
LPWSTR extension;
static const WCHAR bkslashW[] = {'\\',0};
static const WCHAR dotW[] = {'.',0};
TRACE("(%p)\n", pUnknown);
TRACE("%s, %p\n", debugstr_w(filePathName), pclsid);
hres = IUnknown_QueryInterface(pUnknown, &IID_IRunnableObject, (void**)&runable);
if (FAILED(hres))
return S_OK; /* Appears to return no error. */
/* if the file contain a storage object the return the CLSID written by IStorage_SetClass method*/
if((StgIsStorageFile(filePathName))==S_OK){
hres = IRunnableObject_Run(runable, NULL);
IRunnableObject_Release(runable);
return hres;
}
res=StgOpenStorage(filePathName,NULL,STGM_READ | STGM_SHARE_DENY_WRITE,NULL,0,&pstg);
/******************************************************************************
* MkParseDisplayName [OLE32.@]
*/
HRESULT WINAPI MkParseDisplayName(LPBC pbc, LPCOLESTR szUserName,
LPDWORD pchEaten, LPMONIKER *ppmk)
{
FIXME("(%p, %s, %p, %p): stub.\n", pbc, debugstr_w(szUserName), pchEaten, *ppmk);
if (SUCCEEDED(res))
res=ReadClassStg(pstg,pclsid);
if (!(IsValidInterface((LPUNKNOWN) pbc)))
return E_INVALIDARG;
IStorage_Release(pstg);
return MK_E_SYNTAX;
}
return res;
}
/* if the file is not a storage object then attemps to match various bits in the file against a
pattern in the registry. this case is not frequently used ! so I present only the psodocode for
this case
/* Virtual function table for the IRunningObjectTable class. */
static const IRunningObjectTableVtbl VT_RunningObjectTableImpl =
{
RunningObjectTableImpl_QueryInterface,
RunningObjectTableImpl_AddRef,
RunningObjectTableImpl_Release,
RunningObjectTableImpl_Register,
RunningObjectTableImpl_Revoke,
RunningObjectTableImpl_IsRunning,
RunningObjectTableImpl_GetObject,
RunningObjectTableImpl_NoteChangeTime,
RunningObjectTableImpl_GetTimeOfLastChange,
RunningObjectTableImpl_EnumRunning
};
for(i=0;i<nFileTypes;i++)
/***********************************************************************
* RunningObjectTable_Initialize
for(i=0;j<nPatternsForType;j++){
PATTERN pat;
HANDLE hFile;
pat=ReadPatternFromRegistry(i,j);
hFile=CreateFileW(filePathName,,,,,,hFile);
SetFilePosition(hFile,pat.offset);
ReadFile(hFile,buf,pat.size,&r,NULL);
if (memcmp(buf&pat.mask,pat.pattern.pat.size)==0){
*pclsid=ReadCLSIDFromRegistry(i);
return S_OK;
}
}
*/
HRESULT WINAPI RunningObjectTableImpl_Initialize(void)
{
TRACE("\n");
/* create the unique instance of the RunningObjectTableImpl structure */
runningObjectTableInstance = HeapAlloc(GetProcessHeap(), 0, sizeof(RunningObjectTableImpl));
/* if the above strategies fail then search for the extension key in the registry */
if (!runningObjectTableInstance)
return E_OUTOFMEMORY;
/* get the last element (absolute file) in the path name */
nbElm=FileMonikerImpl_DecomposePath(filePathName,&pathDec);
absFile=pathDec[nbElm-1];
/* initialize the virtual table function */
runningObjectTableInstance->lpVtbl = &VT_RunningObjectTableImpl;
/* failed if the path represente a directory and not an absolute file name*/
if (!lstrcmpW(absFile, bkslashW))
return MK_E_INVALIDEXTENSION;
/* the initial reference is set to "1" ! because if set to "0" it will be not practis when */
/* the ROT referred many times not in the same time (all the objects in the ROT will */
/* be removed every time the ROT is removed ) */
runningObjectTableInstance->ref = 1;
/* get the extension of the file */
extension = NULL;
length=lstrlenW(absFile);
for(i = length-1; (i >= 0) && *(extension = &absFile[i]) != '.'; i--)
/* nothing */;
list_init(&runningObjectTableInstance->rot);
InitializeCriticalSection(&runningObjectTableInstance->lock);
DEBUG_SET_CRITSEC_NAME(&runningObjectTableInstance->lock, "RunningObjectTableImpl.lock");
if (!extension || !lstrcmpW(extension, dotW))
return MK_E_INVALIDEXTENSION;
return S_OK;
}
res=RegQueryValueW(HKEY_CLASSES_ROOT, extension, NULL, &sizeProgId);
/***********************************************************************
* RunningObjectTable_UnInitialize
*/
HRESULT WINAPI RunningObjectTableImpl_UnInitialize(void)
{
TRACE("\n");
/* get the progId associated to the extension */
progId = CoTaskMemAlloc(sizeProgId);
res = RegQueryValueW(HKEY_CLASSES_ROOT, extension, progId, &sizeProgId);
if (runningObjectTableInstance==NULL)
return E_POINTER;
if (res==ERROR_SUCCESS)
/* return the clsid associated to the progId */
res= CLSIDFromProgID(progId,pclsid);
RunningObjectTableImpl_Release((IRunningObjectTable*)runningObjectTableInstance);
for(i=0; pathDec[i]!=NULL;i++)
CoTaskMemFree(pathDec[i]);
CoTaskMemFree(pathDec);
RunningObjectTableImpl_Destroy();
CoTaskMemFree(progId);
return S_OK;
if (res==ERROR_SUCCESS)
return res;
return MK_E_INVALIDEXTENSION;
}
/***********************************************************************
......
......@@ -934,6 +934,34 @@ HRESULT WINAPI OleSetContainedObject(
}
/******************************************************************************
* OleRun [OLE32.@]
*
* Set the OLE object to the running state.
*
* PARAMS
* pUnknown [I] OLE object to run.
*
* RETURNS
* Success: S_OK.
* Failure: Any HRESULT code.
*/
HRESULT WINAPI OleRun(LPUNKNOWN pUnknown)
{
IRunnableObject *runable;
HRESULT hres;
TRACE("(%p)\n", pUnknown);
hres = IUnknown_QueryInterface(pUnknown, &IID_IRunnableObject, (void**)&runable);
if (FAILED(hres))
return S_OK; /* Appears to return no error. */
hres = IRunnableObject_Run(runable, NULL);
IRunnableObject_Release(runable);
return hres;
}
/******************************************************************************
* OleLoad [OLE32.@]
*/
HRESULT WINAPI OleLoad(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment