Thread: Trying (and failing) to use an open Dialog box

  1. #1
    The Earth is not flat. Clyde's Avatar
    Join Date
    Mar 2002
    Posts
    1,403

    Trying (and failing) to use an open Dialog box

    I'm trying to use one of the common dialog boxes, and I'm using code from Petzold's book, but MSVC++ is throwing errors at me.

    I have a function called PopFileRead():

    Code:
    {
         BYTE   bySwap ;
         DWORD  dwBytesRead ;
         HANDLE hFile ;
         int    i, iFileLength, iUniTest ;
         PBYTE  pBuffer, pText, pConv ;
    
              // Open the file.
    
         if (INVALID_HANDLE_VALUE == 
                   (hFile = CreateFile (pstrFileName, GENERIC_READ, FILE_SHARE_READ,
                                        NULL, OPEN_EXISTING, 0, NULL)))
              return FALSE ;
    
              // Get file size in bytes and allocate memory for read.
              // Add an extra two bytes for zero termination.
                        
         iFileLength = GetFileSize (hFile, NULL) ; 
         pBuffer = malloc (iFileLength + 2) ;
    
          
    and on and on....
    And i'm getting this error:

    C:\Program Files\Microsoft Visual Studio\MyProjects\winpro2\File.cpp(76) : error C2440: '=' : cannot convert from 'void *' to 'unsigned char *'

    Which is caused by the

    Code:
     pBuffer = malloc (iFileLength + 2) ;
    What's going on?

  2. #2
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    If you're compiling it as C++ code, you'll have to cast -

    pBuffer = (PBYTE)malloc (iFileLength + 2);

  3. #3
    The Earth is not flat. Clyde's Avatar
    Join Date
    Mar 2002
    Posts
    1,403
    thanks

Popular pages Recent additions subscribe to a feed