用vc++ 实现与usb相连 求大神挑错 下面是程序

2019-07-16 08:42发布

#include <iostream>
#include "stdafx.h"
#include "windows.h"
#include "Setupapi.h"
#include "stdio.h"
HANDLE CreatFile
DWORD dwDesiredAcess,//访问模式
DWORD dwShareMode,//共享模式
LPSECURITY_ATTRIBUTES lpSecurityAttribute,//通常为NULL
DWORD dwCreationDistribution,//创建方式
DWORD dwFlagsAndAttributes,//文件属性和标志
HANDLE hTemplateFile,//临时文件的句柄
);

HDEVINFO SetupDiGetClassDevs
(
IN PGUID ClassGuid,//classguid :任意指向一个安装类或接口类的GUID
IN PCTSTR Enumerator,//enumerator:任意指向一个字符串,它过滤返回的设备
IN HWND hwndParent,//给出与该信息集的成员有关的任何拥护接口所用的顶层窗口句柄
IN DWORD Flags,//给出构造设备信息集时所用的控制操作
);

SetupDiEnumDeviceInterfaces
(
IN HDEVINFO DeviceInfoSet,
IN PSP_DEVINFO_DATA DeviceInfoData,
IN LPGUID InterfaceClassGuid,
IN DWORD MenberIndex,
OUT PSP_DEVICE_INTERFACE_DATA DeviceInterface_Data
);

SetupDiGetInterfaceDevicrDetail
(
IN HDEVINFO DeviceInfoSet,
IN PSP_DEVICE_INTERFACE_DATA DeviceInterface_Data,
OUT PS_DEVICE_INTERFACE_DETAIL_DATA DeviceInterfaceDetailData,
IN DWORD DeviceInterfaceDetailDataSize,
OUT PDWORD RequiredSize,OPTIONAL
OUT PSP_DEVINFO_DATA DeiceInfoData OPTIONAL
);

typedef stuct
_SP_DEVICE_INTERFACE_DETAIL_DATA_A
{
        DWORD cbSize;
        CHAR DevicePath[ANYSIZE_ARRAY];
}
SP_DEVICE_INTERFACE_DETAIL_DATA_A,*PSP_DEVICE_INTERFACE_DETAIL_DATA_A;
//部分程序
HANDLE hOut;
hOut=CreatFile
(
pDetail->DevicePath,GENERIC_READ|FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL|FILE_FLAG_OVERLAPPED,
NULL
);

BOOL ReadFile
(
HANDLE hCom,
LOPVOID lpBuffer,
DWORD nNumberOfBytesToRead,
LPDWORD lpNumberOverlapped
);
BOOL WriteFile
(
HANDLE hCom,
LPCVOID lpBuffer,
DWORD nNumberOfBybesTOWRITE,
LPDWORD lpNumberOfBytes Written,
LPOVERLAPPED lpOverlapped
);


友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。