CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2005
    Posts
    59

    Convert char* to Byte*

    In summary I am trying to pass a compressed file to an uncompress function...

    The uncompress function is defined as follows

    Code:
    /*------------------------------------------------------------------------------
    --------------------------
    int DecompressLZW(BYTE *pSrcData,DWORD dwSrcSize,BYTE* OutputBuffer,DWORD dwMaxOutput) 
    
    pSrcData - raw compressed data to be decompressed
    dwSrcSize - the number of bytes of compressed data to decompress
    OutputBuffer - the location to write the decompressed data into
    dwMaxOutput - the maximum amount to write into the OutputBuffer
    --------------------------------------------------------------------------------
    ---------------------*/
    I then have an open file dialog....

    Code:
    BYTE * OutputBuffer;
    BYTE * pSrcData;
    CString strl="Please Select a Compressed File to Decompress";
    
    	char strFilter8[]= { "CMP Files(*.cmp)|*.cmp|All Files(*.*)|*.*||"};
    	CFileDialog dlgFile8(TRUE, ".cmp", NULL,0,strFilter8);
    	dlgFile8.m_ofn.lpstrTitle= strl;
                    if (dlgFile8.DoModal() ==IDOK)
    	{
    		
    		
    		
    		
    	ifstream file9((LPCTSTR) dlgFile8.GetFileName(), ios::in|ios::binary);
    		file9.seekg (0, ios::end);
    		int sizecmp = file9.tellg();
    		int sizecmp2 = sizecmp * 3;
    		file9.seekg (0, ios::beg);
    		pSrcData = new BYTE[sizecmp];
    		file9.read (pSrcData, sizecmp);
    		file9.close();
    		OutputBuffer = new BYTE[sizecmp2];
    	DecompressLZW(pSrcData,sizecmp, OutputBuffer,sizecmp2);
    		
    	}
    The problem is the file.read requires a char * buffer and if I use a char * buffer I cannot pass pSrcData to the function as the function requires a Byte *

    I know the answer is staring me in the face but I cant seem to get it to work.

  2. #2
    Join Date
    Mar 2001
    Posts
    2,529

    Re: Convert char* to Byte*

    This is a common problem.

    cast the byte* to char*.
    Code:
    file9.read ((char*)pSrcData, sizecmp);
    byte * is the same as unsigned char*.

    I find myself doing this occasionally. Also I like to read my files byte by byte especially when dealing with binary data.

    ahoodin

    PS If this helped, don't forget to rate. Good things come to those who rate.
    Last edited by ahoodin; January 24th, 2006 at 01:39 PM. Reason: PS + comment

  3. #3
    Join Date
    Aug 2005
    Posts
    59

    Re: Convert char* to Byte*

    so basically if I use unsigned char * pSrcData I can pass that to the function.....I will give that a go...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured