how to produce a mix of dll and exe in one C# project in visual studio or other build tools?

前端 未结 2 1113
慢半拍i
慢半拍i 2021-01-24 19:41

how to produce a mix of dll and exe in one C# project in visual studio or other build tools ? Is it technically possible ? Yes I know it can done in 2 or more projects .

相关标签:
2条回答
  • 2021-01-24 20:14

    Technically, a mix of exe and dll would be simply an exe. Nothing's wrong with using it as a library e.g reference to it in other projects.

    First we need to be clear that both "exe" and "dll" are fundamentally the same but the difference lies in how windows interacts with them.

    When windows loads a dll, it runs the initialization code and then leaves it alone. Functions in the dll are called if they are explicitly referenced by an application. Another thing, when dll gets crashed it not only crashes itself but also the application as the dll runs in the memory of the parent application.

    When windows load an exe, the exe's initialization code is responsible for creating what is called as "message pump", nothing but a program loop which runs as long as the application is running. The message pump request messages from the operating system. Windows keep track of the application as a separate task. It allocates separate memory for both the exe and the application using that exe. The memory area in which each exe runs is called "Process Space".

    Dan Appleman - Developing ActiveX Components with Visual Basic 5.0

    0 讨论(0)
  • 2021-01-24 20:17

    I'm not sure what the motivations for your question are, as you can reference a .Net executable as if it were a dll anyway, but you could consider copying the exe file to a dll file with the same name (yes it's a hack but not sure of your motivations).

    You can automate this process using a Visual Studio post-build event for your project. This will handle creating the dll copy each time you have a successful build:

    copy "$(TargetPath)" "$(TargetDir)$(TargetName).dll"
    
    0 讨论(0)
提交回复
热议问题