tags:

views:

371

answers:

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

A: 

Try to run your application with administrator rights.

Kirill V. Lyadvinsky