I am trying to use RAPI to copy a file in VB6. Here is the code that I have:

RAPI Module
----------------------------------------
Type RAPIINIT
cbsize As Long
heRapiInit As Long
hrRapiInit As Long
End Type

Public Declare Function CeRapiUninit Lib "rapi.dll" () As Long

Public Declare Function CeGetLastError Lib "rapi.dll" () As Long

Public Declare Function CeRapiGetError Lib "rapi.dll" () As Long

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

Public Declare Function CeRapiInitEx Lib "rapi.dll" ( _
pRapiInit As RAPIINIT) As Long


' Initialize RAPI
Public Function ConnectRapi() As Long
Dim lcon As Long
Dim lRapiInit As RAPIINIT

With lRapiInit
.cbsize = Len(lRapiInit)
.heRapiInit = 0
.hrRapiInit = 0
End With

lcon = CeRapiInitEx(lRapiInit)
ConnectRapi = lcon
End Function

' Uninitialize RAPI
Public Function DisconnectRapi() As Long
Dim lcon As Long
lcon = CeRapiUninit
DisconnectRapi = lcon
End Function



button
------------------------------
Private Sub Command1_Click()

Dim success As Boolean
Dim lconn As Long
Dim x, y, z As String
Dim r as Long

lconn = ConnectRapi
z = CeRapiGetError

x = "\Program Files\Test PPC\1202030002.txt"
y = "D:\1202030002.txt"

r = CeCopyFile(VarPtr(x), VarPtr(y), True)
z = CeRapiGetError
lconn = DisconnectRapi

End Sub

In the button's click event, lconn, r and z are both 0 the whole time. It says that lconn should be 0 if there is a good connection. However, r should contain a non 0 value if the function worked. When I call CERAPIGetError, it returns a 0. Any ideas why this isn't working or another way I can copy a file with VB6? Thanks for the help.

Here are my sources:
connection code:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;306368

CeCopyFile
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wcesdkr/html/_wcesdk_CeCopyFile_RAPI_.asp

Re: CeCopyFile in VB6 by The

The
Thu Jun 17 00:52:08 CDT 2004

> I am trying to use RAPI to copy a file in VB6. Here is the code that I
have:
>
> RAPI Module
> ----------------------------------------
> Type RAPIINIT
> cbsize As Long
> heRapiInit As Long
> hrRapiInit As Long
> End Type
>
> Public Declare Function CeRapiUninit Lib "rapi.dll" () As Long
>
> Public Declare Function CeGetLastError Lib "rapi.dll" () As Long
>
> Public Declare Function CeRapiGetError Lib "rapi.dll" () As Long
>
> Public Declare Function CeCopyFile Lib "rapi.dll" (CurrentPath As Long,
NewPath As Long, Overwrite As Boolean) As Long

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


> Public Declare Function CeRapiInitEx Lib "rapi.dll" ( _
> pRapiInit As RAPIINIT) As Long
>
>
> ' Initialize RAPI
> Public Function ConnectRapi() As Long
> Dim lcon As Long
> Dim lRapiInit As RAPIINIT
>
> With lRapiInit
> .cbsize = Len(lRapiInit)
> .heRapiInit = 0
> .hrRapiInit = 0
> End With
>
> lcon = CeRapiInitEx(lRapiInit)
> ConnectRapi = lcon
> End Function
>
> ' Uninitialize RAPI
> Public Function DisconnectRapi() As Long
> Dim lcon As Long
> lcon = CeRapiUninit
> DisconnectRapi = lcon
> End Function
>
>
>
> button
> ------------------------------
> Private Sub Command1_Click()
>
> Dim success As Boolean
> Dim lconn As Long
> Dim x, y, z As String
> Dim r as Long
>
> lconn = ConnectRapi
> z = CeRapiGetError
>
> x = "\Program Files\Test PPC\1202030002.txt"
> y = "D:\1202030002.txt"
>
> r = CeCopyFile(VarPtr(x), VarPtr(y), True)

r = CeCopyFile(x, y, True)

> z = CeRapiGetError
> lconn = DisconnectRapi
>
> End Sub
>
> In the button's click event, lconn, r and z are both 0 the whole time. It
says that lconn should be 0 if there is a good connection. However, r should
contain a non 0 value if the function worked. When I call CERAPIGetError, it
returns a 0. Any ideas why this isn't working

Yes. Your declaration of CeCopyFile is wrong. The declaration:

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

would have worked, as you coded it with VarPtrs. But by method is simpler.



Re: CeCopyFile in VB6 by David

David
Fri Jun 18 12:37:09 CDT 2004

You are calling CeRapiInitEx incorrectly -- as does the Microsoft KB
article. You should wait on the HE event, per the Pocket PC SDK. If you
don't wait, in some conditions it works, but not in others.

A corrected function is in this newsgroup under:

Can I use RAPI in vb 6.0?
news:OUP$DiWKEHA.624@TK2MSFTNGP11.phx.gbl...

Look for "UPDATED FUNCTION".

David
------
This posting is provided "AS IS" with no warranties, and confers no rights.

"Jonathan" <Jonathan@discussions.microsoft.com> wrote in message
news:C458B14B-34CF-4427-AA7E-035C01ABF8C6@microsoft.com...
> I am trying to use RAPI to copy a file in VB6. Here is the code that I
have:
>
> ' Initialize RAPI
> Public Function ConnectRapi() As Long
> Dim lcon As Long
> Dim lRapiInit As RAPIINIT
>
> With lRapiInit
> .cbsize = Len(lRapiInit)
> .heRapiInit = 0
> .hrRapiInit = 0
> End With
>
> lcon = CeRapiInitEx(lRapiInit)
> ConnectRapi = lcon
> End Function
>
> In the button's click event, lconn, r and z are both 0 the whole time. It
says that lconn should be 0 if there is a good connection. However, r should
contain a non 0 value if the function worked. When I call CERAPIGetError, it
returns a 0. Any ideas why this isn't working or another way I can copy a
file with VB6? Thanks for the help.
>
> Here are my sources:
> connection code:
> http://support.microsoft.com/default.aspx?scid=kb;EN-US;306368
>
> CeCopyFile
>
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wcesdkr/html/_wcesdk_CeCopyFile_RAPI_.asp