ontrols how the members of a structure are packed into memory and specifies the same packing for all structures in a module.
When you specify this option, each structure member after the first is stored on either the size of the member type or n-byte boundaries (where n is 1, 2, 4, 8, or 16), whichever is smaller.
The available values are described in the following table.
1 Packs structures on 1-byte boundaries. Same as /Zp.
2 Packs structures on 2-byte boundaries.
4 Packs structures on 4-byte boundaries.
8 Packs structures on 8-byte boundaries (default).
16 Packs structures on 16-byte boundaries.
You should not use this option unless you have specific alignment requirements.
posted @ 2010-11-25 13:32
SearchDream 阅读(91) | 评论 (0)
| 编辑 收藏
[16.7] Do I need to check for NULL before delete p?
The C++ language guarantees that delete p will do nothing if p is equal to
NULL. Since you might get the test backwards, and since most testing
methodologies force you to explicitly test every branch point, you should not
put in the redundant if test.
if (p != NULL)
posted @ 2010-07-29 12:18
SearchDream 阅读(56) | 评论 (0)
| 编辑 收藏
Seems if struct contain __int64 or unsigned __int64 the compiler will force to use 8 byte if you not use pack to give explicit value.
posted @ 2010-07-02 09:48
SearchDream 阅读(97) | 评论 (0)
| 编辑 收藏
Original link: http://naughter.spaces.live.com/Blog/cns!7692E6D72E26EAC!209.entry
Following on from my "Common problems compiling my code" blog entry, another popular email question I get is related to my SMTP class is problems related to getting OpenSSL support compiled into the class. Here's a snippet from the OpenSSLMfc.h header file which provides a simple encapsulation of a socket connection using OpenSSL:
#include <openssl\ssl.h> //If you get a compilation error about this missing header file, then you need to download OpenSSL from http://www.openssl.org and build a Win32 version and incorporate it into Visual C
#include <openssl\err.h> //If you get a compilation error about this missing header file, then you need to download OpenSSL from http://www.openssl.org and build a Win32 version and incorporate it into Visual C
As you can see it references the OpenSSL header files "ssl.h" and "err.h". You can download OpenSSL directly as the code comments mention above from http://www.openssl.org. As of 7th of July 2007, the latest version of OpenSSL is 0.9.8e. Once you have downloaded OpenSSL you should read and follow the build instructions in the file INSTALL.W32 included in the OpenSSL download. Basically the steps are:
- You will need to have Perl for Win32 installed. If you do not have it you can download ActiveState Perl fromhttp://www.activestate.com/ActivePerl
- Bring up a Visual Studio command prompt, navigate to the OpenSSL install directory (say c:\some\openssl) and run Configure as follows:
perl Configure VC-WIN32 --prefix=c:/some/openssl/dir
This assumes that you have setup perl to be in your search path
- Assuming you do not want to mess about with assembly language, type ms\do_ms from your command prompt. Examine the window for any errors.
- Then type nmake -f ms\ntdll.mak which will actually perform the compile and link of the OpenSSL code. This may take a while. When it finishes examine the out32dll directory which should contain the OpenSSL DLLs and executables. Note that by default this will only produce "release" mode binaries and you need to manually edit and rerun the make process if you want to create "debug" binaries. Also to avoid the "debug" binaries overwritting the already created "release" binaries, you need to edit the make file or backup the existing binary files. Basically this step is a bit of a mess to get right!
- Point your copy of VC to the appropriate Include and Lib directories. In our example this would be "c:\some\openssl\inc32" and "c:\some\openssl\out32dll" respectively. If you are using Visual Studio 2005, this would be using the menu item "Tools -> Options -> Projects and Solutions -> VC++ Directories -> "Include Files" & "Library Files"
- Update your project linker settings to link to the correct OpenSSL libraries. This will normally be ssleay32.lib libeay32.lib for release mode builds.
If all of the steps above prove to be too much work, then a company called Shining Light Productions have very kindly packaged up the end results of all this work into a nice and simple installation package for us Windows developers.
- You can download the Win32 OpenSSL Installation Project from http://www.slproweb.com/products/Win32OpenSSL.html. As of 7th of July 2007, you can download either OpenSSL v0.9.8e and v0.9.7m. Both of these are the most recent builds from each stream of OpenSSL. When you install the download on your machine, you end up with the static import libraries in a "Lib\VC\static" directory below the install directory, the DLL import libraries in a "Lib\VC" directory and the main include files in a "include" directory (again both below the install directory). The download a new developer to OpenSSL should select is the "Win32 OpenSSL v0.9.8e download" link.
- To complete the integration with VC, setup the Include and Lib directories as in Step 5 above. Assuming you installed the Win32 OpenSSL project into C:\dev\openssl-0.9.8e, you would add "c:\dev\openssl-0.9.8e\include" to the Include setting and "C:\dev\openssl-0.9.8e\lib" to the Lib setting in VC.
- You need to link to the correct import library depending on how you build your code. 8 different DLL import lib files are provided in the Lib\VC directory and a further 8 in the Lib\VC\Static directory. The 2 OpenSSL libraries namely libeay and ssleay each come in 4 varieties with the Win32 OpenSSL Project, resulting in 8 DLL import libraries and 8 static import libraries. These are:
Which ones you use depend on how you are building your client project and its use of the VC runtime. For more information seehttp://msdn2.microsoft.com/en-us/library/2kzt1wy3(VS.80).aspx. The differences basically correspond to whether you want to use the VC runtime DLL or statically embed the VC runtime in your application.
Hopefully this info will help you get up and running with OpenSSL and my SSL classes in your own code.
posted @ 2010-04-30 17:03
SearchDream 阅读(679) | 评论 (0)
| 编辑 收藏
Original link: http://news.thedigitalmachine.com/2007/03/28/set-up-sqlite-static-lib-and-a-c-wrapper-in-15-minutes/
sqlite is a sweet little answer to database storage for stand-alone applications. CppSQLite is the best C++ wrapper I found (NOTE: there are many). I didn’t find any quick instructions to get the C code statically linked into a Visual Studio 2005 C++ app, so here they are. At the end, I had all the code wrapped nicely into my application with a size increase of 132kb – and no dependencies! Whoop.
You can just grab the files here if you don’t care about the gory details. Read the included Readme.txt file for quick setup instructions. Everything you need is included, including v3.3.13 of the sqlite source and v3.1 of the CppSQLite files.
Now for the blow-by-blow setup of how to do the static library build yourself. It’s not brain surgery, but it’s good to know – for example, if you want to use a newer version of the source code (in case I get lazy and don’t update this).
- create a new Visual Studio 2005 Win32 console application
- during creation, under advanced options…
- change build target type to “static library”
- uncheck “precompiled header”
- add NO_TCL to preprocessor definitions
- Go here: Project->Properties->Configuration Properties->C/C++->Preprocessor->Preprocessor Definitions
- Add NO_TCL to the existing lists of all configurations, to bypass inclusion of TCL support
- change the runtime library (to match whatever project that will be linking to the sqlite library you build)
- Found here: Project->Properties->Configuration Properties->C/C++->Code Generation->Runtime Library
- download the preprocessed source code and add it to the project
- (optional) disable the more neurotic VS8 warnings (even though you can safely ignore them)…
- add _CRT_SECURE_NO_WARNINGS to preprocessor definitions:
- – Go here: Project->Properties->Configuration Properties->C/C++->Preprocessor->Preprocessor Definitions
- – Add _CRT_SECURE_NO_WARNINGS to the existing lists of all configurations
- disable the following warnings (Project->Properties->C/C++->Advanced->Disable Specific Warnings):
- – 4267;4244;4018;4311;4996;4312;4311
- include the resulting static library, along with the CppSQLite wrapper class, in your shiny new project
- read about CppSQLite and write some code!
posted @ 2010-04-30 16:39
SearchDream 阅读(265) | 评论 (0)
| 编辑 收藏
For this exercise, we will use the mysqldump utility the same as if we were backing up the entire database.
mysqldump -d -h localhost -u root -pmypassword databasename > dumpfile.sql
The only option that is different than creating an entire backup is the -d switch, which tells mysqldump not to output the data.
mysqldump -d -h localhost -u root -p2Uad7as9 database01 > dumpfile.sql
posted @ 2010-03-03 14:28
SearchDream 阅读(35) | 评论 (0)
| 编辑 收藏
void HexStringToBinary(char* szHex, vector<unsigned char> & vBinary)
const unsigned int size = sizeof(szHex) / sizeof(szHex) / 2;
for (int i = 0; i < size; i++)
if (sscanf(szHex + 2 * i, "%2X", &vBinary[i]) != 1)
posted @ 2010-03-01 17:08
SearchDream 阅读(68) | 评论 (0)
| 编辑 收藏
1 printf("%02x %02x %02x %02x",
2 (unsigned char)pData, (unsigned char)pData,
3 (unsigned char)pData, (unsigned char)pData);
posted @ 2009-12-29 11:09
SearchDream 阅读(116) | 评论 (0)
| 编辑 收藏
posted @ 2009-12-28 21:33
SearchDream 阅读(189) | 评论 (0)
| 编辑 收藏
我使用的是VS2005，使用WTL模板创建的工程, 开始一直不能在Release Version设置断点，
我已经在linker->Debugging->Generate Debug Info里选择了Yes (/Debug)。查了一下
其他option发现C/C++->General->Debug Information Format,选择Progam Database (/Zi)
posted @ 2009-12-23 12:52
SearchDream 阅读(55) | 评论 (0)
| 编辑 收藏