how to create anew user control dll using c#?
how to create anew user control dll using c#?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Satyapriya NayakPosted May 12, 2012, 9:20 AM
Create and use DLLs in C Sharp. Before writing code, we will examine some basics of a DLL in the .NET framework; for example, how it's loaded in the process address space, how CLR is initialized, and the mechanism behind the screen. First, we will talk about MSCorEE.dll; you will find this guy in the %windir%\system32\ directory. MSCorEE.dll stands for Microsoft Component object runtime Execution Engine. The existence of this file tells you that you have installed the .NET framework in your system. This DLL is responsible for initializing the CLR.
Whenever you create an assembly, the compiler/linker emits the following 6-byte x86 stub function into the PE file's .text section:
JMP _CorExeMain for Exe or JMP _CorDllMain for Dll.
Figure 1 shows the Portable Executable (PE) file format. This stub function is implemented inside the MSCorEE.dll. So, this dll must be referenced somewhere in the PE file. Yes, your guess is right; it's referenced in the .idata section of the PE file. The .idata section is used to refer import libraries for assembly.
Figure 1—The PE file format.
We have given all the hints and clues to the Windows loader, so here we go.... When the managed assembly file is invoked, the Windows loader completes the following steps:
At this point, the process's primary thread starts executing the stub function; that is, it jumps to _CorExeMain for Exe or _CorDllMain for Dll in the MSCorEE.dll. The _CorExeMain or _CorDllMain initializes the CLR and looks for a managed entry point from the assembly's CLR header and starts executting. Here the IL code for the method is compiled into native CPU instructions and the CLR jumps to native code. That's it; the managed applications code is running.
The framework differentiates between managed executive and managed DLL files because of the stub function stored in the .text section of the PE file. For Exe, the stub function is JMP _CorExeMain and for Dll the stub function is JMP _CorDllMain. The Windows loader differentiates this function and fixes the corresponding address from the MSCorEE.dll.
I think now we know how a managed exe/dll loads in the process address space and how CLR gets initialized. Okay, time for coding. Here we develop a small DLL and a test container for that. This DLL will export three functions, each from one class in a namespace.
Open a new C# WindowsApplication project in Visual Studio .NET. Name the Project MathFunctions.
Add the following three classes to this project. Name them something like AddClass.cs, MultiClass.cs, and FactorialClass.cs.
Listing 1. AddClass.cs
Listing 2. MultiClass.cs
Listing 3. FactorialClass.cs
Our idea is to export AddClass::Add, MultiClass:: Multiply, and FactorialClass::Factorial from the namespace MathFunctions. That's it; we're finished coding.
Go to the command line and type the following.
Go to the command line option /target:library and ask the C Sharp Compiler/Linker to output a DLL instead of an EXE. It's possible to have a different name for the DLL; for example, /out:MyFunctions.dll directs the compiler to output the DLL with the name MyFunctionsLib; otherwise, it will take the default name from the first .cs file. Here, it's AddClass.dll.
Now comes the test container for this DLL. Create a new WindowsApplication project by right-clicking the solution in the Solution Explorer pane. Name it DllTestApp.
Add the following line to the Using section.
Add the following code to the click of button1.
To refer to the DLL in our project, right-click the project's reference and click Add Reference. This displays tabbed panes that list the various types of components and projects you can browse. On the .NET tab, click the Brows button and browse for the DLL to which you want to refer (here, MyFunctions.dll), and click OK.
Please refer the below link
http://www.codeguru.com/csharp/csharp/cs_misc/dllsandexecutables/article.php/c4239/Creating-and-Using-C-DLLs.htm
Thanks