Paul G. Tobey [eMVP] avait soumis l'idée :
Show the code. We don't know what path you're trying to use to create
the file, for example...
Paul T.
HI,
I developped a VB 6.0 application to copy a files from PC to PocketPC.
I'm inspired by the source code on
http://www.devbuzz.com/Archived/zinc_eVB_copy_files_to_device_II_pg1.aspx
This application runs well on a lot of Mobile device from many years,
but on one device (PSION Workabout running under WM2003) I've got an
invalide handle when calling CECreateFile, and the CeGetLastError
returns 0.
I don't know where is the problem with this PSION
Any idea ???
Here is the code :
Public Function CopyFileToPocketPC(ptxtPPCFile As String,
ptxtDesktopFile As String) As Boolean
Dim bytBuffer(8388607) As Byte
Dim lngFileHandle As Long
Dim lngDestinationHandle As Long
Dim lngNumBytesWritten As Long
Dim filename As String
Dim typFindFileData As CE_FIND_DATA
Dim lngFileSize As Long
'On Error GoTo ErrHandler
'locate the file, and see if it already exists on the device
lngFileHandle = CeFindFirstFile(ptxtPPCFile, typFindFileData)
'if we get -1 then the file wasn't found so we can go ahead and create
it
'otherwise we dont want to overwrite in this demo, so we will cancel the
operation.
If lngFileHandle <> INVALID_HANDLE Then
'MsgBox txtPPCFile & " already exists. Operation Cancelled."
CeFindClose lngFileHandle
CopyFileToPocketPC = False
End If
'create the file on the device, and return the handle to the file
filename = ptxtPPCFile
lngDestinationHandle = CeCreateFile(filename, GENERIC_WRITE,
FILE_SHARE_READ, vbNullString, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0)
'if something went wrong in CeCreateFile we will get -1, and therefore
need to abort
If lngDestinationHandle = INVALID_HANDLE Then
MsgBox "CeCreateFile Error " & CeGetLastError & " occurred.",
vbCritical & vbOKOnly
CopyFileToPocketPC = False
CeCloseHandle lngDestinationHandle
Exit Function
End If
'Call function to read file on the desktop into the byte buffer
If ReadFileAsBinary(ptxtDesktopFile, lngFileSize, bytBuffer()) = True
Then
'Write contents of Binary buffer to CE file.
'Return value of 0 = failure, non zero = success
intRetVal = CeWriteFile(lngDestinationHandle, bytBuffer(0), lngFileSize,
lngNumBytesWritten, 0)
If intRetVal = WRITE_ERROR Then
GoTo ErrHandler
End If
End If
CeCloseHandle lngDestinationHandle
CopyFileToPocketPC = True
Exit Function
ErrHandler:
MsgBox "Error " & CeGetLastError & " Occurred When Copying File " & _
ptxtDesktopFile & " To The Device as " & ptxtPPCFile, vbCritical &
vbOKOnly
If lngDestinationHandle Or lngDestinationHandle <> INVALID_HANDLE Then
CeCloseHandle lngDestinationHandle
End If
CopyFileToPocketPC = False
End Function
The function is called, for example,
CopyFileToPocketPC("\Temp\toto.txt","C:\Temp\toto.txt")