|
-
Aug 17th, 2002, 10:58 PM
#1
Thread Starter
Frenzied Member
hInstance
how do i get the hInstance for my app..? i know it can be done because i need it to load a image from a resource file.
Magiaus
If I helped give me some points.
-
Aug 20th, 2002, 05:47 PM
#2
Member
There are two ways to do that:
1: Using managed Namespaces
This command returns what meant to be App.hInstance.
System.Runtime.InteropServices.Marshal.GetHINSTANCE(System.Reflection.Assembly.GetExecutingAssembly. GetModules()(0)).ToInt32
GetModules returns an array of all existing modules in your assembly, I select the first one, but you must check that what's appropriate for you. Remember that GetModules has another version that accepts a Boolean value and filters resource modules.
Also you can use GetModule instead of GetModules and specify your module filename.
2:Using Unmanaged Namespaces
There is a .Net library that provides some compatibility with Visual Basic 6. Add the Microsoft.VisualBasic.Compatibility.dll to references of your project and use this command:
Microsoft.VisualBasic.Compatibility.VB6.GetHInstance().ToInt32
Remember that using this library is not recommended by Microsoft so use it only when you have to. Why don't use the managed Namespaces anyway? They are safer, faster and provide a lot of more features.
Finally, sorry to interfere, dude, but if you wanna load an image that your assembly - read executable file - contains, why you don't use the resources like a good boy, Huh?
Good luck.
-
Aug 21st, 2002, 09:18 PM
#3
Thread Starter
Frenzied Member
ok, well i am but it wanted an hinstance. i don't have the code any longer or i would tell you the exact function was using but it was FromResource(hinstance, id)
Magiaus
If I helped give me some points.
-
Aug 21st, 2002, 09:21 PM
#4
Thread Starter
Frenzied Member
and honestly
i feel stupid because i was trying to find out how to get it and i was wondering if i was going to have to do some off the wall api with GetModule and i never thought to search for a GetModule i did hInstance and app.hinstance
oh well
thanks
Magiaus
If I helped give me some points.
-
Aug 21st, 2002, 11:16 PM
#5
Frenzied Member
C# Version
Code:
// Make a ResourceManager
ResourceManager resources = new ResourceManager (typeof(MainForm));
// Read happy dude from assembly and place it
// into the PictureBox object.
this.pictureBox2.Image = ((System.Drawing.Bitmap)(resources.GetObject("pictureBox1.Image")));
// All done!
resources.ReleaseAllResources();
This is how its done in C#. It should be similar in VB.NET.
Dont gain the world and lose your soul
-
Aug 21st, 2002, 11:22 PM
#6
Thread Starter
Frenzied Member
ah i remember now
it was System.Drawing.Bitmap.FromResource(hInstance,ID)
thanks
Magiaus
If I helped give me some points.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|