开发者

Converting a full-blown application to a DLL

I'm interested in taking a full-blown MFC application (window, menus, dialogs, etc.) application and turning it into a DLL so that it can be brought into the virtual address space of other executables.

I'd like to know if this is feasible or even possible before I invest too much time in it.

I don't think CreateProcess would work because it doesn't (?) bring the process into the same address space as the caller like a DLL does.


I've done some research and found the following:

A page on MSDN, "TN011: Using MFC as Part of a DLL", which is useful, but is written from the perspective that you are writing the DLL from scratch.

The following quote on differences between EXEs and DLLs:

"An application can own things such as a stack, global memory, file handles, and a message queue, but a DLL cannot."


I understand the basics of DLLs, but most DLLs do not provide the same functionality as full-blown applications.

Would it be enough to replace the DLL CRT startup code with something that creates a new thread which emulates the WinMain-style CRT startup? This idea would necessarily开发者_StackOverflow require pushing all this startup code out of the real DllMain to avoid DLL loading lock ups.

Am I on the right track or are there some DLL-related issues that make this untenable?

Is there some easy way to wrap an exe in a DLL I'm unaware of?

Thank you for reading this.


OP here, reporting partial success.

I just used the MFC DllMain rather than trying to emulate a WinMain-style startup. I had a few minor problems: show window bool was 0, GetModule not working as expected, but after sorting them out the program starts and runs as normal. Pretty amazing, actually.

The problems I'm now having relate to ending the program. Closing the window doesn't end the program like it normally would and it locks up trying to get a message shortly afterwards. WM_QUIT solves that problem.

That's in the synchronous case (rundll32 waiting on the main loop to exit). When I create a thread to run the program asynchronously, one of the many threads the program uses crashes soon after WM_QUIT gets sent.

That's as far as I've gotten. I'm not asking for advice, merely putting this out there for future generations to reference.


I'm interested in taking a full-blown MFC application (window, menus, dialogs, etc.) application and turning it into a DLL so that it can be brought into the virtual address space of other executables.

It sounds like you want to reuse functionality in your MVC application, and expose that functionality as a DLL? I don't think you can take the entire thing and wrap it inside a DLL, as this would then violate what you mentioned earlier (DLL does not handle stack, global memory, etc.). Have you considered moving functionality out of the application and into the DLL? I believe this is what the other posters may have been hinting at.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜