I am looking for any info. (I know some C++ with win32 and C#)

The Idea:

The idea is to help a program with missing files load. In the end I wanted to see if I could have my program launch a simple c++ executable that requires a dll which prints "hello world" to standard output. The quirk would be that the dll is not present in the folder. The c++ program instead of crashing is suspended and the main program has to request the dll from some source. When the dll is loaded, the printing process is resumed and continues running.

Example of execution.

MainProcess => start("a.exe");
a.exe => LoadLibrary("test.dll");
OS responds with "file does not exist".
MainProcess catches said exception.

MainProcess suspends a.exe like in this example.

MainProcess finds dll.
MainProcess dispatches the exception.
MainProcess tells gets a.exe to attempt loading again.

Are there cases where this kind of thing would not work? Can a parent capture exceptions meant for children?

How would one do that?

Also is it possible to tell exactly which files a process will need before running it?

  • When you say "files a process will need" do you mean any random file, or do you mean only DLLs? Apr 1, 2016 at 19:46
  • I would like it to work with any file that the process could try to load. So it should handle any operation that could throw a file not found exception. Apr 1, 2016 at 19:48

2 Answers 2


Also is it possible to tell exactly which files a process will need before running it?

This is not feasible. First, there are many APIs that load files. You'd need to scan for every one of them. Then, you'd need to figure out what the appropriate parameter would be at runtime. Consider this code:

char foo[100]
FILE* fp = open(foo)

Well, there you are hosed. How do you predict what the user might enter?

("Hey", you might say, "I tagged my question C++. What's with the scanf!?" Well, see, that's exactly it. That is legal C++ code, so you'd have to scan for code like that, not just std::cout.)

Even if you could ignore that, what about third-party libraries? They load files. For most developers, most files are probably loaded under the covers.

But say you ignore all that...only test for things explicitly listed in the file. But you are in a separate process, and the user just did a DEL importantlibrary.dll.

Now in a constrained system, maybe you could avoid user entry and avoid file system changes, and you might think you are ok. But you'd still have to track every code-path, with every set of possible inputs, until the program stops running.

Which means you have to prove your program will stop running. Oops. That is often [https://en.wikipedia.org/wiki/NP-completeness](Not possible).

Now if you are talking just about DLLs loaded by an EXE on load (and not dynamically at runtime, that is potentially tractable.

  • I understand. It seemed like a cool idea to "stream" a program from the web prioritizing files it needed immediately. Apr 1, 2016 at 20:27
  • Yes, this can be done. Many web-based apps do exactly this. Not many non-web platforms do this directly, but it could be hand-rolled. Apr 1, 2016 at 21:36

In .NET there are mechanisms around to assist with loading libraries. To quote the MSDN article:

The .NET Framework provides the AppDomain.AssemblyResolve event for applications that require greater control over assembly loading. By handling this event, your application can load an assembly into the load context from outside the normal probing paths, select which of several assembly versions to load, emit a dynamic assembly and return it, and so on.

This will allow you to search for the assembly to load (or even download it from a server.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.