Tips for packing DLL files into EXE

  • 2020-05-09 19:06:19
  • OfStack

Without further ado, let's get straight to the point
Build an windows project with VS2005 and name it test

Reference the dll file
Write code that normally refers to the dll library,
Also add the resource file to the test project (this is the dll file you just referenced)
VS2005 automatically generates the reference code, which I'm referring to here as IrisSkin2.dll
 
internal static byte[] IrisSkin2 { 
get { 
object obj = ResourceManager.GetObject("IrisSkin2", resourceCulture); 
return ((byte[])(obj)); 
} 
} 

Then add the code to the Main(program.cs) function
 
static void Main() 
{ 
Application.EnableVisualStyles(); 
Application.SetCompatibleTextRenderingDefault(false); 
string path = Application.StartupPath + "\"; 
string dllFileName = "IrisSkin2.dll"; 
//****** loading IrisSkin2.dll****** 
if (!File.Exists(path + dllFileName)) // File does not exist  
{ 
FileStream fs = new FileStream(path + dllFileName, FileMode.CreateNew, FileAccess.Write); 
byte[] buffer = GetData.Properties.Resources.IrisSkin2;//{GetData It's a namespace } 
fs.Write(buffer, 0, buffer.Length); 
fs.Close(); 
} 
//***************************** 
Application.Run(new GDForm()); 
} 

Compile the test project, generate the exe file, and then delete the referenced dll file.
Copy the exe file and you can run it somewhere else (instead of dll, running EXE will automatically generate DLL files)

Related articles: