Click here to Skip to main content
16,004,854 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Plz sir slow down Pin
CPallini13-May-08 20:55
mveCPallini13-May-08 20:55 
AnswerRe: TCHAR porting issues while porting from VC6 to VC8 Pin
CPallini13-May-08 4:05
mveCPallini13-May-08 4:05 
AnswerRe: TCHAR porting issues while porting from VC6 to VC8 Pin
Iain Clarke, Warrior Programmer13-May-08 5:15
Iain Clarke, Warrior Programmer13-May-08 5:15 
QuestionPassing a function as parameter. Pin
mikyivy13-May-08 3:45
mikyivy13-May-08 3:45 
AnswerRe: Passing a function as parameter. Pin
Rajkumar R13-May-08 3:51
Rajkumar R13-May-08 3:51 
AnswerRe: Passing a function as parameter. Pin
David Crow13-May-08 3:54
David Crow13-May-08 3:54 
AnswerRe: Passing a function as parameter. Pin
Mark Salsbery13-May-08 5:16
Mark Salsbery13-May-08 5:16 
QuestionReading from and Writing to a USB device using ReadFile() and WriteFile() Pin
koumodaki13-May-08 3:44
koumodaki13-May-08 3:44 
Hi,

I am working on a hardware controller device which has a USB port I need to use to write commands to the controller.
I have been able to ennumerate the device and obtain the handle for that device using CreateFile().

But when I try to execute ReadFile() or WriteFile(), the function fails and GetLastError() returns ERROR_INVALID_FUNCTION.

My code looks like this:

HANDLE hUsbDevice = CreateFile(path.c_str(),GENERIC_READ|GENERIC_WRITE,
0, NULL, OPEN_EXISTING, 0, NULL);

if (hUsbDevice == INVALID_HANDLE_VALUE)
{
val = GetLastError();
cout<<"failed in CreateFile"<<" error: "<<val<<"\n" ;
}
else
{
char _send_buff[] = {'I','n','i','t','1','=','0','\0'};
int _send_size = sizeof(_send_buff);
int _wrstatus = 0;
DWORD _bytes_written = 0;

_wrstatus = WriteFile(hUsbDevice,_buff,_size,&_bytes_written,NULL);

if (!_wrstatus)
cout<<"\nError while writing port: "<<GetLastError()<<endl;
}

Where am I going wrong here Confused | :confused:
AnswerRe: Reading from and Writing to a USB device using ReadFile() and WriteFile() Pin
Cedric Moonen13-May-08 4:02
Cedric Moonen13-May-08 4:02 
GeneralRe: Reading from and Writing to a USB device using ReadFile() and WriteFile() Pin
koumodaki13-May-08 4:11
koumodaki13-May-08 4:11 
GeneralRe: Reading from and Writing to a USB device using ReadFile() and WriteFile() Pin
Cedric Moonen13-May-08 4:24
Cedric Moonen13-May-08 4:24 
GeneralRe: Reading from and Writing to a USB device using ReadFile() and WriteFile() Pin
koumodaki13-May-08 4:49
koumodaki13-May-08 4:49 
AnswerRe: Reading from and Writing to a USB device using ReadFile() and WriteFile() Pin
Iain Clarke, Warrior Programmer13-May-08 4:09
Iain Clarke, Warrior Programmer13-May-08 4:09 
AnswerRe: Reading from and Writing to a USB device using ReadFile() and WriteFile() Pin
Hamid_RT14-May-08 6:25
Hamid_RT14-May-08 6:25 
QuestionSMTP Mail Class [modified] Pin
Programm3r13-May-08 3:12
Programm3r13-May-08 3:12 
QuestionRe: Mail Class Pin
CPallini13-May-08 3:16
mveCPallini13-May-08 3:16 
AnswerRe: Mail Class Pin
Programm3r13-May-08 3:30
Programm3r13-May-08 3:30 
GeneralRe: Mail Class Pin
CPallini13-May-08 3:36
mveCPallini13-May-08 3:36 
GeneralRe: Mail Class Pin
Programm3r13-May-08 3:44
Programm3r13-May-08 3:44 
AnswerRe: Mail Class Pin
David Crow13-May-08 3:17
David Crow13-May-08 3:17 
QuestionRe: Mail Class Pin
Programm3r13-May-08 3:33
Programm3r13-May-08 3:33 
AnswerRe: Mail Class Pin
David Crow13-May-08 3:51
David Crow13-May-08 3:51 
GeneralRe: Mail Class Pin
Programm3r13-May-08 4:00
Programm3r13-May-08 4:00 
GeneralRe: Mail Class Pin
toxcct13-May-08 4:03
toxcct13-May-08 4:03 
GeneralRe: Mail Class Pin
Programm3r13-May-08 4:13
Programm3r13-May-08 4:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.