static void Main(string[] args) { PortableDeviceApiLib.IPortableDeviceValues clientInfo = (PortableDeviceApiLib.IPortableDeviceValues)new PortableDeviceTypesLib.PortableDeviceValues(); { clientInfo.SetStringValue(ref WPD_CLIENT_NAME, szClientName); clientInfo.SetUnsignedIntegerValue(ref WPD_CLIENT_MAJOR_VERSION, dwClientVersionMajor); clientInfo.SetUnsignedIntegerValue(ref WPD_CLIENT_MINOR_VERSION, dwClientVersionMinor); clientInfo.SetUnsignedIntegerValue(ref WPD_CLIENT_REVISION, dwClientRevision); clientInfo.SetUnsignedIntegerValue(ref WPD_CLIENT_SECURITY_QUALITY_OF_SERVICE, SECURITY_IMPERSONATION); clientInfo.SetUnsignedIntegerValue(ref WPD_CLIENT_DESIRED_ACCESS, GENERIC_READ); clientInfo.SetUnsignedIntegerValue(ref WPD_CLIENT_SHARE_MODE, FILE_SHARE_READ | FILE_SHARE_WRITE); } for (uint loopCount = 0; loopCount < 100; ++loopCount) { PortableDeviceApiLib.PortableDeviceManager devMgr = new PortableDeviceApiLib.PortableDeviceManager(); devMgr.RefreshDeviceList(); string strDeviceId = null; uint nDeviceCount = 1; // 1 is allowed. over 2, leak CoTaskMemFree at marshall System.Diagnostics.Debug.Assert(1 == nDeviceCount); devMgr.GetDevices(ref strDeviceId, ref nDeviceCount); System.Console.WriteLine("DeviceCount={0}", nDeviceCount); if (0 < nDeviceCount) { //Console.WriteLine(strDeviceId); PortableDeviceApiLib.PortableDevice dev = new PortableDeviceApiLib.PortableDevice(); dev.Open(strDeviceId, clientInfo); PortableDeviceApiLib.IPortableDeviceContent content = null; dev.Content(out content); if (null != content) { for (uint count = 0; count < 30; ++count) { Console.WriteLine("enumrate start"); countContent = 0; bool result = wpdEnumContent(WPD_DEVICE_OBJECT_ID, content); Console.WriteLine("enumrate end: count count={0}", countContent); if (false == result) { break; } System.Threading.Thread.Sleep(1 * 1000); } content = null; } dev.Close(); dev = null; } devMgr = null; System.Threading.Thread.Sleep(1 * 1000); } }
static void Main(string[] args) { PortableDeviceApiLib.PortableDeviceManager devMgr = new PortableDeviceApiLib.PortableDeviceManager(); for (uint loopCount = 0; loopCount < 10000; ++loopCount) { devMgr.RefreshDeviceList(); string[] deviceIDarray = null; uint nDeviceCount = 0; devMgr.GetDevices(null, ref nDeviceCount); //Console.WriteLine("nDeviceCount={0}", nDeviceCount); if (0 < nDeviceCount) { deviceIDarray = new string[nDeviceCount]; devMgr.GetDevices(deviceIDarray, ref nDeviceCount); } if (null != deviceIDarray) { foreach( string deviceId in deviceIDarray) { { uint buffSize = 0; devMgr.GetDeviceFriendlyName(deviceId, null, ref buffSize); if (0 < buffSize) { ushort[] buff = new ushort[buffSize]; devMgr.GetDeviceFriendlyName(deviceId, buff, ref buffSize); byte[] bytes = new byte[buff.Length * sizeof(ushort)]; Buffer.BlockCopy(buff, 0, bytes, 0, bytes.Length); string str = System.Text.Encoding.Unicode.GetString(bytes); //Console.WriteLine(str); } } { uint buffSize = 0; devMgr.GetDeviceManufacturer(deviceId, null, ref buffSize); if (0 < buffSize) { ushort[] buff = new ushort[buffSize]; devMgr.GetDeviceManufacturer(deviceId, buff, ref buffSize); byte[] bytes = new byte[buff.Length * sizeof(ushort)]; Buffer.BlockCopy(buff, 0, bytes, 0, bytes.Length); string str = System.Text.Encoding.Unicode.GetString(bytes); //Console.WriteLine(str); } } { uint buffSize = 0; devMgr.GetDeviceDescription(deviceId, null, ref buffSize); if (0 < buffSize) { ushort[] buff = new ushort[buffSize]; devMgr.GetDeviceDescription(deviceId, buff, ref buffSize); byte[] bytes = new byte[buff.Length * sizeof(ushort)]; Buffer.BlockCopy(buff, 0, bytes, 0, bytes.Length); string str = System.Text.Encoding.Unicode.GetString(bytes); //Console.WriteLine(str); } } Program2.wpdEnum(deviceId); } deviceIDarray = null; } System.Threading.Thread.Sleep(1 * 100); } }
static void Main(string[] args) { PortableDeviceApiLib.PortableDeviceManager devMgr = new PortableDeviceApiLib.PortableDeviceManager(); for (uint loopCount = 0; loopCount < 10000; ++loopCount) { devMgr.RefreshDeviceList(); string[] deviceIDarray = null; uint nDeviceCount = 0; devMgr.GetDevices(null, ref nDeviceCount); //Console.WriteLine("nDeviceCount={0}", nDeviceCount); if (0 < nDeviceCount) { deviceIDarray = new string[nDeviceCount]; devMgr.GetDevices(deviceIDarray, ref nDeviceCount); } if (null != deviceIDarray) { foreach (string deviceId in deviceIDarray) { { uint buffSize = 0; devMgr.GetDeviceFriendlyName(deviceId, null, ref buffSize); if (0 < buffSize) { ushort[] buff = new ushort[buffSize]; devMgr.GetDeviceFriendlyName(deviceId, buff, ref buffSize); byte[] bytes = new byte[buff.Length * sizeof(ushort)]; Buffer.BlockCopy(buff, 0, bytes, 0, bytes.Length); string str = System.Text.Encoding.Unicode.GetString(bytes); //Console.WriteLine(str); } } { uint buffSize = 0; devMgr.GetDeviceManufacturer(deviceId, null, ref buffSize); if (0 < buffSize) { ushort[] buff = new ushort[buffSize]; devMgr.GetDeviceManufacturer(deviceId, buff, ref buffSize); byte[] bytes = new byte[buff.Length * sizeof(ushort)]; Buffer.BlockCopy(buff, 0, bytes, 0, bytes.Length); string str = System.Text.Encoding.Unicode.GetString(bytes); //Console.WriteLine(str); } } { uint buffSize = 0; devMgr.GetDeviceDescription(deviceId, null, ref buffSize); if (0 < buffSize) { ushort[] buff = new ushort[buffSize]; devMgr.GetDeviceDescription(deviceId, buff, ref buffSize); byte[] bytes = new byte[buff.Length * sizeof(ushort)]; Buffer.BlockCopy(buff, 0, bytes, 0, bytes.Length); string str = System.Text.Encoding.Unicode.GetString(bytes); //Console.WriteLine(str); } } Program2.wpdEnum(deviceId); } deviceIDarray = null; } System.Threading.Thread.Sleep(1 * 100); } }
static void Main(string[] args) { PortableDeviceApiLib.IPortableDeviceValues clientInfo = (PortableDeviceApiLib.IPortableDeviceValues) new PortableDeviceTypesLib.PortableDeviceValues(); { clientInfo.SetStringValue(ref WPD_CLIENT_NAME, szClientName); clientInfo.SetUnsignedIntegerValue(ref WPD_CLIENT_MAJOR_VERSION, dwClientVersionMajor); clientInfo.SetUnsignedIntegerValue(ref WPD_CLIENT_MINOR_VERSION, dwClientVersionMinor); clientInfo.SetUnsignedIntegerValue(ref WPD_CLIENT_REVISION, dwClientRevision); clientInfo.SetUnsignedIntegerValue(ref WPD_CLIENT_SECURITY_QUALITY_OF_SERVICE, SECURITY_IMPERSONATION); clientInfo.SetUnsignedIntegerValue(ref WPD_CLIENT_DESIRED_ACCESS, GENERIC_READ); clientInfo.SetUnsignedIntegerValue(ref WPD_CLIENT_SHARE_MODE, FILE_SHARE_READ | FILE_SHARE_WRITE); } for (uint loopCount = 0; loopCount < 100; ++loopCount) { PortableDeviceApiLib.PortableDeviceManager devMgr = new PortableDeviceApiLib.PortableDeviceManager(); devMgr.RefreshDeviceList(); string strDeviceId = null; uint nDeviceCount = 1; // 1 is allowed. over 2, leak CoTaskMemFree at marshall System.Diagnostics.Debug.Assert(1 == nDeviceCount); devMgr.GetDevices(ref strDeviceId, ref nDeviceCount); System.Console.WriteLine("DeviceCount={0}", nDeviceCount); if (0 < nDeviceCount) { //Console.WriteLine(strDeviceId); PortableDeviceApiLib.PortableDevice dev = new PortableDeviceApiLib.PortableDevice(); dev.Open(strDeviceId, clientInfo); PortableDeviceApiLib.IPortableDeviceContent content = null; dev.Content(out content); if (null != content) { for (uint count = 0; count < 30; ++count) { Console.WriteLine("enumrate start"); countContent = 0; bool result = wpdEnumContent(WPD_DEVICE_OBJECT_ID, content); Console.WriteLine("enumrate end: count count={0}", countContent); if (false == result) { break; } System.Threading.Thread.Sleep(1 * 1000); } content = null; } dev.Close(); dev = null; } devMgr = null; System.Threading.Thread.Sleep(1 * 1000); } }