473,385 Members | 1,907 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

embedded resource in dll

If you embedded an icon into a dll, how would you get access to it form
inside the dll and return it to the calling app?

I know how to return it, just I cant figure out how to access the embedded
resource in the dll from the dll (which is an icon) i can though figure out
how to get an embedded resource from inside the exe file... what am i doing
wrong?

'Dim oStream As System.IO.Stream
'Dim oAssembly As System.Reflection.Assembly
'Dim sIcon As String
'Dim oBitmap As Drawing.Bitmap
'sIcon =
System.Reflection.Assembly.GetCallingAssembly().Ge tName.Name.ToString() &
"ICON49.ICO"
'oAssembly =
System.Reflection.Assembly.LoadFrom(System.Reflect ion.Assembly.GetCallingAss
embly.ToString)
'oStream = oAssembly.GetManifestResourceStream(sIcon)
'oBitmap = CType(Drawing.Image.FromStream(oStream), Drawing.Bitmap)
'Return sIcon.FromHandle(oBitmap.GetHicon)
even better, how would i get the resource from the dll from the application
exe? i just need to read out some icons.... thanks!
Nov 20 '05 #1
2 4694
Here's how I do it: I have a variable inside the class of type Icon. During the initialization of the class, I extract the embedded icon and set the variable. I'll include a sample class to demonstrate

Say that the DLL project (assembly) name is "MyIcons" and the icon name is "Icon1.ico"..

Imports System.Drawin
Public Class Class
Dim icoMyIcon as Ico

Public Sub New(
icoMyIcon = New Icon(GetType(Class1).Assembly.GetManifestResourceS tream("MyIcons.Icon1.ico")
End Su
End Clas

If you create a new instance of that class from your application that has the MyIcons assembly attached as a reference, you will be able to reference the icoMyIcon object. If an error occurs when you test the app that says something about you cannot use a null value or something, then that means that the string you use when calling the .GetManifestResourceStream method is wrong...either you don't have the icon set as Embedded Resource, or you typed the name wrong in the string, or you didn't include/misspelled the assembly name in the string

If you have any questions, email me

Hope that helps
Be

Nov 20 '05 #2
thanks! that helped a lot

"Ben Coats" <be*******@newberrypathology.com> wrote in message
news:06**********************************@microsof t.com...
Here's how I do it: I have a variable inside the class of type Icon. During the initialization of the class, I extract the embedded icon and set
the variable. I'll include a sample class to demonstrate.
Say that the DLL project (assembly) name is "MyIcons" and the icon name is "Icon1.ico"...
Imports System.Drawing
Public Class Class1
Dim icoMyIcon as Icon

Public Sub New()
icoMyIcon = New Icon(GetType(Class1).Assembly.GetManifestResourceS tream("MyIcons.Icon1.ico")
) End Sub
End Class

If you create a new instance of that class from your application that has the MyIcons assembly attached as a reference, you will be able to reference
the icoMyIcon object. If an error occurs when you test the app that says
something about you cannot use a null value or something, then that means
that the string you use when calling the .GetManifestResourceStream method
is wrong...either you don't have the icon set as Embedded Resource, or you
typed the name wrong in the string, or you didn't include/misspelled the
assembly name in the string.
If you have any questions, email me.

Hope that helps.
Ben

Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: james | last post by:
What class / method should I be using to get the full path to an embedded resource ? In my case I have an .xml file that my app uses, it is set as embedded resource, and I have a control that...
5
by: Drew | last post by:
Assembly asm = Assembly.GetExecutingAssembly(); me = new Bitmap(asm.GetManifestResourceStream("me.gif")); I have used this before without any problem, but now I get: An unhandled exception...
1
by: n! | last post by:
I have an irritating problem with VS.NET2003, C#. I wrote some code that would build my application menu from an XML resource file. Purely to make it easy for me to edit, so I've added this file as...
2
by: Kyle Kaitan | last post by:
I have an assembly (AppResources.dll) which contains a number of embedded resource files. Most of these are key/value pairs of relevant strings; a few are images and sounds; some more are XML...
0
by: ATS | last post by:
HOWTO Make a UserControl deploy an embedded resource. Please help, I need to embed an EXE into a C# UserControl that is run from script in an HTML web page as such: <html> <object...
0
by: Johann Blake | last post by:
I'm having trouble grasping how ASP.NET correctly locates resources. There is plenty of documentation on this subject but some things are not clear at all. In my ASP.NET application, I have...
4
by: Jason Pettys | last post by:
In an ASP.NET project I am setting the content type of my .ascx and ..aspx files to Embedded Resource for a separate reason. When I do this they get embedded as "RootNamespace.Filename" but I...
3
by: raghu sunkara | last post by:
Hi, How Can i Change or Modify Embedded String Resource In An Assembly. I Need To Modify Embedded String Resource In An Assembly. Please Help Me. Thanks Raghu.
2
Frinavale
by: Frinavale | last post by:
I am attempting to use embedded resources in an Ajax Enabled ASP.NET Web Application. I'm using Visual Studio 2008 and VB.NET server side code. The project is called "EmbeddedResources" with the...
2
by: steve | last post by:
I have the following routine for retrieving error message strigs from a resource file which is embedded in the project. But when it is called I get the error messsage "Could not find any...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.