您的位置:首页 > 编程语言 > Qt开发

qt+osg+vs2008中(msvcr90.dll) 处最可能的异常: 0xC0000005的问题解决

2009-11-06 23:15 302 查看
用此法得到了解决。

3. 另一个运行时异常, Debug时出现:
“Unhandled exception at 0×6c1f4774 (msvcr90.dll) in TestMagick.exe: 0xC0000005: Access violation reading location 0xcccccccc.”

同样在官方论坛上找到答案:是Project属性配置引起的, Project Properties->Configuration Properties->C/C++->Code Generation->Runtime Library, 把Multi-threaded Debug DLL (/MDd)改为Multi-threaded DLL (/MD), 而/MDd是Debug的默认选项. 不过文中提到的有关”_DEBUG”改为”NDEBUG”倒不必.

[转]ImageMagick中文路径名等问题解决

五月 21st, 2009
在C++中使用ImageMagick(简称Magick)处理一些图片, 碰到几个问题并尝试找到了解决方案.

Magick官方网站下载的ImageMagick-6.5.2-4-Q16-windows-dll.exe, 安装时选上C++开发包. 开发用的IDE是Visual Studio 2008.

1. Magick对中文的路径名支持不是很好, 比如

1
2

Image img;
img.read("e://头像 小头//小王.jpg");  // 读取失败

这种中文路径在OpenCV中是没问题的. 不过Magick并非不支持中文路径名, 只是需要先对中文路径进行utf-8编码. 如下面的转换代码, 在windows下通过MultiByteToWideChar和MultiByteToWideChar实现, 需要包含头文件wtypes.h, 细节可查看MSDN. 在linux下据说可以用iconv实现.

1
23
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

// use utf8 to encode the string and store as char*. Need #include <wtypes.h>.
// Not support linux, ps. iconv can do the same thing in linux.
// src -- a string to be converted, may contains characters like Chinese.
// return -- a point to a string which allocated in heap, it should be delete[].
char* acp2utf8(const char* src)
{
int len = strlen(src);
int n = MultiByteToWideChar(CP_ACP, 0, src, -1, NULL, 0);
char* res;
if (len + 1 == n)
{
// all ascii characters, which the same as utf8 encoding string.
res = new char[n];
strncpy(res, src, n);
}
else
{
WCHAR* ws = new WCHAR[n];
MultiByteToWideChar(CP_ACP, 0, src, -1, ws, n-1);
ws[n-1] = 0;

n = WideCharToMultiByte(CP_UTF8, 0, ws, -1, NULL, 0, NULL, NULL);
res = new char[n];
WideCharToMultiByte(CP_UTF8, 0, ws, -1, res, n-1, NULL, NULL);
res[n-1] = 0;

delete[] ws;
}

return res;
}

这样进行调用时, 只要:

1
23
4

char* fn = acp2utf8("e://头像 小头//小王.jpg");
Image img;
img.read(fn);
delete[] fn; // 别忘释放内存

2. 编译通过, 执行时碰到error(可在Debug模式下看到, Release下可能就直接退出了):
“Application Error
The application failed to initialize properly (0xc00000fd). Click on OK to terminate the application.”

很莫名其妙, 正常安装应该不会碰到. 重装系统后, 直接拿上次安装的dll来用就会出错这个错误. Google到答案: 因为它依赖注册表!! 重新安装一下就好了.
“The binary distribution of ImageMagick for Windows requires an installer to properly set entries in the Windows registry. What you want is an “uninstalled” version of ImageMagick. You will need to build ImageMagick from source which by default permits you to gather the binaries and configuration files into one folder and redistribute them free of dependencies on the Windows registry.”

3. 另一个运行时异常, Debug时出现:
“Unhandled exception at 0×6c1f4774 (msvcr90.dll) in TestMagick.exe: 0xC0000005: Access violation reading location 0xcccccccc.”

同样在官方论坛上找到答案:是Project属性配置引起的, Project Properties->Configuration Properties->C/C++->Code Generation->Runtime Library, 把Multi-threaded Debug DLL (/MDd)改为Multi-threaded DLL (/MD), 而/MDd是Debug的默认选项. 不过文中提到的有关”_DEBUG”改为”NDEBUG”倒不必.

“Well, I think I have it…… Turns out I didn’t quite have all the settings the same. But after a series of experiments and keeping track of all changes/differences between Debug and Release I think I’ve got it nailed down. In the “Project Properties” page, under “Configuration Properties/C++/Code Generation” make sure the “Runtime Library” is set to “Multi-Threaded DLL (/MD)” and not to “Multi-Threaded Debug DLL (/MDd)” which is the default for the Debug setup. Then under “Configuration Properties/C++/Preprocessor” you have to change the “Preprocessor Definition” that is set to “_DEBUG” to “NDEBUG”. I assume that this flag is used in the header files for the Magick++.h files somewhere. When I change these two parameters then everything works in the debug build environment.”

至于原因, 查了下MSDN, 找到这么一句话, “All modules passed to a given invocation of the linker must have been compiled with the same run-time library compiler option (/MD, /MT, /LD). “, 可能可以解释.

原文链接:http://ricoss.com/2009/05/imagemagick-tips.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐