Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. why does this code fail?

why does this code fail?

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Brakanjan
    wrote on last edited by
    #1

    Hi another question why don't the following code compile? extern CFile cfile; void *data; CFile::Open(m_Pathname1,modeRead); data = cfile.Read(0,cfile.GetLength()); i get the error: error C2440: '=' : cannot convert from 'unsigned int' to 'void *' Conversion from integral type to pointer type requires einterpret_cast, C-style cast or function-style cast (BTW, what does extern do! Otherwise CFile::Read(etc) also works) thanks

    M 1 Reply Last reply
    0
    • B Brakanjan

      Hi another question why don't the following code compile? extern CFile cfile; void *data; CFile::Open(m_Pathname1,modeRead); data = cfile.Read(0,cfile.GetLength()); i get the error: error C2440: '=' : cannot convert from 'unsigned int' to 'void *' Conversion from integral type to pointer type requires einterpret_cast, C-style cast or function-style cast (BTW, what does extern do! Otherwise CFile::Read(etc) also works) thanks

      M Offline
      M Offline
      Martin Ziacek
      wrote on last edited by
      #2

      extern CFile cfile; CFile::Open(m_Pathname1,modeRead); DWORD dwFileLength = cfile.GetLength(); BYTE *data = new BYTE[dwFileLength]; DWORD dwBytesRed = cfile.Read(data,dwFileLength); Martin -------------------------------------------- C'mon we all know computers are experimental devices and should only be used for playing games. Using them for alternative stuff like business, is clearly not using them for what they are intended. Colin Davies

      B 1 Reply Last reply
      0
      • M Martin Ziacek

        extern CFile cfile; CFile::Open(m_Pathname1,modeRead); DWORD dwFileLength = cfile.GetLength(); BYTE *data = new BYTE[dwFileLength]; DWORD dwBytesRed = cfile.Read(data,dwFileLength); Martin -------------------------------------------- C'mon we all know computers are experimental devices and should only be used for playing games. Using them for alternative stuff like business, is clearly not using them for what they are intended. Colin Davies

        B Offline
        B Offline
        Brakanjan
        wrote on last edited by
        #3

        tx, this works what does BYTE *data = new BYTE[dwFileLength] do?

        M 1 Reply Last reply
        0
        • B Brakanjan

          tx, this works what does BYTE *data = new BYTE[dwFileLength] do?

          M Offline
          M Offline
          Martin Ziacek
          wrote on last edited by
          #4

          It allocates memory to hold data from the file. When you will finish using it, then you have to free that memory with: delete [] data; I think you have to read little bit more about C++. Martin -------------------------------------------- C'mon we all know computers are experimental devices and should only be used for playing games. Using them for alternative stuff like business, is clearly not using them for what they are intended. Colin Davies

          B 1 Reply Last reply
          0
          • M Martin Ziacek

            It allocates memory to hold data from the file. When you will finish using it, then you have to free that memory with: delete [] data; I think you have to read little bit more about C++. Martin -------------------------------------------- C'mon we all know computers are experimental devices and should only be used for playing games. Using them for alternative stuff like business, is clearly not using them for what they are intended. Colin Davies

            B Offline
            B Offline
            Brakanjan
            wrote on last edited by
            #5

            ok hero

            M 1 Reply Last reply
            0
            • B Brakanjan

              ok hero

              M Offline
              M Offline
              Martin Ziacek
              wrote on last edited by
              #6

              Jenny2 wrote: ok hero :):):) Martin -------------------------------------------- C'mon we all know computers are experimental devices and should only be used for playing games. Using them for alternative stuff like business, is clearly not using them for what they are intended. Colin Davies

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups