Why using WIC in my 32 bit application fails in Windows 7 32 bit?

橙三吉。 提交于 2019-12-07 13:41:50

问题


I have Win32 C++ sample application that uses Windows Image Component in Visual Studio Pro 2012 Update 2. I built this app for X86 and tested in Windows 7 X64 SP1 and Windows 7 X86 SP1. It works fine with the first one and it fails on the later with "class not registered".

If I build the same code with VS2008 it works fine.

The WIC instance is created in the sample app as follows:

#include "wincodec.h"
...
case WM_CREATE:
{
IWICImagingFactory *m_pIWICFactory;  
HRESULT hr = S_OK;

CoInitialize(NULL);
// create WIC factory (m_pIWICFactory)
hr = CoCreateInstance(
    &CLSID_WICImagingFactory,
    NULL,
    CLSCTX_INPROC_SERVER,
    &IID_IWICImagingFactory, 
    &m_pIWICFactory);
if (!SUCCEEDED(hr))
    MessageBox(NULL, 
        L"CoCreateInstance(..IID_IWICImagingFactory..) failed!", 
        L"", MB_OK);
else
    MessageBox(NULL, 
        L"CoCreateInstance(..IID_IWICImagingFactory..) succeeded!", 
        L"", MB_OK);

CoUninitialize();
}
break;
...

What could I be doing wrong?


回答1:


There is a breaking change in VS2012 because it targets Windows 8 by default.

The solution is to specify CLSID_WICImagingFactory1 instaed of CLSID_WICImagingFactory because the latter resolves to CLSID_WICImagingFactory2, which does not exist in Windows 7.

So try this

hr = CoCreateInstance(&CLSID_WICImagingFactory1, NULL, CLSCTX_INPROC_SERVER,
         &IID_IWICImagingFactory, &m_pIWICFactory);


来源:https://stackoverflow.com/questions/16697112/why-using-wic-in-my-32-bit-application-fails-in-windows-7-32-bit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!