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. How to execute a file in memory being of type CMemFile

How to execute a file in memory being of type CMemFile

Scheduled Pinned Locked Moved C / C++ / MFC
c++performancehelptutorialquestion
4 Posts 3 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.
  • A Offline
    A Offline
    Anonymous
    wrote on last edited by
    #1

    I have created an executive file in the form of CMemFile In an MFC application, which is directly copied in memory and is not on the hard disk. Now, how to execute this file directly from the memory? I tried to use the ShellExecute method, however, it does not accept the CMemFile giving an error saying that it cannot convert CMemFile to LPCSTR. Is there any method to directly execute the exe file from the memory? Regards

    D 1 Reply Last reply
    0
    • A Anonymous

      I have created an executive file in the form of CMemFile In an MFC application, which is directly copied in memory and is not on the hard disk. Now, how to execute this file directly from the memory? I tried to use the ShellExecute method, however, it does not accept the CMemFile giving an error saying that it cannot convert CMemFile to LPCSTR. Is there any method to directly execute the exe file from the memory? Regards

      D Offline
      D Offline
      David Spain
      wrote on last edited by
      #2

      How does CMemFile store its data? Most likely it stores a pointer to the memory that contains the actual data. Look in the Microsoft documentation for CMemFile to see how it stores the data. Hopefully, CMemFile has a method to provide this pointer. An LPCSTR is a pointer to a string, so method could be called and the result could be cast to an LPCSTR if it is not already returned that way. Then this could be provided to the ShellExecute function. David Spain, C++ Applications Programmer

      J 1 Reply Last reply
      0
      • D David Spain

        How does CMemFile store its data? Most likely it stores a pointer to the memory that contains the actual data. Look in the Microsoft documentation for CMemFile to see how it stores the data. Hopefully, CMemFile has a method to provide this pointer. An LPCSTR is a pointer to a string, so method could be called and the result could be cast to an LPCSTR if it is not already returned that way. Then this could be provided to the ShellExecute function. David Spain, C++ Applications Programmer

        J Offline
        J Offline
        Jose Lamas Rios
        wrote on last edited by
        #3

        David Spain wrote: How does CMemFile store its data? Most likely it stores a pointer to the memory that contains the actual data. Look in the Microsoft documentation for CMemFile to see how it stores the data. Hopefully, CMemFile has a method to provide this pointer. An LPCSTR is a pointer to a string, so method could be called and the result could be cast to an LPCSTR if it is not already returned that way. Then this could be provided to the ShellExecute function. I don't think so. You might obtain the CMemFile data using Detach, which returns a BYTE* and also closes the file. The return type is a BYTE* because a file may contain any type of data, not just text. Casting it to an LPCTSTR makes no sense: it may fool the compiler into accepting it, but the content will still be the same, and if it wasn't text, no one interpreting it as such will have correct results. In this case, in fact, it's an executable (binary) file. Besides, ShellExecute expects to receive the name of the file path and name, not the content of the file. -- jlr http://jlamas.blogspot.com/[^]

        D 1 Reply Last reply
        0
        • J Jose Lamas Rios

          David Spain wrote: How does CMemFile store its data? Most likely it stores a pointer to the memory that contains the actual data. Look in the Microsoft documentation for CMemFile to see how it stores the data. Hopefully, CMemFile has a method to provide this pointer. An LPCSTR is a pointer to a string, so method could be called and the result could be cast to an LPCSTR if it is not already returned that way. Then this could be provided to the ShellExecute function. I don't think so. You might obtain the CMemFile data using Detach, which returns a BYTE* and also closes the file. The return type is a BYTE* because a file may contain any type of data, not just text. Casting it to an LPCTSTR makes no sense: it may fool the compiler into accepting it, but the content will still be the same, and if it wasn't text, no one interpreting it as such will have correct results. In this case, in fact, it's an executable (binary) file. Besides, ShellExecute expects to receive the name of the file path and name, not the content of the file. -- jlr http://jlamas.blogspot.com/[^]

          D Offline
          D Offline
          David Spain
          wrote on last edited by
          #4

          Jose Lamas Rios wrote: I don't think so. You might obtain the CMemFile data using Detach, which returns a BYTE* and also closes the file. The return type is a BYTE* because a file may contain any type of data, not just text. Casting it to an LPCTSTR makes no sense: it may fool the compiler into accepting it, but the content will still be the same, and if it wasn't text, no one interpreting it as such will have correct results. In this case, in fact, it's an executable (binary) file. You are right. What I wrote actually made no sense. Obviously the ShellExecute function wants a string pointer, that points to the name of an actual file on disk. As simply another idea, an executable in memory seems similar to a running process. Would using CreateProcess or something similar be a better avenue to pursue instead of ShellExecute? David Spain, C++ Applications Programmer

          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