PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Writing out Binary Resources

Hi all,
I've run into a bit of a problem in a piece of software I'm working on. I am writing a installer that runs on Pocket PC 2003 and above. The installer is written in eVC++ 4.0. Basically, the installer has a bunch of Resources added to it in the project. These resources are just imported .CAB files. The interface steps through and guides them through installation in a specific order.

When a cab is installed, the resource is locked, a file is created, WriteFile(...) is called, and the file is closed and executed. It seems to be going well. However, occaisionally I have a problem. Through debugging, I've noticed that WriteFile is writing out less than the number of bytes than the resource. Of course, this makes the .CAB invalid and causes problems... Here is the code snippet that writes out the cab file:


Code:
void CopyCabResource(WORD wResource)
{
SetCursor(LoadCursor(NULL, IDC_WAIT));

HGLOBAL hResD = NULL;
void *pvRes = NULL;
DWORD dwSize = NULL;
HRSRC hResInfo = NULL;

///
/// Find the resource and load it into memory
///
hResInfo = FindResource(hInst, MAKEINTRESOURCE(wResource), L"CAB");
hResD = LoadResource(hInst, hResInfo);
pvRes = LockResource(hResD);
dwSize = SizeofResource(hInst, hResInfo);

///
/// Create the temp directory
///
CreateDirectory(tempCabPath, NULL);

///
/// Create the file
///
HANDLE hCabFile = INVALID_HANDLE_VALUE;
hCabFile = CreateFile(tempCabFile, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_ARCHIVE, NULL);

///
/// Write to the file
///
DWORD dwNumberOfBytesWritten = 0;
WriteFile(hCabFile, pvRes, dwSize, &dwNumberOfBytesWritten, NULL);

///
/// Close the file
///
CloseHandle(hCabFile);

SetCursor(NULL);
}


So for example, dwSize (the real size of the resource) could be 1128448 bytes, but WriteFile returns 999876 to the dwNumberOfBytesWritten. I've tried looping WriteFile until TotalBytesWritten = dwSize, but subsequent calls write out 0 bytes... Memory is not an issue. I have 8MB free storage, and 20 running.

Also, this seems to be happening primarily on 2003 2nd Edition devices. My vanilla 2003 device has no issues! Any ideas?
Thinking about this some, I'm starting to wonder if memory is an issue? I "have enough" memory, but maybe I don't have enough un-fragmented memory? I also must mention, the .exe I am working with is 14MB large. There are numerous .CABs in the .exe that need to be installed. Is it possible that the .CAB resource I'm working with is also fragmented? Maybe WriteFile is writing out all it can, because the rest of the resource lies in another portion of memory?
What is WriteFile's return code? If it is FALSE call GetLastError() to see what happened.

Dan East