Definition
dynamic link library (DLL)
A dynamic link library (DLL) is a collection of small programs, any of which can be called when needed by a larger program that is running in the computer. The small program that lets the larger program communicate with a specific device such as a printer or scanner is often packaged as a DLL program (usually referred to as a DLL file). DLL files that support specific device operation are known as device drivers.
//Definition: A DLL file, short for Dynamic Link Library, is a type of file that contains instructions that other programs can call upon to do certain things. This way, multiple programs can share the abilities programmed into a single file.//
DLLs are Dynamic Link Libraries, which means that they're linked into your program at run time instead of build time. There are three parts to a DLL:
*the exports
*the code and data
*the import library
The code and data are the parts you write - functions, variables, etc. All these are merged together, like if you were building one big object files, and put into the dll. They are not put into your .exe at all.
The exports contains a list of functions and variables that the dll makes available to other programs. Think of this as the list of "global" symbols, the rest being hidden. Normally, you'd create this list by hand with a text editor, but it's possible to do it automatically from the list of functions in your code. The dlltool program creates the exports section of the dll from your text file of exported symbols.
The import library is a regular UNIX-like .a library, but it only contains the tiny bit of information needed to tell the OS how your program interacts with ("imports") the dll. This information is linked into your .exe. This is also generated by dlltool.
The advantage of DLL files is that, because they don't get loaded into random access memory (RAM) together with the main program, space is saved in RAM. When and if a DLL file is needed, then it is loaded and run. For example, as long as a user of Microsoft Word is editing a document, the printer DLL file does not need to be loaded into RAM. If the user decides to print the document, then the Word application causes the printer DLL file to be loaded and run.
A DLL file is often given a ".dll" file name suffix. DLL files are dynamically linked with the program that uses them during program execution rather than being compiled with the main program. The set of such files (or the DLL) is somewhat comparable to the library routines provided with programming languages such as C and C++
Example
I received an error message when my computer started up that said I was missing a particular DLL file. After an exhaustive search on the Internet, I found out that I would have to reinstall Windows to fix it!"
///new code
Hi, today i will explain you How to create and manage library(.dll) files in your unity project.
Tools:
1.Unity3D Pro
2.VISUAL C# 2010 EXPRESS or Visual Studio 2010,
3.C# Basic knowledge
4.Brain
5.Hands 8-).
Starting new Project:
Open VISUAL C# 2010 EXPRESS or Visual Studio 2010, go to File>New Project>Visual C#>Class Library. Set Your file name(I named it Tutorial) and Choose(.NET Framework 3.5) not above, otherwise unity will not read .dll.
after setup it will open something like this.
Code: 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Tutorial
{
public class Class1
{
}
}
Ok lets start coding
for more beautifulnes lets change class name (REMEMBER: when you change class name, change also file name in the project) I actualy changing name of the project .cs file name, and it automaticly changing class name for me 8-) .
Now my code will look like this:
Code: select. Line 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Tutorial
{
public class tut
{
//code goes here
}
}
the (namespace Tutorial) will be used in our unity later, it`s mean we must leave it exactly that it or you can change it to other name, for now i will use (namespace Tutorial);
Now i will put some basic function with name "textview" and it will be string. Then i will returne my name.
to construct public function in c# you make it like this (public [string,int,etc...] [function name]() { }).
OK my function is like this
Code: select line 
public string textview()
{
return "Mr.Smart";
}
Now my code will look like this:
Code: code select
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Tutorial
{
public class tut
{
public string textview()
{
return "Mr.Smart";
}
}
}
My dll is ready, i need to build it. go to Build>Configuration Manager... and change debug to release.
your dll must be builded in yourproject\bin\Release folder.
Now go to your Unity project folder and open Assets folder, in that folder make "new folder" called "Plugins".
This will be you plugin folder, paste your.dll to that folder, Unity will automaticly import it.
Usage is very seample open your c# script in your unity project.
Lets say that we make new script and there is nothing.
Blank c# script with class name tutorial.
Code: code select

using UnityEngine;
using System.Collections;
public class tutorial : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}
to get dll work in our script we must make new destination to it.
seamply we will put in upper side "using [your dll file name];" it will automaticly popup if your dll script will not have any error, that is why we didnt delete the "namespace Tutorial" from our dll code.
when we inported dll we must make new variable with the new class of our dll.
for me it will look like
Code: select 1 line
public tut a = new tut();
t somthing like to make new Vector3 class.
We have imported dll , we have new class. Now we need to call function in our "tut()" class.
it will look like this
Code: select line 
a.textview()
and i will print it in my awake function
Code: select lines 
void Awake(){
//printing
print(a.textview());
}
My code finaly will look like this:
Code: select lines 
using UnityEngine;
using System.Collections;
using Tutorial;
public class tutorial : MonoBehaviour {
//making the new class
public tut a = new tut();
//on awake
void Awake(){
//printing
print(a.textview());
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}
Sent from my BlackBerry® wireless device
No comments:
Post a Comment