Windows CE BinaryCompression



Can anyone help me with this?

I found at winCe sources this function:

//------------------------------------------------------------------------------
// Compressors - bufin and bufout must be WORD aligned, lenout must be at
least as
// large as lenin, CECOMPRESS_FAILED is returned if it doesn't fit, else
compressed length
// CECOMPRESS_ALL_ZEROS returned if buffer entirely zero. If bufout is
NULL, the output
// length is computed, but the results are not stored. Lenin must be a
multiple of 2.
//------------------------------------------------------------------------------

DWORD
NKBinaryCompress(
LPBYTE bufin,
DWORD lenin,
LPBYTE bufout,
DWORD lenout
)
{
DWORD retval;

TRUSTED_API (L"NKBinaryCompress", CECOMPRESS_FAILED);

DEBUGMSG(ZONE_ENTRY, (L"NKBinaryCompress entry: %8.8lx %8.8lx %8.8lx
%8.8lx\r\n", bufin, lenin, bufout, lenout));

retval = CECompress(bufin, lenin, bufout, lenout, 1, 1024);

DEBUGMSG(ZONE_ENTRY, (L"NKBinaryCompress exit: %8.8lx\r\n", retval));

return retval;
}

But i CAN´T understand the comment, what is WORD aligned?

i'm trying to use it and i'm receving an Error.. i will post the sample
code:

//DWORD BinaryCompress(LPBYTE bufin, DWORD lenin, LPBYTE bufout, DWORD
lenout);
//DWORD BinaryDecompress(LPBYTE bufin, DWORD lenin, LPBYTE bufout, DWORD
lenout, DWORD skip);
[DllImport("coredll.dll", SetLastError=true)]
public static extern unsafe int BinaryCompress(byte* bufferIn, int lenIn,
byte* bufferOut, ref int lenOut);
[DllImport("coredll.dll", SetLastError = true)]
public static extern unsafe int BinaryDecompress(byte* bufferIn, int lenIn,
byte* bufferOut, ref int lenOut, int skip);
string fileOpen = "\\Temp\\test.bmp";
byte[] bFile;
bFile = OpenFile(fileOpen);
byte[] bufferNew = new byte[bFile.Length];
int iLen = 0;
int ret = 0;
fixed(byte* bLP = bFile)
fixed (byte* bLPNew = bufferNew)
{
ret = BinaryCompress(bLP, (int)bFile.Length, bLPNew, ref
iLen);
if (ret != 0)
{
ret = Marshal.GetLastWin32Error();
MessageBox.Show(new Win32Exception(ret).Message); //
this always return 87 / Win32Exception
}
}

if anyone wants to see the OpenFile
private static byte[] OpenFile(string fileOpen)
{
byte[] bFile;
FileStream fs = File.OpenRead(fileOpen);
bFile = new byte[fs.Length];
byte[] bAux = new byte[1024];
int bytToRead = (int)fs.Length;
int count = 0;
int idx = 0;
while (bytToRead > 0)
{
count = fs.Read(bAux, 0, bAux.Length);
idx = (int)fs.Length - bytToRead;
for (int i = 0; i < count; i++)
bFile[idx+i] = bAux[i];
bytToRead -= count;
}
fs.Close();
return bFile;
}

The file length is 307254 bytes.
Any idea??
Thanks a lot.


.



Relevant Pages

  • Re: Windows CE BinaryCompression
    ... // Compressors - bufin and bufout must be WORD aligned, lenout must be ... // large as lenin, CECOMPRESS_FAILED is returned if it doesn't fit, ... DWORD lenin, ... public static extern unsafe int BinaryCompress(byte* bufferIn, ...
    (microsoft.public.windowsce.app.development)
  • Re: Windows CE BinaryCompression
    ... // Compressors - bufin and bufout must be WORD aligned, lenout must be at ... // large as lenin, CECOMPRESS_FAILED is returned if it doesn't fit, else ... DWORD lenin, ... public static extern unsafe int BinaryCompress(byte* bufferIn, int lenIn, ...
    (microsoft.public.windowsce.app.development)
  • Re: Windows CE BinaryCompression
    ... // Compressors - bufin and bufout must be WORD aligned, lenout must be at ... // large as lenin, CECOMPRESS_FAILED is returned if it doesn't fit, else ... DWORD lenin, ... public static extern unsafe int BinaryCompress(byte* bufferIn, int lenIn, ...
    (microsoft.public.windowsce.app.development)