Log in

View Full Version : Copying files from PC to Pocket PC in C ->RAPI or ???


PeterPan
04-11-2004, 12:34 AM
Hi,

I am currently writing a Winamp (http://www.winamp.com) plugin to allow you to copy/sync files in the playlist with your PocketPC via ActiveSync. I have gotten about 80% of the Winamp side done but am now stuck on the PocketPC side of things. I have so far been able to connect to it and get the DeviceID & Name, but I seem to fall over in the file copying.

I am using RAPI, but read somewhere in this forum by Andy Sjostrom (http://www.pocketpcthoughts.com/forums/profile.php?mode=viewprofile&u=8) that this may not be the best way. Is there another?

Below are the snippets of code that are causing me the prb. The plugin DLL compiles successfully with no errors. I am using the 2 Message boxes to see where I getup to. The “Part1” messagebox shows, but not the “Part 2”, So I presume there is something wrong with my CeCreateFile


#define BUFFSIZE 8192

HANDLE hSrc, hDest;
char *SongSrc, *SongDst;
char SongTarget[MAX_PATH];
BOOL bSucceeded;

//open the desktop file for reading
hSrc=CreateFile(SongSrc, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
bSucceeded=(hSrc!=INVALID_HANDLE_VALUE);
if(bSucceeded)
{
LPCWSTR pwcsDeviceFile=(LPCWSTR)(LPCTSTR)SongDst;
//open the device file for writing
hDest=CeCreateFile(pwcsDeviceFile, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
bSucceeded=(hDest!=INVALID_HANDLE_VALUE);
MessageBox(cwp->hwnd, "Part1" , AppDes,0);

if(bSucceeded)
{
DWORD dwIn=0, dwOut=0, dwSize=GetFileSize(hSrc, NULL), dwTotal=0;
char buff[BUFFSIZE]={0};
MessageBox(cwp->hwnd, "Part2" , AppDes,0);
//no point trying to copy bytes from an empty file...
if(dwSize)
{
//perform a binary copy
while(ReadFile(hSrc, buff, sizeof(buff), &dwIn, NULL) && dwIn)
{
//if(pParams->pbCancel && *(pParams->pbCancel))
// break;
CeWriteFile(hDest, buff, dwIn, &dwOut, NULL);
dwTotal+=dwIn;
}
}
CeCloseHandle(hDest);
}
CloseHandle(hSrc);
}


Any help or sample C++ code for RAPI would greatly be appreciated. Let me also point out that I am a VERY basic C++ programmer, just started moving over from VB.

Thanks in advance,

Pete.