Tips for packaging DLL files into EXE (C #)

Source: Internet
Author: User

Http://www.cnblogs.com/zengxlf/archive/2009/05/17/1458996.html

Let's just talk nonsense. Go to the topic.

Use vs2005 to create a Windows project named Test

Reference DLL files

WriteCode, Normally reference the class library in the DLL,

Add a resource file to the test project (this file is the DLL file just referenced)

Vs2005 will automatically generate the reference code. Here I reference irisskin2.dll

Internal   Static   Byte [] Irisskin2 {
Get {
ObjectOBJ=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 " ;
// * ***** Load irisskin2.dll ******
If ( ! File. exists (Path + Dllfilename )) // File does not exist
{< br> filestream FS = new filestream (path + dllfilename, filemode. createnew, fileaccess. write );
byte [] buffer = getdata. properties. resources. irisskin2; // {getdata is the namespace}
FS. write (buffer, 0 , buffer. length);
FS. close ();
}
// *****************************

Application. Run ( New Gdform ());
}

Compile the test project and generate the EXE file,

Then delete the referenced DLL file (note that the file is compiled first and then deleted)

Copy the EXE file to run it elsewhere (no DLL is needed, and running the EXE will automatically generate the DLL file)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.