embedded resource in dll

B

Brian Henry

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().GetName.Name.ToString() &
"ICON49.ICO"
'oAssembly =
System.Reflection.Assembly.LoadFrom(System.Reflection.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!
 
G

Guest

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.GetManifestResourceStream("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
 
B

Brian Henry

thanks! that helped a lot

Ben Coats said:
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.GetManifestResourceStream("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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top