Some programs run, may call external DLLs, users may accidentally lose these DLLs, causing the program to not function properly, so you can consider embedding these DLLs into the resources, automatically released at startup. For managed DLLs, we can use packaged software to synthesize an EXE (for example, with Imerge), but for some unmanaged DLLs written in C + +, it's a bit cumbersome. In this case, you can consider the approach described in this article.
1. Embed the DLL file you want to use in the resource file.
(1) Copy the required DLL files to the project;
(2) Modify the "Build Action" to "Embedded Resource";
This completes the process of embedding the DLL file into the resource.
2, write the process of automatic release
voidReleasedll () {byte[] Bydll =Global:: namespace. Properties.Resources.test;//gets an array of bytes embedded in the DLL file stringstrpath = Application.startuppath +@"\test.dll";//set the release path//Create DLL file (overwrite mode) using(FileStream fs =NewFileStream (strpath, FileMode.Create)) {fs. Write (Bydll,0, bydll.length); } }
At the start of the program, first call the above function to complete the release of the DLL file, and then the program will be able to run normally. This practice is only the author in the actual project sometimes used in a way, I believe that we also have a certain reference value.
C # Embedded DLL-to-resource release issues