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

C / C++ / MFC

 
GeneralRe: CreateProcess failed Pin
ycc8920095-Mar-10 3:43
ycc8920095-Mar-10 3:43 
GeneralRe: CreateProcess failed Pin
CPallini5-Mar-10 5:23
mveCPallini5-Mar-10 5:23 
AnswerRe: CreateProcess failed Pin
Joe Woodbury5-Mar-10 11:25
professionalJoe Woodbury5-Mar-10 11:25 
QuestionGdiplus::Graphics::DrawString and word wrap Pin
sashoalm4-Mar-10 23:36
sashoalm4-Mar-10 23:36 
AnswerRe: Gdiplus::Graphics::DrawString and word wrap Pin
Luc Pattyn5-Mar-10 1:51
sitebuilderLuc Pattyn5-Mar-10 1:51 
GeneralRe: Gdiplus::Graphics::DrawString and word wrap Pin
sashoalm5-Mar-10 6:34
sashoalm5-Mar-10 6:34 
GeneralRe: Gdiplus::Graphics::DrawString and word wrap Pin
Luc Pattyn5-Mar-10 6:41
sitebuilderLuc Pattyn5-Mar-10 6:41 
Questioncommunicate with usb (MTP) device and IOCTL Pin
Tinf73784-Mar-10 21:54
Tinf73784-Mar-10 21:54 
Hey Smile | :) ,

i study technical computer science and now i want to start with my first driver under WINXP and WINDDK.

I have written two programs to display all connected devices to the computer and a real life detection of adding and removing to the system on two different ways.

/***************/

first:
i build a console application like "usb view" from microsoft to list all devices connected to the pc. After detecting the descriptor i want to start with reading and writing.
To get the usb device i used the IOCTL commands from <a href="http://msdn.microsoft.com/en-us/library/aa476229.aspx">http://msdn.microsoft.com/en-us/library/aa476229.aspx</a>[<a href="http://msdn.microsoft.com/en-us/library/aa476229.aspx" target="_blank" title="New Window">^</a>]

1.) detect host controller (worked)
2.) connect to root hub (worked)
3.) list all ports and connected devices (worked)
4.) fill structe with device desciptor and more
usefull data with this code
IOCTL_USB_GET_NODE_CONNECTION_INFORMATION (worked)
5.) create handle to usb device (problems)

i dont know on which way i can detect the full device path like
\\\\?\\USB#Vid_####&amp;Pid_#####879fe23a000000e83230303630313130#{a5dcbf10-6530-11d2-901f-00c04fb951ed}
or detect a direct handle, i have only the handle to the root hub and the port number.

this is my structure

------------------------------------------
<code>
typedef struct _USB_DEVICES {
HANDLE hDeviceHandle; //RotHubHandle
HANDLE hUSBDeviceHandle; //USBDeviceHandle -> ???
DWORD dwPort; //Port
UCHAR CurrentConfigurationValue;
UCHAR DeviceAddress[2];
UCHAR NumberOfOpenPipes[4];
UCHAR ConnectionStatus[4];
BOOLEAN LowSpeed;
BOOLEAN DeviceIsHub;
USB_PIPE_INFO PipeList[32];
USB_DEVICE_DESCRIPTOR DeviceDescriptor;
USB_CONNECTION_STATUS DeviceStatus;
USB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor;
USB_INTERFACE_DESCRIPTOR InterfaceDescriptor;
} Ts_UsbDevices;
</code>
------------------------------------------

and now my code

------------------------------------------
<code>

......

//get information aber the connected device connected on "dwPort"
ConnectionInformation.ConnectionIndex = s_UsbDevice[dwActiveDevice].dwPort;

bSuccess = DeviceIoControl(s_UsbDevice[dwActiveDevice].hDeviceHandle, -> RootHubHandle
IOCTL_USB_GET_NODE_CONNECTION_INFORMATION,
&ConnectionInformation,
sizeof(ConnectionInformation),
&ConnectionInformation,
sizeof(ConnectionInformation),
&dwBytesReturned,
NULL);

if(bSuccess)
{
// get DeviceName or Handle to start with reading and writing
...
}
</code>
------------------------------------------

i dont know which IOCTL i have to use or on which way i can try to implement some read and wirte functions...

after this problems i checked the internet and found the SetupDi functions and that was the reasen why i started to write a seccond programm

/***************/

seccond:
like the first programm, i build a console application which list all devices. With this function i can detect the device path to create a handle

1.) get all connected devices with SetupDiGetClassDevs() (worked)
2.) get inferfaces with SetupDiEnumDeviceInterfaces() (worked)
3.) get interface details with SetupDiGetInterfaceDeviceDetail() (worked)
4.) CreateFile / DeviceIoControl failed (problems)

i have 3 devices connected to my computer via usb (keyboard, mouse, mtp device (iriver clix), when i tried to create a hanlde to the mouse and keyboard i get this message:
ERROR_GEN_FAILURE 31 (0x1F) - A device attached to the system is not functioning.
ok.. i found out, that microsoft has blocked this devices.. no problem... i dont want to use this.

Then i create a handle to the mtp device and their i have at first no problem. (no error code)

then i tried to test a lot a IOCTL codes with DeviceIoControl to get somme information or to read but erverytime i get the same error message (ERROR_GEN_FAILURE)

i looked in the internet and a lot of people do it on the same way and have no problem. i dont know whats going wrong.

------------------------------------------
<code>

#include <stdio.h>
#include <windows.h>
#include <setupapi.h>
#include <devguid.h>
#include <regstr.h>
#include "initguid.h"

static GUID GUID_DEVINTERFACE_USB_DEVICE = { 0xA5DCBF10L, 0x6530, 0x11D2, { 0x90, 0x1F, 0x00, 0xC0, 0x4F, 0xB9, 0x51, 0xED } };

int main( int argc, char *argv[ ], char *envp[ ] )
{
//HidD_GetHidGuid(&GUID);
DWORD i;
DWORD InterfaceNumber= 0;
HDEVINFO hDevInfo;
SP_DEVINFO_DATA DeviceInfoData;
SP_DEVICE_INTERFACE_DATA DeviceInterfaceData;
struct _GUID GUID = GUID_DEVINTERFACE_USB_DEVICE;

// Create a HDEVINFO with all present devices.
hDevInfo = SetupDiGetClassDevs(&GUID_DEVINTERFACE_USB_DEVICE,NULL,NULL,DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);

if (hDevInfo == INVALID_HANDLE_VALUE)
{
// Insert error handling here.
return 1;
}

// Enumerate through all devices in Set.
DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
for (i=0;SetupDiEnumDeviceInfo(hDevInfo,i,&DeviceInfoData);i++)
{
DWORD DataT;
LPTSTR buffer = NULL;
DWORD buffersize = 0;

while (!SetupDiGetDeviceRegistryProperty(hDevInfo,&DeviceInfoData,SPDRP_LOCATION_INFORMATION ,&DataT,(PBYTE)buffer,buffersize,&buffersize))
{
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
{
// Change the buffer size.
if (buffer) LocalFree(buffer);
buffer = (LPTSTR)LocalAlloc(LPTR,buffersize);
}
else
{
// Insert error handling here.
break;
}
}

if(buffer != NULL)
{
printf("\nDevice Number %i is: %ws",i, buffer);

InterfaceNumber = 0; // this just returns the first one, you can iterate on this
DeviceInterfaceData.cbSize = sizeof(DeviceInterfaceData);

if (SetupDiEnumDeviceInterfaces(hDevInfo,&DeviceInfoData,&GUID,InterfaceNumber,&DeviceInterfaceData))
{
DWORD needed;
SetupDiGetInterfaceDeviceDetail(hDevInfo, &DeviceInterfaceData,NULL, 0, &needed, NULL);
PSP_INTERFACE_DEVICE_DETAIL_DATA detail = (PSP_INTERFACE_DEVICE_DETAIL_DATA) malloc(needed);

if (detail)
{
// fill the device details
detail->cbSize = sizeof(SP_INTERFACE_DEVICE_DETAIL_DATA);

if (SetupDiGetInterfaceDeviceDetail(hDevInfo,&DeviceInterfaceData,detail, needed,NULL, NULL))
{
OpenDevice(detail->DevicePath));
}
}
}
else
{
printf("\n\nNo interface");
}
}

if (buffer) LocalFree(buffer);
}

if ( GetLastError()!=NO_ERROR && GetLastError()!=ERROR_NO_MORE_ITEMS )
{
// Insert error handling here.
return false;
}

// Cleanup
SetupDiDestroyDeviceInfoList(hDevInfo);

getchar();
return 0;
}

void OpenDevice(CHAR DevicePath)
{
HANDLE hUSBDevice = CreateFile(DevicePath,
GENERIC_READ || GENERIC_WRITE,
FILE_SHARE_READ || FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_FLAG_OVERLAPPED,
NULL);

if(hUSBDevice != INVALID_HANDLE_VALUE)
{
// get pipe configuration
bSuccess = DeviceIoControl(s_UsbDevice-&gt;hUSBDevice,
IOCTL_GET_PIPE_CONFIGURATION, NULL,
0, &amp;sUSBPipeInformation, sizeof(sUSBPipeInformation),
&amp;dwBytesReturned,NULL);

if(!bSuccess)
{
//mpt device failed here
// print error message
USB_HW_ErrMsg();
}
}
else
{
//KeyBoad and Mouse failed here
}

}
</code>
------------------------------------------

i hope you can help me.

best regards
QuestionConnecting to a Server Database Pin
jannathali4-Mar-10 21:47
jannathali4-Mar-10 21:47 
QuestionRe: Connecting to a Server Database Pin
David Crow5-Mar-10 7:09
David Crow5-Mar-10 7:09 
QuestionDifference between AVIStreamWrite and AVIStreamWriteData Pin
gmallax4-Mar-10 21:12
gmallax4-Mar-10 21:12 
AnswerRe: Difference between AVIStreamWrite and AVIStreamWriteData Pin
Richard MacCutchan4-Mar-10 21:19
mveRichard MacCutchan4-Mar-10 21:19 
GeneralRe: Difference between AVIStreamWrite and AVIStreamWriteData Pin
gmallax5-Mar-10 20:04
gmallax5-Mar-10 20:04 
QuestionMFC + ORACLE Pin
MsmVc4-Mar-10 19:11
MsmVc4-Mar-10 19:11 
AnswerRe: MFC + ORACLE Pin
Garth J Lancaster4-Mar-10 22:04
professionalGarth J Lancaster4-Mar-10 22:04 
GeneralRe: MFC + ORACLE Pin
MsmVc4-Mar-10 22:13
MsmVc4-Mar-10 22:13 
GeneralRe: MFC + ORACLE Pin
Garth J Lancaster4-Mar-10 22:30
professionalGarth J Lancaster4-Mar-10 22:30 
GeneralRe: MFC + ORACLE Pin
MsmVc4-Mar-10 22:35
MsmVc4-Mar-10 22:35 
GeneralRe: MFC + ORACLE Pin
MsmVc4-Mar-10 22:41
MsmVc4-Mar-10 22:41 
GeneralRe: MFC + ORACLE Pin
Garth J Lancaster4-Mar-10 23:07
professionalGarth J Lancaster4-Mar-10 23:07 
GeneralRe: MFC + ORACLE Pin
MsmVc4-Mar-10 23:11
MsmVc4-Mar-10 23:11 
GeneralRe: MFC + ORACLE Pin
Garth J Lancaster4-Mar-10 23:15
professionalGarth J Lancaster4-Mar-10 23:15 
GeneralRe: MFC + ORACLE Pin
MsmVc7-Mar-10 18:33
MsmVc7-Mar-10 18:33 
QuestionHWND From Procedd ID Pin
john56324-Mar-10 19:00
john56324-Mar-10 19:00 
AnswerRe: HWND From Procedd ID Pin
Adam Roderick J4-Mar-10 19:14
Adam Roderick J4-Mar-10 19:14 

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.