Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems with creating/copying files to pocket pc.

Status
Not open for further replies.

smrtelnik

Programmer
Apr 6, 2005
6
SK
Greetings to all.
I have big problem. I need to send some files from my application on desktop PC to POCKET PC (with Windows CE5).
I try to use rapi.dll, but I don't know how. This is code, I found here on Tek-Tips:

#DEFINE GENERIC_READ 0x80000000
#DEFINE FILE_ATTRIBUTE_NORMAL 0x00000080
#DEFINE GENERIC_WRITE 0x40000000
#define CREATE_ALWAYS 2

hnd=CeCreateFile('My Documents\test.txt')
if hnd<>-1
?cewritefile(hnd,"Hello Windows CE!!")
?ceCloseHandle(hnd)
else
return
endif


* Api function wrappers follow:
FUNCTION CeCreateFile( pcName )
DECLARE LONG CeCreateFile IN RAPI.DLL AS _ceCreateFile ;
STRING @ LPCTSTR_lpFileName, ;
LONG DWORD_dwDesiredAccess, ;
LONG DWORD_dwShareMode, ;
LONG Ignored_LPSECURITY_ATTRIBUTES_lpSecurityAttributes, ;
LONG DWORD_dwCreationDispostion, ;
LONG DWORD_dwFlagsAndAttributes, ;
LONG Ignored_HANDLE_hTemplateFile
LOCAL lnHnd, lcStr
lcStr = StringToUnicode(pcName)
lnHnd = _ceCreateFile( @lcStr, BitOr(GENERIC_READ,GENERIC_WRITE), ;
0,0,CREATE_ALWAYS,0,0 )
RETURN lnHnd
ENDFUNC
FUNCTION CeCloseHandle( pnHnd )
DECLARE LONG CeCloseHandle IN RAPI.DLL AS _ceCloseHandle ;
LONG nHnd
RETURN _ceCloseHandle(pnHnd)=1
ENDFUNC
FUNCTION CeWriteFile( pnHnd, pcStr )
DECLARE LONG CeWriteFile IN RAPI.DLL AS _ceWriteFile ;
LONG HANDLE_hFile, ;
STRING @ LPCVOID_lpBuffer, ;
LONG DWORD_nNumberOfBytesToWrite, ;
LONG @ LPDWORD_lpNumberOfBytesWritten, ;
LONG Ignored_LPOVERLAPPED_lpOverlapped
LOCAL lnWritten
lnWritten = 0
_ceWriteFile( pnHnd, @pcStr, len(pcStr), @lnWritten, 0 )
RETURN lnWritten
ENDFUNC
PROCEDURE UnicodeToString( pcStr )
LOCAL lcSkel
lcSkel = StrConv( pcStr, 6 ) && Double Byte <- Unicode
lcSkel = StrConv( lcSkel, 2 ) && Single byte <- Double Byte
RETURN LEFT(lcSkel, MAX(AT(chr(0),lcSkel)-1,0) )
ENDPROC
PROCEDURE StringToUnicode( pcStr )
LOCAL lcSkel
lcSkel = StrConv( pcStr, 1 ) && Single byte -> Double Byte
lcSkel = StrConv( lcSkel, 5 ) && Double Byte -> Unicode
RETURN lcSkel+chr(0)
ENDPROC

But function cecreatefile returns handle -1.
Don't you know, where is problem?
Thanks for all answers.

Brano Ondrejka

P.S.: I have ActiveSync 4.2 on my desktop PC.
 
Is this a VFP question?

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
Yes, it is. If you see, the code is VFP. My desktop application is made in VFP.
 
OK, it didn't strike me as obviously VFP code... sorry!

Are you running this code on a CE machine?

Which version of VFP are you using?



Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
Ok.
No, I run this code on my desktop PC. I need to send some files to CE PC.
I'm using VFP 9.0 SP2.
 
Brano,

Although your code is VFP, and you are calling Rapi.DLL from a VFP application, your problem really relates to Rapi.DLL itself.

For that reason, it might be a good idea to also post it in a forum directly related to this DLL, or perhaps to ActiveSync. After all, it's the DLL that's returning an error indication. (But keep it here as well; you might get a reply from one of the knowledgeable folk in this forum.)

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Well, I'm not familiar with the .dll you are using, but is the code perhaps creating the file you want locally - in your own "my documents" folder?

I don't see any initialisation code or redirection that
would take the output to any specific CE device...



Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
Mike, thanks.
Here are so many forums, i must find the right one for my problem.

Griff, my code creates a file in CE PC, and then tryes to write some text/content from local file on my desktop PC to that file.
 
Hi Brano

I had worked that much out, but it seems (from what you are saying) that it fails on the 'create' part of that equation.
Because a non -1 value in hnd would result in something being written to the file (presumably).

I would look at the actual value in hnd and see if the documentation for the .dll gives you any clue as to what the problem might be based on that value - for example a value of 4 MIGHT mean the file is open, a 3 MIGHT mean the folder does not exist.

I made those two values up (3 and 4) only the documentation for rapi.dll will tell you if such codes exist and their meaning.



Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
Have you tried using CeCopyFile?

Some of these snippets may help:
Code:
DECLARE INTEGER CeCopyFile IN rapi;
    STRING lpExistingFileName, STRING lpNewFileName,;
    INTEGER bFailIfExists

DECLARE INTEGER CeGetLastError IN rapi

FUNCTION CopyFile(cSourceName, cTargetName) As Boolean
    IF CeCopyFile(m.ToUnicode(cSourceName),;
        ToUnicode(m.cTargetName), 0) = 0
        THIS.errorcode=CeGetLastError()
        RETURN .F.
    ENDIF
RETURN .T.

FUNCTION ToUnicode(cStr)
RETURN STRCONV(cStr+CHR(0), 5)


-Dave Summers-
[cheers]
Even more Fox stuff at:
 
Dave, thanks. I tried your code, but it didn't worked. Function always returns 0. So it fails. I don't know, where is the mistake.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top