Your browser does not allow scripts
Please click here to view a static table of contents without scripts
FT_W32_CreateFile
Return to Introduction  Previous page  Next page
Open the specified device and return a handle which will be used for subsequent accesses. The device can be specified by its serial number, device description, or location.

This function must be used if overlapped I/O is required.


FT_HANDLE
FT_W32_CreateFile
(LPCSTR lpszName, DWORD dwAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreate, DWORD dwAttrsAndFlags, HANDLE hTemplate)




Parameters
lpszName
Pointer to a null terminated string that contains the name of the device. The name of the device can be its serial number or description as obtained from the FT_ListDevices function.
dwAccess
Type of access to the device. Access can be GENERIC_READ, GENERIC_WRITE or both. Ignored in Linux.
dwShareMode
How the device is shared. This value must be set to 0.
lpSecurityAttributes
This parameter has no effect and should be set to NULL.
dwCreate
This parameter must be set to OPEN_EXISTING. Ignored in Linux.
dwAttrsAndFlags
File attributes and flags. This parameter is a combination of FILE_ATTRIBUTE_NORMAL, FILE_FLAG_OVERLAPPED if overlapped I/O is used, FT_OPEN_BY_SERIAL_NUMBER if lpszName is the devices serial number, and FT_OPEN_BY_DESCRIPTION if lpszName is the devices description.
hTemplate
This parameter must be NULL




Return Value
If the function is successful, the return value is a handle.
If the function is unsuccessful, the return value is the Win32 error code INVALID_HANDLE_VALUE.



Remarks
The meaning of pvArg1 depends on dwAttrsAndFlags: if FT_OPEN_BY_SERIAL_NUMBER or FT_OPEN_BY_DESCRIPTION is set in dwAttrsAndFlags, pvArg1 contains a pointer to a null terminated string that contains the device's serial number or description; if FT_OPEN_BY_LOCATION is set in dwAttrsAndFlags, pvArg1 is interpreted as a value of type long that contains the location ID of the device.

dwAccess can be GENERIC_READ, GENERIC_WRITE or both; dwShareMode must be set to 0; lpSecurityAttributes must be set to NULL; dwCreate must be set to OPEN_EXISTING; dwAttrsAndFlags is a combination of FILE_ATTRIBUTE_NORMAL, FILE_FLAG_OVERLAPPED if overlapped I/O is used, FT_OPEN_BY_SERIAL_NUMBER or FT_OPEN_BY_DESCRIPTION or FT_OPEN_BY_LOCATION; hTemplate must be NULL.

Windows CE does not support overlapped IO or location IDs.


Examples

The examples that follow use these variables.

FT_STATUS ftStatus;
FT_HANDLE ftHandle;
char Buf[64];


Open a device for overlapped I/O using its serial number

ftStatus = FT_ListDevices(0,Buf,FT_LIST_BY_INDEX|FT_OPEN_BY_SERIAL_NUMBER);

ftHandle = FT_W32_CreateFile(Buf,GENERIC_READ|GENERIC_WRITE,0,0,
               OPEN_EXISTING,
               FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED |                FT_OPEN_BY_SERIAL_NUMBER,
               0);

if (ftHandle == INVALID_HANDLE_VALUE)
   ; // FT_W32_CreateDevice failed


Open a device for non-overlapped I/O using its description

ftStatus = FT_ListDevices(0,Buf,FT_LIST_BY_INDEX|FT_OPEN_BY_DESCRIPTION);

ftHandle = FT_W32_CreateFile(Buf,GENERIC_READ|GENERIC_WRITE,0,0,
               OPEN_EXISTING,
               FILE_ATTRIBUTE_NORMAL | FT_OPEN_BY_DESCRIPTION,
               0);

if (ftHandle == INVALID_HANDLE_VALUE)
   ; // FT_W32_CreateDevice failed


Open a device for non-overlapped I/O using its location

long locID;

ftStatus = FT_ListDevices(0,&locID,FT_LIST_BY_INDEX|FT_OPEN_BY_LOCATION);

ftHandle = FT_W32_CreateFile((PVOID) locID,GENERIC_READ|GENERIC_WRITE,0,0,
               OPEN_EXISTING,
               FILE_ATTRIBUTE_NORMAL | FT_OPEN_BY_LOCATION,
               0);

if (ftHandle == INVALID_HANDLE_VALUE)
   ; // FT_W32_CreateDevice failed