How to execute a file in memory being of type CMemFile
-
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
-
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
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
-
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
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 usingDetach
, which returns aBYTE*
and also closes the file. The return type is aBYTE*
because a file may contain any type of data, not just text. Casting it to anLPCTSTR
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/[^] -
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 usingDetach
, which returns aBYTE*
and also closes the file. The return type is aBYTE*
because a file may contain any type of data, not just text. Casting it to anLPCTSTR
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/[^]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