tailieunhanh - USB Complete fourth- P28
USB Complete fourth- P28:This book focuses on Windows programming for PCs, but other computers and operating systems also have USB support, including Linux and Apple Computer’s Macintosh. Some real-time kernels also support USB. | Chapter 10 string from the pointer IntPtr pDevicePathName returned by an API function vb Dim devicePathName as String devicePathName pDevicePathName vc String devicePathName devicePathName pDevicePathName The MarshalAs attribute defines an array s size to enable accessing the array in a structure returned by unmanaged code. This example declares a 16-byte array parameter that will hold a GUID from a structure returned by an API function vb MarshalAs _ ArraySubType SizeConst 16 _ Public dbcc_classguid _ As Byte vc MarshalAs ArraySubType SizeConst 16 public Byte dbcc_classguid The GUID is marshaled into the byte array as an . The ArraySubType field defines the array s elements as unsigned 1-byte U1 values and the SizeConst field sets the array s size as 16 bytes. In an asynchronous read or write operation an application may need to ensure that a variable or structure passed to an unmanaged function remains in the same memory location after the function returns. Doing so enables other unmanaged functions to access the variable or structure when completing the asynchronous operation. The method can help by allocating memory that the garbage collector won t move vb Dim inputReportBuffer 2 As Byte Dim unManagedBuffer As IntPtr unManagedBuffer vc Byte inputReportBuffer 0 0 0 IntPtr unManagedBuffer 246 Detecting Devices unManagedBuffer The method frees allocated memory when the application no longer needs to access the memory vb unManagedBuffer vc unManagedBuffer To ensure that code to free memory or other resources executes place the code in the Finally block of a statement. The examples in this book omit the Try .
đang nạp các trang xem trước