Archive for the 'Programming Language' Category

BlowFish算法封装

前面一个帖子一样,只是为了使用方便,把别人已经写好的BlowFish加密算法封装了一下。

点击这里下载(VS2005)

VS2005打包问题终于搞定

参考:

http://msdn2.microsoft.com/en-us/library/ms235291(VS.80).aspx

Deploying Visual C++ library DLLs as private assemblies

In this scenario, the application is deployed by just copying a folder from the development computer to the target computer, and installing dependent assemblies as private side-by-side assemblies. To deploy Visual C++ libraries as private assemblies, perform the following steps:

Steps

  1. Create a folder structure on the development computer that matches the folder structure to be used on the target computer. For this example, create a \bin folder and copy myapplication.exe there. Then create a \bin\mylibrary folder and copy MyLibrary.dll there.
  2. On the development computer, from %PROGDIR%\Microsoft Visual Studio 8\VC\Redist\x86, copy Microsoft.VC80.CRT and Microsoft.VC80.MFC to \bin and to \bin\MyLibrary.

    NoteNote
    Visual C++ Express does not create %PROGDIR%\Microsoft Visual Studio 8\VC\Redist\ during installation on the development computer. To redistribute Visual C++ libraries with applications built with Visual C++ Express, please use Visual C++ Redistributable Packages (VCRedist_*.exe). See section “Deploying Visual C++ library DLLs as shared assemblies” above for more information.

    NoteNote
    For deploying 64-bit applications to 64-bit operating systems, use \vc\redist\amd64 or \vc\redist\ia64.
  3. Copy the \bin folder to the target computer. On a target computer with manifest-based binding support (Windows XP Home Edition, Windows XP Professional, Windows Server 2003, Windows Vista) no further preparation is necessary. On a computer without such support (Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows 2000), Microsoft.VC80.CRT and Microsoft.VC80.MFC must be on the path.

    NoteNote
    For debug applications, use debug DLLs from \vc\redist\debug_nonredist\. However, remote debugging may not work for an application that deploys debug versions of Visual C++ libraries as private assemblies. For more information, see Preparing a Test Machine To Run a Debug Executable.

    NoteNote
    If you want to do remote debugging on the target machine, you must copy over the debug DLLs or follow the procedure to install debug DLLs in Preparing a Test Machine To Run a Debug Executable.

再也不用VS2005的Setup Project了,麻烦,并且要求目标机器安装Windows Installer,搜遍了半个地球,最后才在上面的文章中找到问题所在,上面的写的很复杂,其实就是几句话:

1:Copy X:\Program Files\Microsoft Visual Studio 8\VC\redist\x86下目录Microsoft.VC80.CRT和目录Microsoft.VC80.MFC中的所有文件到你的程序的路径下

2:没有2,完了。

How to upload a file with HTTP POST?

How to upload a file, e.g. music, image file to a webserver? To do this, there are several ways available: FTP, SFTP, and so on, usually FTP is the common one, almost all file servers support FTP, but the user must have a valid account in server, this will cause a lot of security issues, also it is not friendly for average users. The most easy and popular way is uploading in web pages, this is straight-forward, even a monkey can do it, just press the ‘submit’ button. But that enforces you to get your files uploaded in web pages, you’ll feel tired if you have to upload dozens of files. So If we got a client which uploads files automatically for us, it will be a convenient tool.

This is an article that teaches you to make your tool for uploading files with http protocal step by step. I’ll write this program in C++.

The idea behind ths program is simple,  it simulates a browser, and submmit files to sever using HTTP post.

To be continued…

Read the rest of this entry »

AES加密算法的简单封装

by Charry

AES加密算法每次对16字节的数据进行加密,而且加密后的密文通常是非ASCII字符,不易于保存和传输, 为了使用方便,我写了个包装类,使得使用AES加密非常简单,并且加密后的密文以它的16进制的形式出现,不再有乱码。

接口为:

BOOL Encrypt(const CString &key, const CString &in, CString &out);
BOOL Decrypt(const CString &key, const CString &in, CString &out);

由于AES是每16字节加密一下,所以如果被加密的明文的长度不是16的整数倍,我们需要在明文的后面补齐,比如用字符“0”。为了记录最后补了多少个“0”,可以把这个数字保存在最终的密文的后面,形如:

“DA7C8E7BF333EE0C612A8E211B139D4D{[]}10″

数字10前面的{[]}是为了查找方便。这个外包类只是我为了自己使用方便而写,其核心部分来自CodeProject:http://www.codeproject.com/cpp/aes.asp ,我只是简化了接口,并添加了UNICODE支持等细节。

点击这里下载代码

Java中发送结构体

最近给个朋友做个网站的客户端,使用C/S模式,Client为VC6开发,Server为Java,通过Socket通信。由于Client这边为C++,所以,在接受Java发过来的数据包时,需要知道发来的包的长度,所以,就要引入变长包的机制。

方法是:首先Server发送一个包头,如下:

// packet head
typedef struct tagPacketHead{
long PacketID;
long PacketLen;
}PacketHead;

Read the rest of this entry »

MS Soap Toolkit In C++

下面的例子简要的说明一下如何使用MS Soap Toolkit访问Web Service

首先


#import “msxml3.dll”
#import “C:Program FilesCommon FilesMSSoapBinariesmssoap30.dll”
exclude(“IStream”, “ISequentialStream”, “_LARGE_INTEGER”,
“_ULARGE_INTEGER”, “tagSTATSTG”, “_FILETIME”)


Read the rest of this entry »

How to call TCL from c++

CString CTCL::EvalFile(const CString &file, const CString &flag)
{
Tcl_FindExecutable(file);
int ret = Tcl_EvalFile(m_pInterp, file);

char szResult[1024] = {0};
const char *pResult = Tcl_GetVar(m_pInterp, flag, 0);

if (pResult == NULL)
return “”;

strncpy(szResult, pResult, sizeof(szResult) – 1);
return (CString(szResult));
}

My Sniffer

最近写的一个Sniffer小程序,可以捕获当前用户上了哪些网。
(设置混杂模式部分参考网络文章,SocketInfo来自codeproject.com)

下载:http://www.mpfive.com/m/myapps/MySniffer.rar

使用方法:
1:拷贝下面的文件到你的工程下

HttpParser.cpp
SocketInfo.cpp
SocketInfo.h
define.h
SnifferManager.h
Sniffer.cpp
Sniffer.h
HttpParser.h
SnifferManager.cpp

2:在程序中 include SnifferManager.h
3:在你的程序中开启Sniffer的地方加入:

CSnifferManager *pSM = CSnifferManager::GetInstance();
pSM->StartSniffers();

4:程序关闭的地方加入:

this->ShowWindow(SW_HIDE);if(CSnifferManager::DestroyThreads())

       CSnifferManager::FreeInstance();

else

{

       PostMessage(WM_CLOSE);

       TRACE("// %s:%dn", __FILE__, __LINE__);

       return;

}

比如在OnClose中加入

void CMySnifferDlg::OnClose()

{

       this->ShowWindow(SW_HIDE);       if(CSnifferManager::DestroyThreads())

              CSnifferManager::FreeInstance();

       else

       {

              PostMessage(WM_CLOSE);

              TRACE("//%s:%dn", __FILE__, __LINE__);

              return;

       }

CDialog::OnClose();

}

Page 3 of 3123

Switch to our mobile site