Retrieval of hInstance ??
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by michaelj.
Hi,
I'm wondering if PureBasic has a way of getting to the application instance, known as hInstance in most win API code.
I've used the API call I found elsewhere which is :
hInstance = GetModuleHandle_(0)
... but I'm wondering if there's an easier way ??
Thanks.
Michael.
(Registered PureBasic user)
Hi,
I'm wondering if PureBasic has a way of getting to the application instance, known as hInstance in most win API code.
I've used the API call I found elsewhere which is :
hInstance = GetModuleHandle_(0)
... but I'm wondering if there's an easier way ??
Thanks.
Michael.
(Registered PureBasic user)
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by michaelj.
I realise it's very simple as stands. I was thinking more along the lines of a PureBasic constant or something, as the hInstance is passed in (I believe) in the WinMain which PureBasic is wrapping, and so it would be neat to have it available without any extra method calls.
Just a thought really.
Danilo:
Can you use that within PureBasic Code as is ?? That would be very useful !
Michael.
(Registered PureBasic user)
Edited by - michaelj on 30 January 2002 08:55:36
Hi PB.> I'm wondering if there's an easier way ??
Maybe I'm missing the point, but what can be shorter and easier than the tiny
API example you just posted? Or is your app destined for Amiga/Linux ports?
I realise it's very simple as stands. I was thinking more along the lines of a PureBasic constant or something, as the hInstance is passed in (I believe) in the WinMain which PureBasic is wrapping, and so it would be neat to have it available without any extra method calls.
Just a thought really.
Danilo:
Can you use that within PureBasic Code as is ?? That would be very useful !
Michael.
(Registered PureBasic user)
Edited by - michaelj on 30 January 2002 08:55:36
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by El_Choni.
You can use this, no calls:
Bye,
El_Choni
You can use this, no calls:
Code: Select all
Instance.l
!push dword [_PB_Instance]
!pop dword [v_Instance]
El_Choni
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Franco.
Maybe somebody can lighten my brain cells:
I thought that an Instance is the OS process number for the opened application. Isn't it?
But if I make a little test code like:
Every time I call this app I get always the number: 4194304 (Win98SE)
Every time I call this app it is another process and it should have another number or not?
Even if I call the compiled application twice: every app has the same number.
But the second application is another process, isn't it?
What is wrong in my thoughts though?
Have a nice day...
Franco
Sometimes you have to go a lonely way to accomplish genius things.
Edited by - franco on 30 January 2002 16:59:23
Maybe somebody can lighten my brain cells:
I thought that an Instance is the OS process number for the opened application. Isn't it?
But if I make a little test code like:
Code: Select all
If OpenWindow(0, 200, 200, 320,240, #PB_Window_SystemMenu ,"Test Window")
;method 1
hInstance = GetModuleHandle_(0) ;<- only for a double check
;method 2
Instance.l
!push dword [_PB_Instance]
!pop dword [v_Instance]
; double check if the numbers are the same... they have to!
; only for checking both methods...
MessageRequester(Str(hInstance),Str(Instance),0)
Repeat
EventID.l = WaitWindowEvent()
Until EventID = #PB_EventCloseWindow
EndIf
Every time I call this app it is another process and it should have another number or not?
Even if I call the compiled application twice: every app has the same number.
But the second application is another process, isn't it?
What is wrong in my thoughts though?
Have a nice day...
Franco
Sometimes you have to go a lonely way to accomplish genius things.
Edited by - franco on 30 January 2002 16:59:23
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by PB.
> Every time I call this app I get always the number: 4194304 (Win98SE)
I get the same number on Win 2000.
Off-topic note: the new Debug command in PureBasic means you don't need
to open a window and use a message box anymore to test things... for example,
your code above can be reduced to this shorter snippet:
Just for your information.
PB - Registered PureBasic Coder
> Every time I call this app I get always the number: 4194304 (Win98SE)
I get the same number on Win 2000.
Off-topic note: the new Debug command in PureBasic means you don't need
to open a window and use a message box anymore to test things... for example,
your code above can be reduced to this shorter snippet:
Code: Select all
hInstance = GetModuleHandle_(0)
Instance.l
!push dword [_PB_Instance]
!pop dword [v_Instance]
Debug Str(hInstance)+","+Str(Instance)
Delay(9999)
PB - Registered PureBasic Coder
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by El_Choni.
But, guys, this is cool! So we don't have to bother about hInstance anymore, we can use always 4194304. Fred, why don't you add it as a built-in constant? #hInstance = 4194304 XXDDDDDDDDD
Bye,
PS: I think the process identifier must be retrieved with GetStartupInfo_() or GetCurrentProcess_(), but I'm not sure since I lost all my docs (sigh!)
El_Choni
But, guys, this is cool! So we don't have to bother about hInstance anymore, we can use always 4194304. Fred, why don't you add it as a built-in constant? #hInstance = 4194304 XXDDDDDDDDD
Bye,
PS: I think the process identifier must be retrieved with GetStartupInfo_() or GetCurrentProcess_(), but I'm not sure since I lost all my docs (sigh!)
El_Choni
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by fred.
Fred - AlphaSND
Hum hum . Never do that. If I change one line in the PureBasic startup code you app will crashs.But, guys, this is cool! So we don't have to bother about hInstance anymore, we can use always 4194304. Fred, why don't you add it as a built-in constant? #hInstance = 4194304 XXDDDDDDDDD
Fred - AlphaSND
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Franco.
Fred, do you say that every application coded with PureBasic has the same Instance # ?
What is this all about? I don't get it.
If somebody has 2 different programs running (both coded with PureBasic) both would have the same Instance #.
So if you want to catch/work with the right program you need the Instance and the MainWindowHandle?
So the Instance # is not the OS process #?
Is this the same under Linux/Amiga others?
I feel so klutzy with the amount of the above questions... sorry
Have a nice day...
Franco
Sometimes you have to go a lonely way to accomplish genius things.
Fred, do you say that every application coded with PureBasic has the same Instance # ?
What is this all about? I don't get it.
If somebody has 2 different programs running (both coded with PureBasic) both would have the same Instance #.
So if you want to catch/work with the right program you need the Instance and the MainWindowHandle?
So the Instance # is not the OS process #?
Is this the same under Linux/Amiga others?
I feel so klutzy with the amount of the above questions... sorry
Have a nice day...
Franco
Sometimes you have to go a lonely way to accomplish genius things.
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by michaelj.
4194304 is the same for any win32 application. The module handle represents the location in memory where the application is loaded. Because win32 has a unique address space for each application, they are all loaded at the same place (as far as they are concerned), hence the same value.
If you were to run win16 applications, then they would be different.
This does mean that you can't check for multiple instances using the module handle (although you could FindWindow, or use mutexes).
Here endeth the lesson for the day (At least, I think that's right !).
Michael.
(Registered PureBasic user)
Okay, after a bit of research, I learnt something ;o)Fred, do you say that every application coded with PureBasic has the same Instance # ?
What is this all about? I don't get it.
If somebody has 2 different programs running (both coded with PureBasic) both would have the same Instance #.
So if you want to catch/work with the right program you need the Instance and the MainWindowHandle?
So the Instance # is not the OS process #?
4194304 is the same for any win32 application. The module handle represents the location in memory where the application is loaded. Because win32 has a unique address space for each application, they are all loaded at the same place (as far as they are concerned), hence the same value.
If you were to run win16 applications, then they would be different.
This does mean that you can't check for multiple instances using the module handle (although you could FindWindow, or use mutexes).
Here endeth the lesson for the day (At least, I think that's right !).
Michael.
(Registered PureBasic user)