Click here to Skip to main content
13,344,765 members (59,589 online)
Click here to Skip to main content
Add your own
alternative version


43 bookmarked
Posted 20 Aug 2006

Using DLL Component as Embedded Resource (Using Reflection)

, 20 Aug 2006
Rate this:
Please Sign up or sign in to vote.
Describes how you can use DLL component without reference from resources
Sample screenshot


Hello! First of all, I need to say some words about the main aim of this topic. This is Reflection. Reflection is a great instrument for a programmer. You can use it for dynamically creating an instance of some types, bind the type to an existing object or get the type of the existing object.

My sample application gets the main system info. You may create your own.:) Source code isn't quite good, but it's just an example of how you can use a DLL component from resources. Some time ago, I downloaded IrisSkin component to make my applications in skin automatically, including all forms and Windows. This component is quite good, but I had to distribute IrisSkin.DLL and other stuff with my application... and I really didn't want to do that...

So I decided to use IrisSkin component from applications resources using Reflection.

First of all, we should add IrisSkin.DLL to our solution and set as Embedded Resource BuildAction for this component.

If we are using IrisSkin component like an Extern resource (referencing), InitializeComponent method seems like this (in the general case):

private void InitializeComponent()
   this.skinEngine1 = new Sunisoft.IrisSkin.SkinEngine(
    // skinEngine1 
    // this.skinEngine1.SerialNumber = ""; 
    this.skinEngine1.SkinFile = null; 
    // Form1 
    // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 
    this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 
    this.ClientSize = new System.Drawing.Size(292, 273); 
    this.Name = "Form1"; this.Text = "Form1"; 

But we are using Iris Component like an Embedded Resource, so InitializeComponent method in this case should seem like this (in the movement of my application):

private void InitializeComponent()
    System.ComponentModel.ComponentResourceManager resources = 
       new System.ComponentModel.ComponentResourceManager(typeof(Form1));
    this.skinEngine1 = GetDLLComponent();

GetDLLComponent is the heart of this block of code. Let's view this part of code. Here we go...

public object GetDLLComponent()
System.Reflection.BindingFlags flags = 
     (System.Reflection.BindingFlags.NonPublic | 
      System.Reflection.BindingFlags.Public |
      System.Reflection.BindingFlags.Static | 
      System.Reflection.BindingFlags.Instance | 

System.Globalization.CultureInfo clinf = new System.Globalization.CultureInfo(

System.Reflection.Assembly assembly = System.AppDomain.CurrentDomain.Load(

supaObj = assembly.CreateInstance("Sunisoft.IrisSkin.SkinEngine", 
          false, flags, null, 
          new object[] { ((System.ComponentModel.Component)(this)) }, 
          clinf, new object[] { });

System.Type supaType = supaObj.GetType();

System.ComponentModel.ComponentResourceManager resources = new 

      supaObj, new object[] 
     { "isBx30VBCC0GTnUjKOl7Q0jK7I8NqeyOjDigXGIG5v1dN7aw4qc3Ogw==" });
           new object[] { ((System.IO.Stream)(
           resources.GetObject("DiamondBlue.ssk"))) });
		new object[] { ((System.IO.Stream)(
                resources.GetObject("skinEngine1.SkinStreamMain"))) });

return supaObj;

So, if you are acquainted with Reflection and OOP;), this part of code will be quite simple for you. If you have any suggestions or questions - you are welcome! I hope this code will help you.


  • 20th August, 2006: Initial post


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Web Developer
Russian Federation Russian Federation
FetalDump has been developing about 6 years.
He is a lead developer of DataFort Company(Ibs Holding
He lives in Moscow.
His interests are: Music and Painting.

You may also be interested in...


Comments and Discussions

QuestionHow to use a unmanged C++ dll Component( that doesn't require instantiation) as Embedded Resource using Reflection ? Pin
manutechalpy3088-Apr-09 20:35
membermanutechalpy3088-Apr-09 20:35 Pin
Angel T26-Jun-07 5:48
memberAngel T26-Jun-07 5:48 
GeneralRe: Pin
Grant Porteous24-May-08 17:43
memberGrant Porteous24-May-08 17:43 
QuestionError Pin
Member #327494324-Feb-07 1:14
memberMember #327494324-Feb-07 1:14 
GeneralcecUnamanaged dll as a resource Pin
raghab19-Feb-07 23:42
memberraghab19-Feb-07 23:42 
Generalre Using DLL component as Embedded Resource (Using reflection) [modified] Pin
haida18-Jan-07 5:40
memberhaida18-Jan-07 5:40 
GeneralError loading project Pin
ajay20059-Jan-07 5:05
memberajay20059-Jan-07 5:05 
QuestionError loading project [modified] Pin
Nbranquinho18-Sep-06 5:20
memberNbranquinho18-Sep-06 5:20 
GeneralSerial Number Pin
regedit22-Aug-06 3:37
memberregedit22-Aug-06 3:37 
GeneralRe: Serial Number Pin
FetalDump22-Aug-06 5:21
memberFetalDump22-Aug-06 5:21 
Only shi... OMG | :OMG: Confused | :confused: WTF | :WTF: Unsure | :~

Just FetalDump...

GeneralRe: Serial Number Pin
caiafaverde29-Aug-06 2:28
membercaiafaverde29-Aug-06 2:28 
GeneralILMerge Pin
tonyt21-Aug-06 10:56
membertonyt21-Aug-06 10:56 
GeneralRe: ILMerge Pin
FetalDump22-Aug-06 5:25
memberFetalDump22-Aug-06 5:25 
GeneralRe: ILMerge [modified] Pin
Boris Boef29-Aug-06 1:56
memberBoris Boef29-Aug-06 1:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.180111.1 | Last Updated 21 Aug 2006
Article Copyright 2006 by FetalDump
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid