What is the best way to load a 64-bit dynamic library from a 32-bit one ? The LoadLibrary () function in this case does not help, since the bit depth is different.
I saw many similar questions, where they write that it is necessary to create a separate process in which to load the dll- file and interact with it by means of IPC (Inter-Process Communication) , but nowhere are there examples. Is this the only way and is it really the best? In the answer, please give an example of the program code in C ++ .
PS:
There is such an article, but there the case is exactly the opposite: Accessing 32-bit DLLs from 64-bit code and without examples.
In this article, they write that you can do without COM and IPC using the LoadLibraryEx () function: Lesson 2. Support of 32-bit applications in 64-bit Windows environment .
It is impossible to load a 32-bit DLL from a 64-bit process and execute its code. It is not possible due to the design of 64-bit systems. It is impossible fundamentally. And no tricks and undocumented means will help you. It is not necessary to speak of the kernel structures. Actually, it means a 32-bit process must be made 32-bit "on the fly". "Why can't you thunk between 32-bit and 64-bit Windows?" It is a process that can be carried out through the COM technology. You may read "Accessing 32-bit DLLs from 64-bit code".
But it is a 32-bit DLL into a 64-bit process. Load_LIBRARY_AS_DATAFILE when calling LoadLibraryEx .
However, in the description of the function from here: The LoadLibraryEx function says that:
LOAD_LIBRARY_AS_DATAFILE. If this value is used, the system converts and projects the file data into the virtual address space of the calling process, as if it were a data file. Nothing is done to execute the code or to prepare for the execution of the displayed file. Therefore, you cannot call functions like GetModuleHandle or GetProcAddress for this DLL. Use this flag when you want to load a DLL only to extract messages or resources from it.
So, this option is not suitable.