posts - 11,  comments - 0,  trackbacks - 0
  2010年11月25日

ontrols how the members of a structure are packed into memory and specifies the same packing for all structures in a module.

Copy

/Zp[1|2|4|8|16]


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 阅读(253) | 评论 (0)编辑 收藏
  2010年7月29日
[16.7] Do I need to check for NULL before delete p?

No!

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.

Wrong:

 if (p != NULL)
   delete p;

Right:

 delete p;
posted @ 2010-07-29 12:18 SearchDream 阅读(166) | 评论 (0)编辑 收藏
  2010年7月2日
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 阅读(256) | 评论 (0)编辑 收藏
  2010年4月30日
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
#include "SocMFC.h"

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:

  1. 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
  2. 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
  3. 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.
  4. 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!
  5. 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"
  6. 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.

  1. 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.
  2. 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.
  3. 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:

    libeay32MD.lib
    libeay32MDd.lib
    libeay32MT.lib
    libeay32MTd.lib
    ssleay32MD.lib
    ssleay32MDd.lib
    ssleay32MT.lib
    ssleay32MTd.lib

    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.

Happy coding!

posted @ 2010-04-30 17:03 SearchDream 阅读(867) | 评论 (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

  • compile!
  • 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 阅读(422) | 评论 (0)编辑 收藏
  2010年3月3日

For this exercise, we will use the mysqldump utility the same as if we were backing up the entire database.

Syntax:

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.

Example:

mysqldump -d -h localhost -u root -p2Uad7as9 database01 > dumpfile.sql

posted @ 2010-03-03 14:28 SearchDream 阅读(110) | 评论 (0)编辑 收藏
  2010年3月1日
void HexStringToBinary(char* szHex, vector<unsigned char> & vBinary)
{
    
const unsigned int size = sizeof(szHex) / sizeof(szHex[0]) / 2;

    vBinary.resize(size);

    
for (int i = 0; i < size; i++)
    {
        
if (sscanf(szHex + 2 * i, "%2X"&vBinary[i]) != 1
        {
            
break;
        }
    }
}
posted @ 2010-03-01 17:08 SearchDream 阅读(375) | 评论 (0)编辑 收藏
  2009年12月29日
代码如下:

1 printf("%02x %02x %02x %02x",
2       (unsigned char)pData[0], (unsigned char)pData[1],
3       (unsigned char)pData[2], (unsigned char)pData[3]);


posted @ 2009-12-29 11:09 SearchDream 阅读(176) | 评论 (0)编辑 收藏
  2009年12月28日
记录一点心得:Unicode的Version中需要注意,在传递DLL的路径时需要加两个字节的0x00作为结尾标志.
其他的可以参考下面两个文章:
http://www.codeproject.com/KB/threads/completeinject.aspx
http://www.codeproject.com/KB/threads/winspy.aspx

posted @ 2009-12-28 21:33 SearchDream 阅读(318) | 评论 (0)编辑 收藏
  2009年12月23日
我使用的是VS2005,使用WTL模板创建的工程, 开始一直不能在Release Version设置断点,
我已经在linker->Debugging->Generate Debug Info里选择了Yes (/Debug)。查了一下
其他option发现C/C++->General->Debug Information Format,选择Progam Database (/Zi)
就可以了,生成PDB也大20多M。

posted @ 2009-12-23 12:52 SearchDream 阅读(164) | 评论 (0)编辑 收藏
仅列出标题  下一页
<2024年11月>
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567

常用链接

留言簿

随笔档案

搜索

  •  

最新评论

阅读排行榜

评论排行榜