新手学C++ 帮忙看段代码,进来赚积分了
这是网上下载的代码,老是在第一个return 就结束了 ,按理说代码没问题的,怎么让程序运行到后面的。
试过把后面的代码调前和把第一个retyrn注释,但运行后程序错误
int main (int argc, char** argv)
{
// Open a file in read-only mode (flag 0x1).
// You can also open an image file with the contents of a disk and interpret
// it as such by specifying another flag (0x4).
if (argc <2) {
cout << "Please give a file name" << endl;
return 1;
}
// Initialize the WinHex API, so that it is ready for use
int initRes = WHX_Init(1); //初始化函数
if (initRes <= 0) {
cout << "Could not initialize WinHexAPI.dll, error" << initRes << endl;
WHX_Done();//初始化失败,则调用“完成”的函数
return 1;
} else if (initRes == 2) {
cout << "Opened WinHex API, evaluation version" << endl;//如果返回值等于2,则表明所使用的版本为评估版
}
if (! WHX_OpenEx(argv[1], 0x00000001)) {
cout << "Error opening " << argv[1] << endl;
WHX_Done();//完成,返回。
return 1;//返回。
}
//WHX_Goto(SomeOffset);
char buf[256];
WHX_Read(buf, sizeof(buf));//调用读取文件的函数
DumpBuf(buf, sizeof(buf));//完成其他的功能
// Close the file
WHX_Close();//关闭文件
// Properly free all allocated resources and release the WinHex API
WHX_Done();//完成
return 0;//返回
}
运行可执行文件的时候要输入参数的!
//argc 表示命令行输入参数的个数(以空白符分隔) argv存储了所有的命令行参数
//这里是至少两个 一个是你的可执行文件,一个你是要操作打开的文件!
if (argc <2) {
cout << "Please give a file name" << endl;
return 1;
}
WHX_OpenEx(argv[1], 0x00000001)
//这里的argv[1],就是你命令行的第二个参数了!