回 帖 发 新 帖 刷新版面

主题:为什么会有这样的错误提示?

程序如下:
#include <windows.h>
#include <stdio.h>
#define BUF_SIZE 256
int main(int argc,LPTSTR argv[])
{
    HANDLE hIn,hOut;
    DWORD nIn,nOut;
    CHAR Buffer[BUF_SIZE];
    if(argc!=3)
    {
        printf("Usage:cp file1 file2\n");
        return 1;
    }
    hIn=CreateFile(argv[1],GENERIC_READ,0,NULL,OPEN_EXISTING,0,NULL);
    if(nIn == INVALID_HANDLE_VALUE)
    {
        printf("Can not open input file.Error:%x\n",GetLastError());
        return 2;
    }
    hOut=CreateFile(argv[2],GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
    if(hOut == INVALID_HANDLE_VALUE)
    {
        printf("Can not open output file:Error:%x\n",GetLastError());
        return 3;
    }
    while(ReadFile(hIn,Buffer,BUF_SIZE,&nIn,NULL)&&nIn>0)
    {
        WriteFile(hOut,Buffer,nIn,&nOut,NULL);
        if(nIn!=nOut)
        {
            printf("Fatal write.Error:%x\n",GetLastError());
            return 4;
        }
    }
    CloseHandle(hIn);
    CloseHandle(hOut);
    return 0;
}
我是用borland c++ compiler 5.5.1编译的
可是出现了这样的错误提示:
---------- Borland C++ Compiler ----------
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
D:\bcc\Pro\test.cpp:
Warning W8012 D:\bcc\Pro\test.cpp 15: Comparing signed and unsigned values in function main(int,char * *)
Error E2034 D:\bcc\Pro\test.cpp 15: Cannot convert 'unsigned long' to 'void *' in function main(int,char * *)
*** 1 errors in Compile ***

Output completed (1 sec consumed) - Normal Termination
其中说的第15行就是:
if(nIn == INVALID_HANDLE_VALUE)
这样话那第21行if(nOut == INVALID_HANDLE_VALUE)也是同样的问题了哦
为什么会这样?
有没有方法?
这个程序在Visual C++下编译没有问题

回复列表 (共2个回复)

沙发

你把 hIn 错打成 nIn 了

板凳

汗!!
犯这样的错误了
谢谢老大

看来要好好先检讨一下自已了

我来回复

您尚未登录,请登录后再回复。点此登录或注册