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