Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / How do i get the darkbasic hInstance?

Author
Message
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 8th Apr 2009 04:00
Ok i was going to try and use winAPI to change the icon of the db window. but i need the hInstance of the exe to load the icon.

Does anyone know the function to get it?i know it's possible i just can't find it on msdn.

New Site! Check it out \/
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 8th Apr 2009 04:17
use GetModuleFileName to return the filename and path of DB.exe and store it in a string pointer.

Then use GetModuleHandle with the string pointer from the previous call to retrieve the hinstance.

Enjoy your day.
Benjamin
22
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 8th Apr 2009 04:33
Actually, it is sufficient to simply call GetModuleHandle and pass NULL.

Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 8th Apr 2009 04:51 Edited at: 8th Apr 2009 04:57
Actually i found something that should be working but i'm getting a error "Dll call failed to execute"

I am using GetWindowLong and Specifying the handle to the db window and then using GWL_HINSTANCE parameter to return the instnance but it is coming up with that error.

heres the code



I will try your ideas though.


Latch:

When you say "String pointer" do you mean in ascii form in a memblock? i'm geussing since thats the only way to get a pointer to anything in db lol.

Edit
What dll is GetModuleFileName and GetModuleHandle in? i tried it in user32 and it's saying it doesn't exist?

New Site! Check it out \/
Benjamin
22
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 8th Apr 2009 05:26
GetModuleHandle

Search MSDN for the functions you need information on, that's what I do. As for LoadImage, the actual function name you want is LoadImageA.

Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 8th Apr 2009 06:33
I couldn't find it on msdn. well i did but it said it couldn't be found lol

ya i just search msdn also lol

Quote: "As for LoadImage, the actual function name you want is LoadImageA."


Oh thanks! ussually you don't need to inlude the A/W at the end of the functions.

New Site! Check it out \/
Benjamin
22
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 8th Apr 2009 07:49
The A/W is only required in functions that take string arguments (A = ANSI, W = UNICODE).

Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 8th Apr 2009 18:19
Oh ok thanks!

New Site! Check it out \/
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 8th Apr 2009 23:09
@Caleb
If you are trying to just change the icon of an exe you are distributing, you could use something like reshack

Or if you still want to use the winapi, you don't actually need the hinstance if you are trying to replace the icon with one you are loading from disk. If the icon is the resource of another exe or dll then you would need the hinst of that exe or dll. You don't need the hinst of the DB.exe that you want to change.

First get hwnd : GetActiveWindow
If loading the image or icon from disk, you need to create a handle for the icon with LoadImageA . Then use SetClassLongA to change the icon of hwnd with the handle of the icon.

Enjoy your day.
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 8th Apr 2009 23:44
I tried ResHack but after i changed it the exe didn't run lol

the reason i was trying to get the hInstance was cuz LoadImageA called for the Instance of the window. so i thought it was required.

I'll try it with null though. and with resHack you would have to change it with every exe you build you have to change it. using winapi it's built in and you don't need to thats my oppinion though

New Site! Check it out \/
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 9th Apr 2009 01:30
LoadImage requires the hinstance when you wish to GRAB an icon FROM an application or DLL. Let's say you wanted to change DBs icon to IE explorer's. In this case, you'd need IE explorer's hinstance so you can get the handle of the icon resource you want to add to DB. Once you have the handle of the icon, you use SetClassLongA to change the icon of the DB app using the icon handle.

LoadImage does not require an hinstance if you are loading the resource directly from disk. If you have a file named myicon.ico in a folder, you don't need an hinstance with LoadImageA. You load the icon into memory and assign it a handle - there is no application (no hinstance) that you need to take a copy of the icon from. Understand the difference? LoadImage doesn't load the icon into your app, it just creates or retrieves a pointer (handle) to the image that your apps can use.

Enjoy your day.
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 9th Apr 2009 06:16
Oh Ok! thanks that clears up a lot thanks!

New Site! Check it out \/
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 14th May 2009 19:43 Edited at: 14th May 2009 19:47
edited out.... i'm dumb

New Site! Check it out \/

Login to post a reply

Server time is: 2025-06-08 05:35:27
Your offset time is: 2025-06-08 05:35:27