为什么在我的32位应用程序中使用WIC在Windows 7 32位中失败? [英] Why using WIC in my 32 bit application fails in Windows 7 32 bit?
问题描述
我有使用 Windows Studio组件(在Visual Studio Pro 2012 Update 2中).我为X86构建了此应用,并在Windows 7 X64 SP1和Windows 7 X86 SP1中进行了测试.它在第一个上运行良好,而在后一个未注册类"上运行失败.
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".
如果我使用VS2008构建相同的代码,则可以正常工作.
If I build the same code with VS2008 it works fine.
在示例应用程序中创建WIC实例,如下所示:
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;
...
我做错了什么?
推荐答案
There is a breaking change in VS2012 because it targets Windows 8 by default.
解决方案是指定CLSID_WICImagingFactory
的CLSID_WICImagingFactory1
实例,因为后者解析为CLSID_WICImagingFactory2
,而Windows 7中不存在.
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.
所以试试这个
hr = CoCreateInstance(&CLSID_WICImagingFactory1, NULL, CLSCTX_INPROC_SERVER,
&IID_IWICImagingFactory, &m_pIWICFactory);
这篇关于为什么在我的32位应用程序中使用WIC在Windows 7 32位中失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!