How C + + programs play into DLL dynamic libraries:
**1. Create a new main.h in VS and add the following: * *extern"C" _declspec (dllexport)IntOnLoad();**2. Create a new main.cpp and include the following. h header, then implement the definition function onload (): * *#Include"MainFunc.h"IntOnLoad(){//func ....} 3. Executes the program, generating corresponding Dll4. Use this dll:i. Declare in the file to be used: form: [DllImport ( "DllName")][dllimport ( "kernel32")]// Returns the length of the obtained string buffer private static Span class= "Hljs-keyword" >extern long getprivateprofilestring (string section, string key,< Span class= "hljs-built_in" >string def, StringBuilder RetVal, int size, string FilePath); and then calls like the other functions: GetPrivateProfileString (section, Key, Notext, temp, 1024, IniFilePath);
How C # programs play into DLLs:
方法1:图形界面的类库工程1.文件->新建项目->Visual C#->类库,输入项目名称即DLL类库的名称如FuncUtil,确定,新建类库项目;2.然后按照自己的功能需求新建C#源文件,可以有若干个.cs源文件,源文件间也可以相互调用,但必须有一个主类提供通用方法供外部调用(public method);3.点击生成->生成FuncUtil,程序就会编译并生成FuncUtil.dll文件;4.将如上生成的DLL文件以引用的方式导入到需要调用该DLL的项目中.5.调用方式和其他C#DLL的引用方式相同:如:using ComDll; //头部引用Communicate comm = new Communicate(); // 主函数调用comm.doSth();
Method 2:CSC Package Command into DLL
File:Add.csNamespaceutilitymethods{PublicClassAddClass {PublicStaticLongADD (Long I,Long j) {return (i + j); } }}...File:Mult.csNamespaceUtilitymethods {PublicClassMultiplyclass {PublicStaticLongMultiply (Long X,Long y) {return (x * y); } }}...File:TestCode.csUsing Utilitymethods;Classtestcode{StaticvoidMain (String[] args) {System.Console.WriteLine ("Calling Methods from MathLibrary.DLL:");if (args. Length! =2) {System.Console.WriteLine ( "Usage:testcode <num1> <num2> "); return;} long num1 = long. Parse (Args[0]); long num2 = long. Parse (Args[1]); long sum = Addclass.add (NUM1, num2); long Product = multiplyclass.multiply (NUM1, num2); System.Console.WriteLine ( "{0} + {1} = {2}", NUM1, num2, sum); System.Console.WriteLine ( "{0} * {1} = {2}", NUM1, num2, product);}} /* Output (assuming 1234 and 5678 is entered as command-line arguments): calling Methods from mathlibrary.dll:1234 + 5678 = 6912 1234 * 5678 = 7006652 */
Csc/target:library/out:mathlibrary.dll Add.cs Mult.cs
Pack Add.cs, Mult.cs into MathLibrary.DLL
Reprinted from: Http://www.cnblogs.com/qichunlin/p/7751786.html (has been agreed by bloggers)
C/c++/c# program how to make DLL dynamic library