Firstly, sorry if this is in the wrong area, but this seemed to be the more
active area.

I have searched everywhere, both here and via google for an answer on how to
use the CeCopyFile function in VB but I can not find the answer I am looking
for.

I have an Access database I use to push and pull files to and from the PDA to
a network server using the functions as provided by Microsoft that everyone
seems to use. This works fantastic as I use a table to define the files and
paths to complete the transfer of the data to and from.

I was asked the other day if I could backup the files on the PDA to itself
prior to a transfer of the files from the PDA to the network as a means of
safe guarding the data a little more. After a quick google search it appears
the CeCopyFile is the way to go and I realise that this only copies files
from one location on the PDA to another, which is exactly what i want.

The problem is that i do not know how to implement the code in Access to get
it to work!

I have the following code at the moment

<CODE>
Public Declare Function CeCopyFile Lib "rapi.dll" ( _
ByVal CurrentPath As String, _
ByVal NewPath As String, _
ByVal Overwrite As Boolean) As Long
</CODE>

I use this funtion in a custom function to pass the variables

<CODE>
Public Function buFiles(sOLoc As String, sDLoc As String, bFailIfExists As
Boolean)

'bFailIfExists = True if you DO NOT want to overwrite!

If Not RapiIsConnected Then
MsgBox "Device is not connected. Please connect first."
Exit Function
End If

'Do the file copy
Dim lBU As Long

lBU = CeCopyFile(sOLoc, sDLoc, bFailIfExists)

'Check CeGetLastError
Dim lLastError As Long
If lBU = False Then
lLastError = CeGetLastError()
End If

Select Case lLastError
Case ERROR_FILE_EXISTS
MsgBox "A file already exists with the specified name."
Case ERROR_INVALID_PARAMETER
MsgBox "A parameter was invalid."
Case ERROR_DISK_FULL
MsgBox "Disk if Full."
Case 32
MsgBox "File access error. It is possible that Arcpad in your
mobile device is still running." & vbCrLf & "Please close the Arcpad in the
mobile device and try again."
Case Else
MsgBox "An unknown error occured."
End Select

End Function
</CODE>

When I run this function ( ?buFiles("\Temp\CannedText.txt", "\Temp\BU\
CannedText.txt", False) ) in the Immediate Window (Ctrl + G) it gives me an
error message where the error number is '2' which when looking at the RAPI
documentation relates to a "Can not find file location" error.

Can someone please point me in the right direction as to why it can not find
the location on the PDA or where else I might not be calling the function
correctly.

Cheers

Dave - inf3rno

Re: CeCopyFile - VB in MS Access by Scott

Scott
Fri Jul 04 03:25:17 CDT 2008

"inf3rno" <u44664@uwe> wrote:
>
>I have searched everywhere, both here and via google for an answer on
>how to use the CeCopyFile function in VB but I can not find the answer
>I am looking for.

Because CeCopyFile is a Unicode only API (like all of the RAPI
functions), you can't use "ByVal foo As String" in your API declaration
in VB, since this tells VB to use an Ascii string. It's been a while
since I've dealt with VB, but if I recall correctly, something like this
should do the trick:

Public Declare Function CeCopyFile Lib "rapi.dll" ( _
CurrentPath As Any, _
NewPath As Any, _
ByVal Overwrite As Boolean) As Long

Dim bCurrentPath() As Byte
Dim bNewPath() As Byte
bCurrentPath = sOldLoc
bNewPath = sNewLoc

CeCopyFile bCurrentPath(0), bNewPath(0), False


Also, make sure you're calling CeRapiInit() somewhere before calling
any of the other APIs.

--
--------- Scott Seligman <scott at <firstname> and michelle dot net> ---------
Democracy must be something more than two wolves and a sheep voting
on what to have for dinner.
-- James Bovard in Lost Rights: The Destruction of American Liberty

Re: CeCopyFile - VB in MS Access by inf3rno

inf3rno
Fri Jul 04 05:57:00 CDT 2008

Scott Seligman wrote:
>>I have searched everywhere, both here and via google for an answer on
>>how to use the CeCopyFile function in VB but I can not find the answer
>>I am looking for.
>
>Because CeCopyFile is a Unicode only API (like all of the RAPI
>functions), you can't use "ByVal foo As String" in your API declaration
>in VB, since this tells VB to use an Ascii string. It's been a while
>since I've dealt with VB, but if I recall correctly, something like this
>should do the trick:
>
>Public Declare Function CeCopyFile Lib "rapi.dll" ( _
> CurrentPath As Any, _
> NewPath As Any, _
> ByVal Overwrite As Boolean) As Long
>
>Dim bCurrentPath() As Byte
>Dim bNewPath() As Byte
>bCurrentPath = sOldLoc
>bNewPath = sNewLoc
>
>CeCopyFile bCurrentPath(0), bNewPath(0), False
>
>Also, make sure you're calling CeRapiInit() somewhere before calling
>any of the other APIs.
>

SCott,

Thanks for the quick reply however I am still not getting anywhere with this!

I am still getting the error number 2 when I use your code.

I have added in the initialising of the PDA i.e. CeRapiInit() and still no
luck!

I have also tested my existing functions to transfer files to and from the
PDa and they work fine.

Cheers

Dave


Re: CeCopyFile - VB in MS Access by inf3rno

inf3rno
Wed Jul 09 00:48:39 CDT 2008

I cracked it! CeCopyFile - VB - Example

The following code is what I have successfully implemented in VB in an Access
Database. Please use this as a worked example of how to implement CeCopyFile
via RAPI in VB.

<CODE>

Public Declare Function CeCopyFile Lib "rapi.dll" ( _
ByVal CurrentPath As String, _
ByVal NewPath As String, _
ByVal Overwrite As Boolean) As Long


Public Function buFiles(sOLoc As String, sDLoc As String, bFailIfExists As
Boolean)

'bFailIfExists = True if you DO NOT want to overwrite!
'Do the file copy
Dim lBU As Long
Dim lLastError As Long
Dim sError As String

Call RapiConnect

If Not RapiIsConnected Then
MsgBox "Device is not connected. Please connect first."
Exit Function
End If

'bFailIfExists fails to be passed via the function correctly thus the if
statement
'is used to deal with the overwriting of the existing file if it already
exists

If bFailIfExists = False Then
lBU = CeCopyFile(StrConv(sOLoc, vbUnicode), StrConv(sDLoc, vbUnicode),
False)
Else
lBU = CeCopyFile(StrConv(sOLoc, vbUnicode), StrConv(sDLoc, vbUnicode),
True)
End If

If lBU = False Then
lLastError = CeGetLastError()
'Debug.Print lLastError
Select Case lLastError
Case 1
sError = "Incorrect function"
Case 2
sError = "The system cannot find the file specified!"
Case 3
sError = "The system cannot find the path specified!"
Case 4
sError = "The system cannot open the file!"
Case 5
sError = "Access is denied"
Case 32
sError = "The process cannot access the file because it is being
used by another process!"
Case 80
sError = "The file already exists and may not be overwritten!"
Case Else
sError = "An unknown error occured."
End Select
MsgBox sError, vbCritical, "Error..."
End If

End Function

</CODE>

If anyone has any questions please reply!

Cheers

Dave

--
Message posted via PocketPCJunkies.com
http://www.pocketpcjunkies.com/Uwe/Forums.aspx/pocketpc-prog/200807/1


Re: CeCopyFile - VB in MS Access by r_z_aret

r_z_aret
Wed Jul 09 15:10:00 CDT 2008

On Fri, 04 Jul 2008 06:45:29 GMT, "inf3rno" <u44664@uwe> wrote:

>Firstly, sorry if this is in the wrong area, but this seemed to be the more
>active area.
>
>I have searched everywhere, both here and via google for an answer on how to
>use the CeCopyFile function in VB but I can not find the answer I am looking
>for.

I'm traveling and stuck with a slow connection this week, so I can't
check. But I'm sure one of the developer sites (probably
www.pocketpcdev.com) had info, including code, for using RAPI with VB.

-----------------------------------------
To reply to me, remove the underscores (_) from my email address (and please indicate which newsgroup and message).

Robert E. Zaret, eMVP
PenFact, Inc.
20 Park Plaza, Suite 478
Boston, MA 02116
www.penfact.com

Re: CeCopyFile - VB in MS Access by inf3rno

inf3rno
Wed Jul 09 17:16:38 CDT 2008

r_z_aret@pen_fact.com wrote:
>>Firstly, sorry if this is in the wrong area, but this seemed to be the more
>>active area.
>>
>>I have searched everywhere, both here and via google for an answer on how to
>>use the CeCopyFile function in VB but I can not find the answer I am looking
>>for.
>
>I'm traveling and stuck with a slow connection this week, so I can't
>check. But I'm sure one of the developer sites (probably
>www.pocketpcdev.com) had info, including code, for using RAPI with VB.
>
>-----------------------------------------
>To reply to me, remove the underscores (_) from my email address (and please indicate which newsgroup and message).
>
>Robert E. Zaret, eMVP
>PenFact, Inc.
>20 Park Plaza, Suite 478
>Boston, MA 02116
>www.penfact.com


Robert,

Yes, you are correct however the MSDN and pocketpcdev sites (they all have
the same slab of code) only have the code and functions to copy frm the PDA
to PC and vice versa with a few others thrown in. It did NOT include the
CeCopyFile function!

Cheers

Dave

--
Message posted via http://www.pocketpcjunkies.com