出现这个问题,是由于libjpeg库的编译有问题,不要自已新建库工程一个个加jpeg-9c.zip里的文件,要按官方方法编译生成库,网上也有很多关于正确编库的说明,主要命令是
nmake nodebug=1 -f makefile.vc libjpeg.lib
记住nodebug版性能要好很多。另外,libjpeg读文件出异常就退出的问题参见:
人,技术,生活。
出现这个问题,是由于libjpeg库的编译有问题,不要自已新建库工程一个个加jpeg-9c.zip里的文件,要按官方方法编译生成库,网上也有很多关于正确编库的说明,主要命令是
nmake nodebug=1 -f makefile.vc libjpeg.lib
记住nodebug版性能要好很多。另外,libjpeg读文件出异常就退出的问题参见:
编译jpeg-9c后得到libjpeg.lib,按照网上的例程,读jpg文件时,只要jpg文件有错误,libjpeg库的函数内部就直接调系统函数exit退出了,这在整合libjpeg库到大型程序里时是绝对不能允许的。仔细查看库里的libjpeg.txt,才知道原来libjpeg能自定义错误处理,例程在example.c文件里的read_JPEG_file。
以下是我整理好的集成接口:
ReadJpg.h
#pragma once HBITMAP readJpegAsBitmap(const char *fileName); |
ShellExecuteEx使用不当会造成系统运行越来越慢,比如,如果指定了SEE_MASK_NOCLOSEPROCESS隐码,而未关闭返回的进程句柄,就是不对的,这样反复调ShellExecuteEx的后果是系统越来越慢。
正确做法是调用系统函数CloseHandle关闭返回的进程句柄。
很有意思,我发现vs2013 mfc对话框中只要焦点在ip输入控件或编辑框控件上时,调用该对话框实例的DestroyWindow()函数,就会很有可能抛如下之类的异常:
First-chance exception at 0x6EC815AC (comctl32.dll) in MyApp.exe: 0xC0000005: Access violation reading location 0x08824FC0.
现在临时的解决办法是调用对话框实例的DestroyWindow之前,找一个对话框上的非输入控件对其调用SetFocus()。
原因是mso.dll库中的定义没导入,对于装的是Office 2013的环境,正确写法是:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | #import "C:\\Program Files (x86)\\Common Files\\microsoft shared\\OFFICE15\\MSO.DLL" rename("RGB", "MSRGB") using namespace Office; #import "C:\\Program Files (x86)\\Common Files\\Microsoft Shared\\VBA\\VBA6\\VBE6EXT.OLB" raw_interfaces_only, \ rename("Reference", "ignorethis"), rename("VBE", "JOEVBE") using namespace VBIDE; #import "C:\\Program Files (x86)\\Microsoft Office\\Office15\\EXCEL.EXE" exclude("IFont", "IPicture") \ rename("RGB", "ignorethis"), rename("DialogBox", "ignorethis"), rename("VBE", "JOEVBE"), \ rename("ReplaceText", "JOEReplaceText"), rename("CopyFile","JOECopyFile"), \ rename("FindText", "JOEFindText"), rename("NoPrompt", "JOENoPrompt") using namespace Excel; #include "CApplication.h" #include "CWorkbooks.h" #include "CWorkbook.h" #include "CWorksheets.h" #include "CWorksheet.h" #include "CRange.h" #include "CFont0.h" //下面再写导出Excel文件的逻辑。 |
同时还要把这包含的Type Lib几个头文件的开头的import语句都删掉。
还要把CRange.h里的DialogBox函数注释掉。
就可以了。
还有,导出Excel文件用这种COM进程间通讯的方式最大缺点是慢,当导出条数很大时尤为明显,最好的方法是写一个C#子程序调npoi库。现在都是win7以上了,做成安装包时不需要要用户先安装.net framework之类的库。
refer to: http://blog.sina.com.cn/s/blog_7c5bff15010117cb.html
这个问题很无语,说一种原因,在用cmake写CMakeLists.txt编译live555时,
1 | project(Project01 CXX C) |
看见没?project关键字后少写了一个C,就不会编译纯C的代码。
原因是在ON_WM_PAINT对应的OnPaint函数里没有调过:
1 | CPaintDC dc(this); |
比如以下语句:
1 2 3 4 | CFont font_; font_.CreatePointFont(16 * 10, _T("微软雅黑")); ... SelectObject(hdc, &font_); |
编译后运行,在hdc上写的字根本没改变字体。很郁闷。
最后发现,要这样写:
1 | SelectObject(hdc, font_.m_hObject); |
或者这样写:
1 | SelectObject(hdc, font_); |
jpeg文件的标准格式是文件内容的前两字节是0xFF和0xD8,而有的jpg后缀的文件内容前两个字节有可能为0x42和0x4D之类。
所以在用JpegLib库如jpegsr9c.zip读取jpg文件时,可能在jpeg_read_header处报错,或者程序退出,因为源码中遇到错误时就会调系统函数exit(1)。
因此,在调用Jpeg库之前,一定要检查jpg文件的头两个字节是否标准。
编译期算结果C98示例:
1 2 3 4 5 6 7 | template <int n> struct fact98 { static const int value = n * fact98<n - 1>::value; }; template <> struct fact98<0> { static const int value = 1; }; std::cout << fact98<5>::value << std::endl; |
或C11的示例:
1 2 3 | constexpr int fact11(int n) { return n <= 1 ? 1 : (n * fact11(n - 1)); } |
C11中不能使用变量和循环,C14中可以:
1 2 3 4 5 | constexpr int fact14(int n) { int s = 1; for (int i = 1; i <= n; i++) { s = s * i; } return s; } |
编译期检查1:
1 2 3 4 5 6 7 | static_assert(sizeof(void *) == 8, "expected 64-bit platform"); template<typename T, int Row, int Column> struct Matrix { static_assert(Row >= 0, "Row number must be positive."); static_assert(Column >= 0, "Column number must be positive."); }; |
编译期检查2:
1 2 3 4 5 6 7 8 9 | struct A { void foo(){} int member; }; template<typename Function> std::enable_if_t<!std::is_member_function_pointer_v<Function>> foo(Function&& f) { } foo([] {}); //ok foo(&A::foo); //compile error: no matching function for call to 'foo(void (A::*)())' |
编译期检查3:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | template< class, class = void > struct has_foo : std::false_type {}; template< class T > struct has_foo< T, std::void_t<decltype(std::declval<T>().foo())> > : std::true_type {}; template< class, class = void > struct has_member : std::false_type {}; template< class T > struct has_member< T, std::void_t<decltype(std::declval<T>().member)> > : std::true_type {}; struct A { void foo(){} int member; }; static_assert(has_foo< A >::value); static_assert(has_member< A >::value); |