利用批处理快速编译测试VC网络程序

        在用VC编写一个网络程序时需要反复测试客户端和服务段。尤其是服务端的程序需要释放Dll。编译测试的时候需要进行以下操作:
        1、编译Dll模块。
        2、将Dll模块加壳压缩。
        3、将Dll模块用BINTOC转换成文本数组。
        4、将转换的文本数组粘贴到服务段主程序的代码中。
        5、编译主服务端主程序。
        6、配置服务端主程序。
        7、测试运行。
       如果手动进行以上操作,每次测试都浪费不少时间。测试频繁的时候还容易的强迫症。于是改写了bintoc,再写了个命令行下的服务段配置程序,最后写了个批处理来完成编译测试过程,内容如下。

@echo off
@echo compile server

rem  server_dll和server_install工程文件夹和编译输出文件夹分别为
rem  server_dll、server_install和compile。
rem  在编译之前要分别在server_dll和server_install的工程中点击“Project”-〉“Export MakeFIle”
rem  生成server_dll.mak和mouse_install.mak文件。

rem  1、编译Dll模块。
@echo compile server_dll project
cd server_dll
del /Q Release
nmake /f server_dll.mak

rem  2、将Dll模块加壳压缩,本例中用UPX ,只要支持命令行的都可以。
@echo compress server_dll use upx
cd..
cd compile
upx -9 server_dll.dll

rem 3、将Dll模块用BINTOC转换成数组头文件。
@echo convert server_dll to GenFile.h
bintoc.exe server_dll.dll  GenFile.h

rem 4、将数组头文件覆盖服务段主程序的头文件。
@echo copy GenFile.h to server_install project
cd..
copy /Y %cd%/compile/GenFile.h %cd%/server_install/GenFile.h

rem 5、编译主服务端主程序。
@echo compile server_install
cd server_install
del /Q Release
nmake /f server_install.mak

rem 6、配置服务端主程序。
@echo config server_install
cd..
cd compile
serverconfig.exe server_install.exe config.txt

rem 7、测试运行。
@echo run server_install
server_install.exe
cd ..

   
       下面是改写的bintoc源码

#include <stdio.h>
FILE *in;
FILE *out;
int main(int argc, char *argv[])
{
    unsigned char ch;
    int    cnt = 0;
    if (argc < 3)
    {
        printf("usage: bin2c infile.bin outfile.h /n");
        return -1;
    }
   
    if ((out = fopen(argv[2], "wb")) == NULL)
    {
        printf("Couldn't open output file./n");
        return -1;
    }

    if ((in = fopen("start.h", "rb")) != NULL)
    {
        printf("open start.h file./n");
        ch = fgetc(in);
        while (!feof(in))
        {
            fprintf(out, "%c", ch);
            ch = fgetc(in);
        }
        fclose(in);
    }
   

    if ((in = fopen(argv[1], "rb")) == NULL)
    {
        printf("Couldn't open data file./n");
        return -1;
    }
   
    fseek(in,0,SEEK_END); 
    long   lFileSize   =   ftell(in);
    fprintf(out, "int  Dll Len = %ld;/n", lFileSize);
    fprintf(out, "unsigned char DllData [%ld] = {", lFileSize);
    fseek(in,0,SEEK_SET);
    ch = fgetc(in);
    while (!feof(in))
    {
        if (cnt != 0)
            fprintf(out, ", ");
        if (!(cnt % 10))
            fprintf(out, "/n/t");
        fprintf(out, "0x%02x", (int)ch);
        cnt++;
        ch = fgetc(in);
    }
    fprintf(out, "/n};/n");
    fclose(in);

    if ((in = fopen("end.h", "rb")) != NULL)
    {
        printf("open end.h file./n");
        ch = fgetc(in);
        while (!feof(in))
        {
            fprintf(out, "%c", ch);
            ch = fgetc(in);
        }   
        fclose(in);
    }
   
    fclose(out);
    return 0;
}

       下面是改写的bintoc需要的文件 start.h

#include "stdafx.h"
#include <stdio.h>

BOOL CreateDllFile ( LPSTR szPathFile );

      
下面是改写的bintoc需要的文件 end.h

BOOL CreateDllFile( LPSTR szPathFile )
{
    FILE *fp;
    fp=fopen(szPathFile, "wb");
    if (fp!=NULL)
    {
        fwrite(DllData, 1, Dll Len, fp);
        fclose(fp);
    } 
     return TRUE;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值