Re: loadlibrary mfc exe
- From: Tim Roberts <timr@xxxxxxxxx>
- Date: Thu, 14 Sep 2006 23:28:09 -0700
George VS <GeorgeVS@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
I am trying to load MFC exe module as dynamic link library and call an
exported function from it:
LoadLibrary("myapp1.exe")
Myapp1Test();
The exe is loaded successfully and the function is entered,
but whichever function is called exception raises.
It seems as virtual addresses in the loaded exe mess up with loading
application;
That's correct. You can load an EXE with LoadLibrary, but it will be
loaded as a chunk of inanimate data. It will not be relocated or processed
like a DLL.
Think about what it would mean otherwise. When you call LoadLibrary, the
loader calls the function at the initial transfer address. For a DLL, that
means the DllEntryPoint/DllMain function gets called. For an EXE, that
means calling mainCRTstartup, which calls the "main" function. That means
that LoadLibrary("myapp1.exe") would end up running the whole application.
Is there any standard/documented way to load exe as DLL?
No. You can do the relocation yourself, but you will only end up hurting
yourself. The right thing to do is to extract the desired function into a
separate DLL and call it from both places.
--
- Tim Roberts, timr@xxxxxxxxx
Providenza & Boekelheide, Inc.
.
- Prev by Date: Re: Process image name and path from PID.
- Next by Date: Re: Mapping memory of another process
- Previous by thread: Re: loadlibrary mfc exe
- Next by thread: Process image name and path from PID.
- Index(es):
Relevant Pages
|