From c5cb6a3fabbc59568fcd0794473b94ea61127a85 Mon Sep 17 00:00:00 2001 From: Dmitry Timoshkov Date: Sun, 27 Mar 2016 16:28:33 +0800 Subject: oleaut32: Implement OleLoadPictureFile. (v2) --- dlls/oleaut32/olepicture.c | 36 ++++++++++++++++++++------- dlls/oleaut32/tests/olepicture.c | 53 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+), 9 deletions(-) diff --git a/dlls/oleaut32/olepicture.c b/dlls/oleaut32/olepicture.c index 765711d..29a091f 100644 --- a/dlls/oleaut32/olepicture.c +++ b/dlls/oleaut32/olepicture.c @@ -2315,15 +2315,6 @@ HRESULT WINAPI OleLoadPictureEx( LPSTREAM lpstream, LONG lSize, BOOL fRunmode, return hr; } -/*********************************************************************** - * OleLoadPictureFile (OLEAUT32.422) - */ -HRESULT WINAPI OleLoadPictureFile(VARIANT file, LPDISPATCH *picture) -{ - FIXME("(%s %p): stub\n", wine_dbgstr_variant(&file), picture); - return E_NOTIMPL; -} - static HRESULT create_stream(const WCHAR *filename, IStream **stream) { HANDLE hFile; @@ -2364,6 +2355,33 @@ static HRESULT create_stream(const WCHAR *filename, IStream **stream) } /*********************************************************************** + * OleLoadPictureFile (OLEAUT32.422) + */ +HRESULT WINAPI OleLoadPictureFile(VARIANT filename, IDispatch **picture) +{ + IStream *stream; + HRESULT hr; + + TRACE("(%s,%p)\n", wine_dbgstr_variant(&filename), picture); + + if (V_VT(&filename) != VT_BSTR) + return CTL_E_FILENOTFOUND; + + hr = create_stream(V_BSTR(&filename), &stream); + if (hr != S_OK) + { + if (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) + return CTL_E_FILENOTFOUND; + + return CTL_E_PATHFILEACCESSERROR; + } + + hr = OleLoadPicture(stream, 0, FALSE, &IID_IDispatch, (void **)picture); + IStream_Release(stream); + return hr; +} + +/*********************************************************************** * OleSavePictureFile (OLEAUT32.423) */ HRESULT WINAPI OleSavePictureFile(IDispatch *picture, BSTR filename) diff --git a/dlls/oleaut32/tests/olepicture.c b/dlls/oleaut32/tests/olepicture.c index 0903298..46cb185 100644 --- a/dlls/oleaut32/tests/olepicture.c +++ b/dlls/oleaut32/tests/olepicture.c @@ -850,6 +850,7 @@ static void test_OleLoadPicturePath(void) HANDLE file; DWORD size; WCHAR *ptr; + VARIANT var; const struct { @@ -916,6 +917,14 @@ static void test_OleLoadPicturePath(void) if (pic) IPicture_Release(pic); + VariantInit(&var); + V_VT(&var) = VT_BSTR; + V_BSTR(&var) = SysAllocString(temp_fileW + 8); + hres = OleLoadPictureFile(var, (IDispatch **)&pic); + ok(hres == S_OK, "OleLoadPictureFile error %#x\n", hres); + IPicture_Release(pic); + VariantClear(&var); + /* Try a DOS path with tacked on "file:". */ hres = OleLoadPicturePath(temp_fileW, NULL, 0, 0, &IID_IPicture, (void **)&pic); ok(hres == S_OK || @@ -924,6 +933,13 @@ static void test_OleLoadPicturePath(void) if (pic) IPicture_Release(pic); + VariantInit(&var); + V_VT(&var) = VT_BSTR; + V_BSTR(&var) = SysAllocString(temp_fileW); + hres = OleLoadPictureFile(var, (IDispatch **)&pic); + ok(hres == CTL_E_PATHFILEACCESSERROR, "wrong error %#x\n", hres); + VariantClear(&var); + DeleteFileA(temp_file); /* Try with a nonexistent file. */ @@ -933,12 +949,26 @@ static void test_OleLoadPicturePath(void) broken(hres == E_FAIL), /*Win2k */ "Expected OleLoadPicturePath to return INET_E_RESOURCE_NOT_FOUND, got 0x%08x\n", hres); + VariantInit(&var); + V_VT(&var) = VT_BSTR; + V_BSTR(&var) = SysAllocString(temp_fileW + 8); + hres = OleLoadPictureFile(var, (IDispatch **)&pic); + ok(hres == CTL_E_FILENOTFOUND, "wrong error %#x\n", hres); + VariantClear(&var); + hres = OleLoadPicturePath(temp_fileW, NULL, 0, 0, &IID_IPicture, (void **)&pic); ok(hres == INET_E_RESOURCE_NOT_FOUND || /* XP+ */ broken(hres == E_UNEXPECTED) || /* NT4 */ broken(hres == E_FAIL), /* Win2k */ "Expected OleLoadPicturePath to return INET_E_RESOURCE_NOT_FOUND, got 0x%08x\n", hres); + VariantInit(&var); + V_VT(&var) = VT_BSTR; + V_BSTR(&var) = SysAllocString(temp_fileW); + hres = OleLoadPictureFile(var, (IDispatch **)&pic); + ok(hres == CTL_E_PATHFILEACCESSERROR, "wrong error %#x\n", hres); + VariantClear(&var); + file = CreateFileA(temp_file, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); WriteFile(file, bmpimage, sizeof(bmpimage), &size, NULL); @@ -960,6 +990,13 @@ static void test_OleLoadPicturePath(void) if (pic) IPicture_Release(pic); + VariantInit(&var); + V_VT(&var) = VT_BSTR; + V_BSTR(&var) = SysAllocString(temp_fileW); + hres = OleLoadPictureFile(var, (IDispatch **)&pic); + ok(hres == CTL_E_PATHFILEACCESSERROR, "wrong error %#x\n", hres); + VariantClear(&var); + DeleteFileA(temp_file); /* Try with a nonexistent file. */ @@ -968,6 +1005,22 @@ static void test_OleLoadPicturePath(void) broken(hres == E_UNEXPECTED) || /* NT4 */ broken(hres == E_FAIL), /* Win2k */ "Expected OleLoadPicturePath to return INET_E_RESOURCE_NOT_FOUND, got 0x%08x\n", hres); + + VariantInit(&var); + V_VT(&var) = VT_BSTR; + V_BSTR(&var) = SysAllocString(temp_fileW); + hres = OleLoadPictureFile(var, (IDispatch **)&pic); + ok(hres == CTL_E_PATHFILEACCESSERROR, "wrong error %#x\n", hres); + VariantClear(&var); + + VariantInit(&var); + V_VT(&var) = VT_INT; + V_INT(&var) = 762; + hres = OleLoadPictureFile(var, (IDispatch **)&pic); + ok(hres == CTL_E_FILENOTFOUND, "wrong error %#x\n", hres); + +if (0) /* crashes under Windows */ + hres = OleLoadPictureFile(var, NULL); } static void test_himetric(void) -- 2.7.1