Readfile and Writefile in win32 fails with error code 1

Go To StackoverFlow.com

1

Code :

hHCDev = CreateFileA(completeDeviceName,
                        //"F:\\test.txt",
                        GENERIC_WRITE|GENERIC_READ,
                        FILE_SHARE_WRITE|FILE_SHARE_READ,
                        NULL,
                        OPEN_EXISTING,
                        0,
                        NULL);



    if (hHCDev == INVALID_HANDLE_VALUE)
        {
                CloseHandle(hHCDev);
        }
    else
        {
            char bufRead[256] = {0};
            DWORD countRead = 0;
            BOOL result ;

            result = ReadFile(hHCDev, bufRead, 5, &countRead, NULL) ;
            if(!result)
            {
                printf("Reading file error %d\n", GetLastError());
            }


            char bufWrite[] = {'7', '8', '9', ' '};
            DWORD countWritten = 0;


            result = WriteFile(hHCDev, bufWrite, 3, &countWritten, NULL) ;
            if(!result)
            {
                printf("Writing file error %d\n", GetLastError());
            }
            else
                {
                    printf("sucess");
                }
            CloseHandle(hHCDev);
        }
        memset(completeDeviceName,0,256) ;

Description:

We tried to open the USB device connected using createfile(). Using Readfile and Writefile() calls we tried to communicate with the device. But these calls returned with error code 1. What might be the reason??

Your Help would be highly appreciated.

Best Regards Suren

2009-06-16 14:13
by NoName
which version of Windows do you use - devio 2009-08-03 12:27


0

Try to run your application with administrator rights.

2009-06-16 14:26
by Kirill V. Lyadvinsky
Ads