Click here to Skip to main content
13,348,514 members (80,699 online)
Rate this:
Please Sign up or sign in to vote.
Hi Experts,
After spending my whole last night on google i doesn't found any thing useful to solve my problem.
so my last choice is all of you guys,
now problem start when,
I improves my window based application from serial communication to USB communication for hardware device communication.

When i deal with hardware from my pc .i need intermadiate for communication.need to avoid this with direct USB communication..
When i connect a USB pen drive to PC my software detect it and allows me to write any data on it.

please provide any interface, library , class or any think in c++ or mfc that helps me to read and write data on USB PORT.

Posted 20-Sep-12 23:06pm
Jochen Arndt 21-Sep-12 4:15am
What kind of USB device you are using? The device usually comes with drivers that can be used to access it. These drivers often provide a virtual COM port that can be accessed by your aplication like physical serial ports. You may also identify the chip of your USB device and use the library provided by the chip manufacturer.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

First of all, sleep (it helps keeping you healthy).

Using virtual serial port on USB is often fine. If you need to write data on a pen drive the I believe the easier way is (by far) using OS file functions (you only need to detect when the pen drive is plugged in, using, for instance WMI[^]).

On the other hand, if you really need high speed communication with a USB device then, be warned, it wouldn't be (as far as I know) a simple task (see for instance, here[^]).
Coder Block 21-Sep-12 8:07am
thank u so much for valueable guid but,
i am new bee in usb communication i don't known even how to write data on usb ,
is there is any mechanism or code in mfc or vc++ that allows me to write data on port...
and really its defficult to me to understand the WMI
CPallini 21-Sep-12 8:13am
If you just need to write/read on a pen drive the use the standard OS file functions (e.g. CreateFile). As about WMI I'm a newbie myself, but you may find many samples on the web, just Google for.
Good luck.
Coder Block 5-Oct-12 2:18am
Hey is WDK (Window Driver Kit)is useful while communicating USB device.
i can communincate with USB port using same but,
while using it..
Now i got problem ,
DWORD Error = GetLastError();
where this function return 0 which is invalide and GetLastError() returns 259
please give me little hint why this is happening..
CPallini 5-Oct-12 3:31am
259 means (according to Winerror.h): "no more items".
Coder Block 5-Oct-12 4:05am
how to handle it..
CPallini 5-Oct-12 4:14am
That stops the enumeration, as far as I understand.
Coder Block 5-Oct-12 4:26am
yup but what wrong with code??

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.180111.1 | Last Updated 21 Sep 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100