/// <summary> /// Connect to the portable device /// </summary> /// <param name="appName"></param> /// <param name="majorVersionNumber"></param> /// <param name="minorVersionNumber"></param> public void ConnectToDevice(string appName, float majorVersionNumber, float minorVersionNumber) { if (string.IsNullOrEmpty(appName)) { throw new ArgumentNullException("appName"); } //Creating propValues for connection var clientValues = (IPortableDeviceValues) new PortableDeviceValuesClass(); //Set the application name _tagpropertykey prop = PortableDevicePKeys.WPD_CLIENT_NAME; clientValues.SetStringValue(ref prop, appName); //Set the App version prop = PortableDevicePKeys.WPD_CLIENT_MAJOR_VERSION; clientValues.SetFloatValue(ref prop, majorVersionNumber); //Set the app minor version prop = PortableDevicePKeys.WPD_CLIENT_MINOR_VERSION; clientValues.SetFloatValue(ref prop, minorVersionNumber); //Open connection PortableDeviceClass.Open(DeviceId, clientValues); //Extract device capabilities ExtractDeviceCapabilities(); eventCallback = new PortableDeviceEventCallback(this); // According to documentation pParameters should be null (see http://msdn.microsoft.com/en-us/library/dd375684%28v=VS.85%29.aspx ) PortableDeviceClass.Advise(0, eventCallback, null, out adviseCookie); IsConnected = true; }