當前位置:成語大全網 - 新華字典 - 找到壹個可以批量測試的程序或解決方案。

找到壹個可以批量測試的程序或解決方案。

用VC寫網絡程序時,需要反復測試客戶端和服務端。特別是服務器上的程序需要釋放Dll。編譯測試時,您需要執行以下操作:

1.編譯Dll模塊。

2.外殼和壓縮Dll模塊。

3.用BINTOC將Dll模塊轉換成文本數組。

4.將轉換後的文本數組粘貼到服務部分主程序的代碼中。

5.編譯主服務器的主程序。

6.配置服務器主程序。

7.試運行。

如果手動做以上操作,每次測試都會浪費很多時間。測試頻繁時容易出現的強迫癥。於是我重寫了bintoc,在命令行下寫了壹個服務段配置程序,最後寫了壹批,完成編譯和測試過程。內容如下。

@關閉回聲

@echo編譯服務器

Rem server_dll和server_install項目文件夾和編譯輸出文件夾分別是

Rem server_dll,server_install並編譯。

Rem在編譯前要在server_dll和server_install的項目中點擊“項目”->“導出makefile”。

Rem生成server_dll.mak和mouse_install.mak文件。

Rem 1,編譯Dll模塊。

@echo編譯server_dll項目

cd服務器_dll

del /Q發布

nmake /f server_dll.mak

雷姆2。外殼和壓縮Dll模塊。在本例中,使用了UPX,只要它支持命令行。

@echo使用upx壓縮server_dll

激光唱片..

cd編譯

upx -9 server_dll.dll

雷姆3。用BINTOC將Dll模塊轉換成數組頭文件。

@echo將server_dll轉換為GenFile.h

bintoc.exe服務器_dll.dll GenFile.h

雷姆4。用服務部分主程序的頭文件覆蓋數組頭文件。

@echo將GenFile.h復制到server_install項目

激光唱片..

copy/Y % CD % \ compile \ gen file . h % CD % \ server _ install \ gen file . h

Rem 5。編譯主服務器的主程序。

@echo編譯server_install

cd服務器_安裝

del /Q發布

nmake /f server_install.mak

Rem 6,配置服務器主程序。

@echo配置服務器_安裝

激光唱片..

cd編譯

serverconfig.exe服務器_安裝. exe配置. txt

雷姆7號,試運行。

@echo運行server_install

服務器安裝程序

激光唱片..

以下是重寫後的bintoc源代碼

# include & ltstdio.h & gt

文件* in

文件* out

int main(int argc,char *argv[])

{

無符號字符ch;

int CNT = 0;

if(argc & lt;3)

{

printf("用法:bin2c infile . bin outfile . h \ n ");

return-1;

}

if ((out = fopen(argv[2]," WB))= = NULL)

{

printf("無法打開輸出文件。\ n ");

return-1;

}

if ((in = fopen("start.h "," rb "))!=空)

{

printf("打開start.h文件。\ n ");

ch = fgetc(in);

而(!英尺(英寸)

{

fprintf(out," %c ",ch);

ch = fgetc(in);

}

fclose(in);

}

if ((in = fopen(argv[1]," Rb))= = NULL)

{

printf("無法打開數據文件。\ n ");

return-1;

}

fseek(in,0,SEEK _ END);

long lFileSize = ftell(in);

fprintf(out," int DllLen = % ld\n ",lFileSize);

fprintf(out," unsigned char DllData[%ld] = { ",lFileSize);

fseek(in,0,SEEK _ SET);

ch = fgetc(in);

而(!英尺(英寸)

{

如果(cnt!= 0)

fprintf(out,",");

如果(!(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 "))!=空)

{

printf("打開end.h文件。\ n ");

ch = fgetc(in);

而(!英尺(英寸)

{

fprintf(out," %c ",ch);

ch = fgetc(in);

}

fclose(in);

}

fclose(out);

返回0;

}

下面是重寫bintoc需要的文件start.h。

#包含" stdafx.h "

# include & ltstdio.h & gt

BOOL CreateDllFile(LPSTR szpath file);

下面是重寫的bintoc需要的文件end.h。

BOOL created llfile(LPSTR szpath file)

{

FILE * fp

fp=fopen(szPathFile," WB ");

if (fp!=空)

{

fwrite(DllData,1,DllLen,FP);

fclose(FP);

}

返回TRUE

}

摘自紅色黑客聯盟(www.7747.net)原文:/Article/Article/200803/24557 . html