With this library you can access smartpones, tablets, cameras and other mobile devices that support the MTP (Media Transfer Protocol) protocol and read device information (device ID, device name, firmware version, manufacturer, serial number, ...) and the directories and files on the device and copy them to the PC.
I tested it with my iPhone and with my Canon digital camera.
Functions:
- ExamineMTP()
- Syntax:
Code: Select all
Result = ExamineMTP(@ErrorOutput$)
- Description: Starts the list of all devices. This could be smartphones, tablets, cameras, mass storage and other mobile devices.
- Parameter:
- @ErrorOutput$: If an error occurred, the error message is stored in the variable. This variable must be reserved with 128 characters before passing. Maximum return length is 128 characters including the NULL character. If no error description is to be returned for an error, 0 can be passed instead.
- Return value:
- 1: The process was successful.
- Syntax:
Code: Select all
Result = NextMTPEntry(@ErrorOutput$)
- Description: The next device is determined. This function is only valid within the ExamineMTP loop.
- Parameter:
- @ErrorOutput$: If an error occurred, the error message is stored in the variable. This variable must be reserved with 128 characters before passing. Maximum return length is 128 characters including the NULL character. If no error description is to be returned for an error, 0 can be passed instead.
- Return value:
- 1: The process was successful.
- Syntax:
Code: Select all
Result = FinishMTP(@ErrorOutput$)
- Description: Closes the list of devices. This function is only valid within the ExamineMTP loop.
- Parameter:
- @ErrorOutput$: If an error occurred, the error message is stored in the variable. This variable must be reserved with 128 characters before passing. Maximum return length is 128 characters including the NULL character. If no error description is to be returned for an error, 0 can be passed instead.
- Return value:
- 1: The process was successful.
- Syntax:
Code: Select all
Result = MTPEntryName(@Output$, @ErrorOutput$)
- Description: Determines the name of the current device. This function is only valid within the ExamineMTP loop.
- Parameter:
- @Output$: The device name is stored in this variable. With this name it is possible to access this device with OpenMTP() to read device information and copy files.
- @ErrorOutput$: If an error occurred, the error message is stored in the variable. This variable must be reserved with 128 characters before passing. Maximum return length is 128 characters including the NULL character. If no error description is to be returned for an error, 0 can be passed instead.
- Return value:
- 1: The process was successful.
- Syntax:
Code: Select all
Result = OpenMTP(ID, DeviceName$, @ErrorOutput$)
- Description: Connects to the specified device to read device information and copy files.
- Parameter:
- ID: A unique number. #PB_Any can be used to generate the number automatically.
- DeviceName$: The name of the device. The device name can be determined with ExamineMTP().
- @ErrorOutput$: If an error occurred, the error message is stored in the variable. This variable must be reserved with 128 characters before passing. Maximum return length is 128 characters including the NULL character. If no error description is to be returned for an error, 0 can be passed instead.
- Return value:
- 1: The process was successful. If #PB_Any is used, the ID is returned.
- Example:
Code: Select all
EnableExplicit Global PBEx_MTP #PBEx_MTP_Type_File = 1 #PBEx_MTP_Type_Directory = 2 #PBEx_MTP_DeviceType_Generic = 0 #PBEx_MTP_DeviceType_Camera = 1 #PBEx_MTP_DeviceType_MediaPlayer = 2 #PBEx_MTP_DeviceType_Phone = 3 #PBEx_MTP_DeviceType_Video = 4 #PBEx_MTP_DeviceType_PersonalInformationManager = 5 #PBEx_MTP_DeviceType_AudioRecorder = 6 CompilerIf #PB_Compiler_Processor = #PB_Processor_x86 PBEx_MTP = OpenLibrary(#PB_Any, "PB.Ex_MTP_x86.dll") CompilerElseIf #PB_Compiler_Processor = #PB_Processor_x64 PBEx_MTP = OpenLibrary(#PB_Any, "PB.Ex_MTP_x64.dll") CompilerEndIf If PBEx_MTP Prototype ExamineMTP(ErrorOutput) Global ExamineMTP.ExamineMTP = GetFunction(PBEx_MTP, "ExamineMTP") Prototype NextMTPEntry(ErrorOutput) Global NextMTPEntry.NextMTPEntry = GetFunction(PBEx_MTP, "NextMTPEntry") Prototype FinishMTP(ErrorOutput) Global FinishMTP.FinishMTP = GetFunction(PBEx_MTP, "FinishMTP") Prototype MTPEntryName(Output, ErrorOutput) Global MTPEntryName.MTPEntryName = GetFunction(PBEx_MTP, "MTPEntryName") Prototype OpenMTP(ID, DeviceName.p-Unicode, ErrorOutput) Global OpenMTP.OpenMTP = GetFunction(PBEx_MTP, "OpenMTP") Prototype CloseMTP(ID, ErrorOutput) Global CloseMTP.CloseMTP = GetFunction(PBEx_MTP, "CloseMTP") Prototype IsMTP(ID, ErrorOutput) Global IsMTP.IsMTP = GetFunction(PBEx_MTP, "IsMTP") Prototype ExamineMTPDirectory(ID, ErrorOutput) Global ExamineMTPDirectory.ExamineMTPDirectory = GetFunction(PBEx_MTP, "ExamineMTPDirectory") Prototype FinishMTPDirectory(ID, ErrorOutput) Global FinishMTPDirectory.FinishMTPDirectory = GetFunction(PBEx_MTP, "FinishMTPDirectory") Prototype NextMTPDirectoryEntry(ID, ErrorOutput) Global NextMTPDirectoryEntry.NextMTPDirectoryEntry = GetFunction(PBEx_MTP, "NextMTPDirectoryEntry") Prototype MTPDirectoryEntryName(ID, Output, ErrorOutput) Global MTPDirectoryEntryName.MTPDirectoryEntryName = GetFunction(PBEx_MTP, "MTPDirectoryEntryName") Prototype SetMTPDirectory(ID, DirectoryPath.p-Unicode, ErrorOutput) Global SetMTPDirectory.SetMTPDirectory = GetFunction(PBEx_MTP, "SetMTPDirectory") Prototype GetMTPDirectory(ID, Output, ErrorOutput) Global GetMTPDirectory.GetMTPDirectory = GetFunction(PBEx_MTP, "GetMTPDirectory") Prototype MTPDirectoryEntryType(ID, ErrorOutput) Global MTPDirectoryEntryType.MTPDirectoryEntryType = GetFunction(PBEx_MTP, "MTPDirectoryEntryType") Prototype ReceiveMTPFile(ID, RemoteFileName.p-Unicode, FileName.p-Unicode, ErrorOutput) Global ReceiveMTPFile.ReceiveMTPFile = GetFunction(PBEx_MTP, "ReceiveMTPFile") Prototype MTPDirectoryEntrySize(ID, ErrorOutput) Global MTPDirectoryEntrySize.MTPDirectoryEntrySize = GetFunction(PBEx_MTP, "MTPDirectoryEntrySize") Prototype MTPDirectoryEntryDate(ID, ErrorOutput) Global MTPDirectoryEntryDate.MTPDirectoryEntryDate = GetFunction(PBEx_MTP, "MTPDirectoryEntryDate") Prototype GetMTPDescription(ID, Output, ErrorOutput) Global GetMTPDescription.GetMTPDescription = GetFunction(PBEx_MTP, "GetMTPDescription") Prototype GetMTPDeviceID(ID, Output, ErrorOutput) Global GetMTPDeviceID.GetMTPDeviceID = GetFunction(PBEx_MTP, "GetMTPDeviceID") Prototype GetMTPDeviceType(ID, ErrorOutput) Global GetMTPDeviceType.GetMTPDeviceType = GetFunction(PBEx_MTP, "GetMTPDeviceType") Prototype GetMTPFirmwareVersion(ID, Output, ErrorOutput) Global GetMTPFirmwareVersion.GetMTPFirmwareVersion = GetFunction(PBEx_MTP, "GetMTPFirmwareVersion") Prototype GetMTPFriendlyName(ID, Output, ErrorOutput) Global GetMTPFriendlyName.GetMTPFriendlyName = GetFunction(PBEx_MTP, "GetMTPFriendlyName") Prototype GetMTPManufacturer(ID, Output, ErrorOutput) Global GetMTPManufacturer.GetMTPManufacturer = GetFunction(PBEx_MTP, "GetMTPManufacturer") Prototype GetMTPModel(ID, Output, ErrorOutput) Global GetMTPModel.GetMTPModel = GetFunction(PBEx_MTP, "GetMTPModel") Prototype GetMTPPnPDeviceID(ID, Output, ErrorOutput) Global GetMTPPnPDeviceID.GetMTPPnPDeviceID = GetFunction(PBEx_MTP, "GetMTPPnPDeviceID") Prototype GetMTPSerialNumber(ID, Output, ErrorOutput) Global GetMTPSerialNumber.GetMTPSerialNumber = GetFunction(PBEx_MTP, "GetMTPSerialNumber") EndIf Global Output$ = Space(1024) Global ErrorOutput$ = Space(128) ;List all devices to determine the device name. ; If ExamineMTP(@ErrorOutput$) ; While NextMTPEntry(@ErrorOutput$) ; MTPEntryName(@Output$, @ErrorOutput$) ; Debug Output$ ; Wend ; EndIf ;List all directories and files. ;If OpenMTP(1, "Canon IXUS 125 HS", @ErrorOutput$) If OpenMTP(1, "Apple iPhone", @ErrorOutput$) ;Get device information GetMTPFriendlyName(1, @Output$, @ErrorOutput$) Debug "Friendly name: " + Output$ GetMTPManufacturer(1, @Output$, @ErrorOutput$) Debug "Manufacturer: " + Output$ GetMTPFirmwareVersion(1, @Output$, @ErrorOutput$) Debug "Firmware version: " + Output$ GetMTPPnPDeviceID(1, @Output$, @ErrorOutput$) Debug "PnPDeviceID: " + Output$ Debug "--------------------------------------------------" ;SetMTPDirectory(1, "\Internal Storage\DCIM\100APPLE", @ErrorOutput$) If ExamineMTPDirectory(1, @ErrorOutput$) While NextMTPDirectoryEntry(1, @ErrorOutput$) MTPDirectoryEntryName(1, @Output$, @ErrorOutput$) If MTPDirectoryEntryType(1, @ErrorOutput$) = #PBEx_MTP_Type_Directory Debug "Folder: " + Output$ ElseIf MTPDirectoryEntryType(1, @ErrorOutput$) = #PBEx_MTP_Type_File Debug "File: " + Output$ Debug Str(MTPDirectoryEntrySize(1, @ErrorOutput$)) + " Bytes" Debug FormatDate("%dd.%mm.%yyyy %hh:%ii:%ss", MTPDirectoryEntryDate(1, @ErrorOutput$)) EndIf Wend EndIf CloseMTP(1, @ErrorOutput$) Else Debug ErrorOutput$ EndIf CloseLibrary(PBEx_MTP)
- Syntax:
Code: Select all
Result = CloseMTP(ID, @ErrorOutput$)
- Description: Closes the connection to the device.
- Parameter:
- ID: The number connection.
- @ErrorOutput$: If an error occurred, the error message is stored in the variable. This variable must be reserved with 128 characters before passing. Maximum return length is 128 characters including the NULL character. If no error description is to be returned for an error, 0 can be passed instead.
- Return value:
- 1: The process was successful.
- Syntax:
Code: Select all
Result = IsMTP(ID, @ErrorOutput$)
- Description: Checks if the connection is still valid.
- Parameter:
- ID: The number connection.
- @ErrorOutput$: If an error occurred, the error message is stored in the variable. This variable must be reserved with 128 characters before passing. Maximum return length is 128 characters including the NULL character. If no error description is to be returned for an error, 0 can be passed instead.
- Return value:
- 1: ID is valid.
- Syntax:
Code: Select all
Result = ExamineMTPDirectory(ID, @ErrorOutput$)
- Description: Starts the listing of all directories and files.
- Parameter:
- ID: The number connection.
- @ErrorOutput$: If an error occurred, the error message is stored in the variable. This variable must be reserved with 128 characters before passing. Maximum return length is 128 characters including the NULL character. If no error description is to be returned for an error, 0 can be passed instead.
- Return value:
- 1: The process was successful.
- Syntax:
Code: Select all
Result = FinishMTPDirectory(ID, @ErrorOutput$)
- Description: Closes the list of directories and files. This function is only valid within the ExamineMTPDirectory loop.
- Parameter:
- ID: The number connection.
- @ErrorOutput$: If an error occurred, the error message is stored in the variable. This variable must be reserved with 128 characters before passing. Maximum return length is 128 characters including the NULL character. If no error description is to be returned for an error, 0 can be passed instead.
- Return value:
- 1: The process was successful.
- Syntax:
Code: Select all
Result = NextMTPDirectoryEntry(ID, @ErrorOutput$)
- Description: The next directory or file is determined. This function is only valid within the ExamineMTPDirectory loop.
- Parameter:
- ID: The number connection.
- @ErrorOutput$: If an error occurred, the error message is stored in the variable. This variable must be reserved with 128 characters before passing. Maximum return length is 128 characters including the NULL character. If no error description is to be returned for an error, 0 can be passed instead.
- Return value:
- 1: The process was successful.
- Syntax:
Code: Select all
Result = MTPDirectoryEntryName(ID, @Output$, @ErrorOutput$)
- Description: The name of the directory or file is determined. This function is only valid within the ExamineMTPDirectory loop.
- Parameter:
- ID: The number connection.
- @Output$: The name of the directory or file is stored in this variable.
- @ErrorOutput$: If an error occurred, the error message is stored in the variable. This variable must be reserved with 128 characters before passing. Maximum return length is 128 characters including the NULL character. If no error description is to be returned for an error, 0 can be passed instead.
- Return value:
- 1: The process was successful.
- Syntax:
Code: Select all
Result = SetMTPDirectory(ID, DirectoryPath$, @ErrorOutput$)
- Description: Changes the current directory using the path. If empty, the root directory is selected.
- Parameter:
- ID: The number connection.
- DirectoryPath$: Path to the directory.
- @ErrorOutput$: If an error occurred, the error message is stored in the variable. This variable must be reserved with 128 characters before passing. Maximum return length is 128 characters including the NULL character. If no error description is to be returned for an error, 0 can be passed instead.
- Return value:
- 1: The process was successful.
- Syntax:
Code: Select all
Result = GetMTPDirectory(ID, @Output$, @ErrorOutput$)
- Description: Determines the current directory.
- Parameter:
- ID: The number connection.
- @Output$: The path of the current directory is stored in this variable.
- @ErrorOutput$: If an error occurred, the error message is stored in the variable. This variable must be reserved with 128 characters before passing. Maximum return length is 128 characters including the NULL character. If no error description is to be returned for an error, 0 can be passed instead.
- Return value:
- 1: The process was successful.
- Syntax:
Code: Select all
Result = MTPDirectoryEntryType(ID, @ErrorOutput$)
- Description: Determines the type of the current entry. This function is only valid within the ExamineMTPDirectory loop.
- Parameter:
- ID: The number connection.
- @ErrorOutput$: If an error occurred, the error message is stored in the variable. This variable must be reserved with 128 characters before passing. Maximum return length is 128 characters including the NULL character. If no error description is to be returned for an error, 0 can be passed instead.
- Return value: The following constants can be queried:
- #PBEx_MTP_Type_File: The entry is a file.
- #PBEx_MTP_Type_Directory: The entry is a directory.
- Syntax:
Code: Select all
Result = ReceiveMTPFile(ID, RemoteFileName$, FileName$, @ErrorOutput$)
- Description: Copies the specified file to the hard disk using the path.
- Parameter:
- ID: The number connection.
- RemoteFileName$: Complete path including file name of the file to be copied.
- FileName$: Complete target path incl. file name where the file should be copied to.
- @ErrorOutput$: If an error occurred, the error message is stored in the variable. This variable must be reserved with 128 characters before passing. Maximum return length is 128 characters including the NULL character. If no error description is to be returned for an error, 0 can be passed instead.
- Return value:
- 1: The process was successful.
- Syntax:
Code: Select all
Result = MTPDirectoryEntrySize(ID, @ErrorOutput$)
- Description: Determines the file size. This function is only valid within the ExamineMTPDirectory loop.
- Parameter:
- ID: The number connection.
- @ErrorOutput$: If an error occurred, the error message is stored in the variable. This variable must be reserved with 128 characters before passing. Maximum return length is 128 characters including the NULL character. If no error description is to be returned for an error, 0 can be passed instead.
- Return value: The size of the file in bytes.
- Syntax:
Code: Select all
Result = MTPDirectoryEntryDate(ID, @ErrorOutput$)
- Description: Determines the creation date of the file. This function is only valid within the ExamineMTPDirectory loop.
- Parameter:
- ID: The number connection.
- @ErrorOutput$: If an error occurred, the error message is stored in the variable. This variable must be reserved with 128 characters before passing. Maximum return length is 128 characters including the NULL character. If no error description is to be returned for an error, 0 can be passed instead.
- Return value: Value of the creation date. The value can be used with the date library.
- Syntax:
Code: Select all
Result = GetMTPDescription(ID, @Output$, @ErrorOutput$)
- Description: Determines the device description.
- Parameter:
- ID: The number connection.
- @Output$: The device description is stored in this variable.
- @ErrorOutput$: If an error occurred, the error message is stored in the variable. This variable must be reserved with 128 characters before passing. Maximum return length is 128 characters including the NULL character. If no error description is to be returned for an error, 0 can be passed instead.
- Return value:
- 1: The process was successful.
- Syntax:
Code: Select all
Result = GetMTPDeviceID(ID, @Output$, @ErrorOutput$)
- Description: Determines the device ID.
- Parameter:
- ID: The number connection.
- @Output$: The device ID is stored in this variable.
- @ErrorOutput$: If an error occurred, the error message is stored in the variable. This variable must be reserved with 128 characters before passing. Maximum return length is 128 characters including the NULL character. If no error description is to be returned for an error, 0 can be passed instead.
- Return value:
- 1: The process was successful.
- Syntax:
Code: Select all
Result = GetMTPDeviceType(ID, @ErrorOutput$)
- Description: Determines the type of the device.
- Parameter:
- ID: The number connection.
- @ErrorOutput$: If an error occurred, the error message is stored in the variable. This variable must be reserved with 128 characters before passing. Maximum return length is 128 characters including the NULL character. If no error description is to be returned for an error, 0 can be passed instead.
- Return value: The following constants can be queried:
- #PBEx_MTP_DeviceType_Generic
- #PBEx_MTP_DeviceType_Camera
- #PBEx_MTP_DeviceType_MediaPlayer
- #PBEx_MTP_DeviceType_Phone
- #PBEx_MTP_DeviceType_Video
- #PBEx_MTP_DeviceType_PersonalInformationManager
- #PBEx_MTP_DeviceType_AudioRecorder
- Syntax:
Code: Select all
Result = GetMTPFirmwareVersion(ID, @Output$, @ErrorOutput$)
- Description: Determines the firmware version.
- Parameter:
- ID: The number connection.
- @Output$: The firmware version is stored in this variable.
- @ErrorOutput$: If an error occurred, the error message is stored in the variable. This variable must be reserved with 128 characters before passing. Maximum return length is 128 characters including the NULL character. If no error description is to be returned for an error, 0 can be passed instead.
- Return value:
- 1: The process was successful.
- Syntax:
Code: Select all
Result = GetMTPFriendlyName(ID, @Output$, @ErrorOutput$)
- Description: Determines the device name.
- Parameter:
- ID: The number connection.
- @Output$: The device name is stored in this variable.
- @ErrorOutput$: If an error occurred, the error message is stored in the variable. This variable must be reserved with 128 characters before passing. Maximum return length is 128 characters including the NULL character. If no error description is to be returned for an error, 0 can be passed instead.
- Return value:
- 1: The process was successful.
- Syntax:
Code: Select all
Result = GetMTPManufacturer(ID, @Output$, @ErrorOutput$)
- Description: Determines the manufacturer.
- Parameter:
- ID: The number connection.
- @Output$: The manufacturer is stored in this variable.
- @ErrorOutput$: If an error occurred, the error message is stored in the variable. This variable must be reserved with 128 characters before passing. Maximum return length is 128 characters including the NULL character. If no error description is to be returned for an error, 0 can be passed instead.
- Return value:
- 1: The process was successful.
- Syntax:
Code: Select all
Result = GetMTPModel(ID, @Output$, @ErrorOutput$)
- Description: Determines the model name.
- Parameter:
- ID: The number connection.
- @Output$: The model name is stored in this variable.
- @ErrorOutput$: If an error occurred, the error message is stored in the variable. This variable must be reserved with 128 characters before passing. Maximum return length is 128 characters including the NULL character. If no error description is to be returned for an error, 0 can be passed instead.
- Return value:
- 1: The process was successful.
- Syntax:
Code: Select all
Result = GetMTPPnPDeviceID(ID, @Output$, @ErrorOutput$)
- Description: Determines the PnP device ID. (Plug and Play)
- Parameter:
- ID: The number connection.
- @Output$: The PnP Device ID is stored in this variable.
- @ErrorOutput$: If an error occurred, the error message is stored in the variable. This variable must be reserved with 128 characters before passing. Maximum return length is 128 characters including the NULL character. If no error description is to be returned for an error, 0 can be passed instead.
- Return value:
- 1: The process was successful.
- Syntax:
Code: Select all
Result = GetMTPSerialNumber(ID, @Output$, @ErrorOutput$)
- Description: Determines the serial number.
- Parameter:
- ID: The number connection.
- @Output$: The serial number is stored in this variable.
- @ErrorOutput$: If an error occurred, the error message is stored in the variable. This variable must be reserved with 128 characters before passing. Maximum return length is 128 characters including the NULL character. If no error description is to be returned for an error, 0 can be passed instead.
- Return value:
- 1: The process was successful.
- Syntax:
- Windows Vista or higher
- .NET Framework 4.5 or higher
- Unicode activation (default from PB 5.50)
This library is based on: https://github.com/Bassman2/MediaDevices
Download: https://www.rsbasic.de/downloads/downlo ... Ex_MTP.zip
I would be very pleased about feedbacks, improvement suggestions, error messages or wishes. If you want to support me, you can also donate something. Thanks