可以在Windows中使用CreateFile以编程方式从iPhone读取图像吗?

iPhone连接到Win7计算机时,可以使用资源pipe理器(和我的应用程序的打开文件对话框)查看图像。 但是,文件位置不包含驱动器号。

例如Computer\Apple iPhone\Internal Storage\DCIM\800AAAAA\IMG_0008.JPG而不是E:\DCIM\800AAAAA\IMG_0008.JPG这是常见的SD卡,USB驱动器等…

我试过使用CreateFileW从iPhone读取图像,但它失败,'(错误代码:3)系统找不到指定的path。 我也试着用Chrome访问它们,但也失败了。

有什么build议么?

Solutions Collecting From Web of "可以在Windows中使用CreateFile以编程方式从iPhone读取图像吗?"

该文件夹实际上被称为“虚拟文件夹”,并且在文件系统上没有完整的路径。 您需要使用从打开的对话框返回的shell项来获取文件的内容,而不是使用CreateFile。

数据应该是可访问的,但是您应该遵循MSDN文档中的说明 。 我敢肯定,可能有更好的例子(因为这只是给出了指导方针)。

编辑粗略的过程是从IFileOpenDialog获取IShellItem,然后绑定到流,然后读取流(假设只读) – 请记住,这个代码几乎没有错误处理或检查或安全性:

 if (pitem->GetDisplayName(SIGDN_NORMALDISPLAY, &destName) == S_OK) { std::cout << destName << std::endl; CoTaskMemFree(destName); } IStream *pistream; if (pitem->BindToHandler(0, BHID_Stream, IID_PPV_ARGS(&pistream)) == S_OK) { char input[1024]; long to_read = 1024; unsigned long read; while (S_OK == pistream->Read(input, to_read, &read)) { std::cout << input << std::endl; } pistream->Release(); } pitem->Release(); 

大多数情况下,这样的设备作为Shell命名空间扩展插入到Windows资源管理器中,而不是像驱动器号的USB盘。 像CopyFile(..),FindFirst()或GetFileInfo(..)等大多数正常的文件命令不能直接在这样的Shell命名空间扩展中使用。 只有CopyHere(..)正在工作。 我需要很长时间来弄清楚如何枚举数码相机上的文件,现在也使用vb.net程序在Android设备上,并将我的照片复制到Windows PC上:

 Public Const MyComputer As Integer = &H11& Sub EnumMyComputer() Dim oItem As Object Dim res As Integer For Each oItem In DirectCast(CreateObject("Shell.Application").Namespace(MyComputer).Items, System.Collections.IEnumerable) Debug.Print(oItem.Type.ToString) if oItem.Type.ToString="Tragbares Medienwiedergabegerät" then '<- check, adopt! res = EnumNamespaceItems(oItem, "", oItem.Name.ToString, 0) End If Next oItem End Sub Function EnumNamespaceItems(oItem As Object, SrcCPath As String, SrcDPath As String, folderLevel As Integer) As Integer Dim y As Object Dim tempFullFileName As String Debug.Print(StrDup(folderLevel, " ") & "\" & oItem.Name.ToString & " (" & oItem.Path.ToString & ")") For Each y In DirectCast(oItem.GetFolder.items, System.Collections.IEnumerable) 'Debug.Print(StrDup(folderLevel, " ") & SrcDPath & y.Name.ToString) If y.IsFolder = True Then Dim n1 As Integer n1 = EnumNamespaceItems(y, SrcCPath & y.Path.ToString & "\", SrcDPath & y.Name.ToString & "\", 1 + folderLevel) If n1 < 0 Then 'failure: Cancel EnumNamespaceItems = n1 Exit Function End If Else 'it's a file: Debug.Print(StrDup(folderLevel, " ") & " " & y.Name.ToString) tempFullFileName = System.IO.Path.GetTempPath() & y.Name.ToString ' CopyFile is not possible here if SrcCPath is like "::{…}…": ' My.Computer.FileSystem.CopyFile(SrcCPath & y.Name.ToString , fFile.FullName) Dim suc As Integer = CopyHereFileWait(y, My.Computer.FileSystem.SpecialDirectories.Temp) If suc >= 0 Then 'now we can do things like this: Dim MyFileInfo As System.IO.FileInfo = My.Computer.FileSystem.GetFileInfo(tempFullFileName) Dim fileDate As Date = MyFileInfo.LastWriteTime End If 'suc End If 'else y.IsFolder Next y EnumNamespaceItems = 0 End Function Function CopyHereFileWait(sourceNamespaceObject As Object, targetFolder As String) As Integer Dim fsMyStream As System.IO.FileStream Dim n1 As Integer Dim taregetFullFileName As String n1 = Len(targetFolder) If Mid(targetFolder, n1, 1) = "\" Then targetFolder = Microsoft.VisualBasic.Left(targetFolder, n1 - 1) End If taregetFullFileName = targetFolder & "\" & sourceNamespaceObject.Name.ToString Dim oNsTargetFolder As Object oNsTargetFolder = CreateObject("Shell.Application").Namespace(CStr(targetFolder)) oNsTargetFolder.copyHere(sourceNamespaceObject) 'returns immediately and is doing the work in the background n1 = 0 Do Threading.Thread.Sleep(50) 'ms Try fsMyStream = System.IO.File.Open(taregetFullFileName, IO.FileMode.Open, IO.FileAccess.ReadWrite) fsMyStream.Close() CopyHereFileWait = n1 Exit Function Catch ex As Exception Debug.Print(ex.Message) End Try n1 = n1 + 1 Loop While n1 < 400 'timeout 400*50ms = 20s CopyHereFileWait = -n1 End Function 

您可以添加检查文件夹与y.Name.ToString =“DCIM”(在folderLevel = 1)和文件与“.jpg”。