CECreateFile invalide handle

A

Amirallia

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 ???
 
P

Paul G. Tobey [eMVP]

Show the code. We don't know what path you're trying to use to create the
file, for example...

Paul T.
 
A

Amirallia

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.

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")
 
P

Paul G. Tobey [eMVP]

And is there a \temp folder on the device? Can you, using the user
interface on the device, create a file there? I don't think there's any
requirement that every device have such a folder.

Paul T.

Amirallia said:
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.

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")
 
A

Amirallia

Paul G. Tobey [eMVP] a couché sur son écran :
And is there a \temp folder on the device? Can you, using the user interface
on the device, create a file there? I don't think there's any requirement
that every device have such a folder.

Paul T.

Amirallia said:
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")

Yes I can explorer my temp folder and copy files.

With an another mobile device(iPaq) it'ok but with an another(Psion
workabout), I 've got the error on CECreateFile

Where is the difference between this two devices?
 
P

Paul G. Tobey [eMVP]

You'd have to ask the device manufacturer to tell you, specifically, what's
different. In this case, if the Workabout *is* a Windows Mobile device, as
opposed to a Windows CE device, I can't explain the difference and you'll
*have* to talk to Psion about what's going on. My best guess would be a
problem with the path that you're specifying, whether that's a spelling
error in your code as compared with the device (maybe there's a space in the
name on one or the other, your filename matches a read-only file that
already exists in the folder, etc.), or some special functionality of the
folder on the Psion...

Paul T.

Amirallia said:
Paul G. Tobey [eMVP] a couché sur son écran :
And is there a \temp folder on the device? Can you, using the user
interface on the device, create a file there? I don't think there's any
requirement that every device have such a folder.

Paul T.

Amirallia said:
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")

Yes I can explorer my temp folder and copy files.

With an another mobile device(iPaq) it'ok but with an another(Psion
workabout), I 've got the error on CECreateFile

Where is the difference between this two devices?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top