Hello Alll,
I am learning windows programming and getting confused more and more..
here is my latest confusion...
What is the relation between processId (which we come to know from the
task manager) and hInstance (which is one of the parameter passed in
the winmain function) of a program?

Or there isn't any relation at all? if yes..why? as both give us the
unique number related to a running program..
Thanks and Regards,
Yogesh Joshi

Re: process Id and HINSTANCE...what is the relation betweeen them? by Jochen

Jochen
Sun Feb 05 11:16:33 CST 2006

Hi yogpjosh!


> What is the relation between processId (which we come to know from the
> task manager)

It does not come from the task-manager... it comes from the OS
(process-manager)

> and hInstance (which is one of the parameter passed in
> the winmain function) of a program?

There is no relation.


> Or there isn't any relation at all? if yes..why? as both give us the
> unique number related to a running program..

hInstance is not a unique number, it is just a "handle" to the EXE...

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/

Re: process Id and HINSTANCE...what is the relation betweeen them? by Mark

Mark
Sun Feb 05 11:19:17 CST 2006

H<anything> is a handle; kind of like an internal pointer to special data in
the system that you cannot access directly.

It can be used via OpenProcess, and get the process ID.


<yogpjosh@gmail.com> wrote in message
news:1139159482.468622.38340@g44g2000cwa.googlegroups.com...
> Hello Alll,
> I am learning windows programming and getting confused more and more..
> here is my latest confusion...
> What is the relation between processId (which we come to know from the
> task manager) and hInstance (which is one of the parameter passed in
> the winmain function) of a program?
>
> Or there isn't any relation at all? if yes..why? as both give us the
> unique number related to a running program..
> Thanks and Regards,
> Yogesh Joshi
>



Re: process Id and HINSTANCE...what is the relation betweeen them? by Scherbina

Scherbina
Sun Feb 05 11:42:18 CST 2006

"Jochen Kalmbach [MVP]" <nospam-Jochen.Kalmbach@holzma.de> wrote in message
news:Ow5jsfnKGHA.140@TK2MSFTNGP12.phx.gbl...
> Hi yogpjosh!
>> What is the relation between processId (which we come to know from the
>> task manager)
>
> It does not come from the task-manager... it comes from the OS
> (process-manager)
>
>> and hInstance (which is one of the parameter passed in
>> the winmain function) of a program?
>
> There is no relation.
>
>
>> Or there isn't any relation at all? if yes..why? as both give us the
>> unique number related to a running program..
>
> hInstance is not a unique number, it is just a "handle" to the EXE...

In other words it's just the address where process is mapped in OS address
space.

>
> --
> Greetings
> Jochen
>
> My blog about Win32 and .NET
> http://blog.kalmbachnet.de/

--
Vladimir



Re: process Id and HINSTANCE...what is the relation betweeen them? by William

William
Sun Feb 05 12:52:29 CST 2006

"Scherbina Vladimir" <vladimir.scherbina@gmail.com> wrote in message
news:%23mWm5snKGHA.744@TK2MSFTNGP09.phx.gbl...
> In other words it's just the address where process is mapped in OS address
> space.

In 32 bit Windows a module's instance handle is its address in the private
address space of the process that loads it. I wonder if the same is true in
64 bit Windows?

Regards,
Will



Re: process Id and HINSTANCE...what is the relation betweeen them? by Jochen

Jochen
Sun Feb 05 13:00:33 CST 2006

Hi William!
>>In other words it's just the address where process is mapped in OS address
>>space.
>
> In 32 bit Windows a module's instance handle is its address in the private
> address space of the process that loads it. I wonder if the same is true in
> 64 bit Windows?

Yes, its the same... why should it be different???

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/

Re: process Id and HINSTANCE...what is the relation betweeen them? by Mark

Mark
Sun Feb 05 13:10:39 CST 2006


"Jochen Kalmbach [MVP]" wrote:>
> Yes, its the same... why should it be different???

It would completely wreck anything compiled for 32 bit pointers id imagine.

- MR



Re: process Id and HINSTANCE...what is the relation betweeen them? by Scherbina

Scherbina
Sun Feb 05 13:46:55 CST 2006

Btw, just noticed that my MSDN (April 2003) states that GetProcessId has the
following prototype:

void GetProcessId(
HANDLE Process
);

:)

--
Vladimir

"Mark Randall" <markyr@gmail.com> wrote in message
news:u1RENhnKGHA.3492@TK2MSFTNGP09.phx.gbl...
> H<anything> is a handle; kind of like an internal pointer to special data
> in the system that you cannot access directly.
>
> It can be used via OpenProcess, and get the process ID.
>
>
> <yogpjosh@gmail.com> wrote in message
> news:1139159482.468622.38340@g44g2000cwa.googlegroups.com...
>> Hello Alll,
>> I am learning windows programming and getting confused more and more..
>> here is my latest confusion...
>> What is the relation between processId (which we come to know from the
>> task manager) and hInstance (which is one of the parameter passed in
>> the winmain function) of a program?
>>
>> Or there isn't any relation at all? if yes..why? as both give us the
>> unique number related to a running program..
>> Thanks and Regards,
>> Yogesh Joshi
>>
>
>



Re: process Id and HINSTANCE...what is the relation betweeen them? by James

James
Sun Feb 05 14:45:36 CST 2006

This must be a new API because it has not existed up til now...
also note the distinction between a HANDLE to a process - which
is a user-mode HANDLE to a kernel PROCESS object, and
a HINSTANCE which is not a handle at all - rather it is a pointer
in thin disguise which points to the base address of the process/DLL -
synonymous with a HMODULE. These last two "handles" are really
just a hang-up from win16 days.

James

--
Microsoft MVP - Windows SDK
www.catch22.net
Free Win32 Source and Tutorials


"Scherbina Vladimir" <vladimir.scherbina@gmail.com> wrote in message
news:OfV6iyoKGHA.2696@TK2MSFTNGP14.phx.gbl...
> Btw, just noticed that my MSDN (April 2003) states that GetProcessId has
> the following prototype:
>
> void GetProcessId(
> HANDLE Process
> );
>
> :)
>
> --
> Vladimir
>
> "Mark Randall" <markyr@gmail.com> wrote in message
> news:u1RENhnKGHA.3492@TK2MSFTNGP09.phx.gbl...
>> H<anything> is a handle; kind of like an internal pointer to special data
>> in the system that you cannot access directly.
>>
>> It can be used via OpenProcess, and get the process ID.
>>
>>
>> <yogpjosh@gmail.com> wrote in message
>> news:1139159482.468622.38340@g44g2000cwa.googlegroups.com...
>>> Hello Alll,
>>> I am learning windows programming and getting confused more and more..
>>> here is my latest confusion...
>>> What is the relation between processId (which we come to know from the
>>> task manager) and hInstance (which is one of the parameter passed in
>>> the winmain function) of a program?
>>>
>>> Or there isn't any relation at all? if yes..why? as both give us the
>>> unique number related to a running program..
>>> Thanks and Regards,
>>> Yogesh Joshi
>>>
>>
>>
>
>



Re: process Id and HINSTANCE...what is the relation betweeen them? by Vipin

Vipin
Sun Feb 05 14:49:07 CST 2006

Each Process has an internal data structure in the system space
known as the executive process block which contains a field for
the Process ID. The Executive process block also has a pointer
to the handle table. So HANDLE you see for apis are nothing but
indices into the handle table maintained in the system space and
they increments in the order of 4,8,12,... like that. Try opening a
couple of handles in a program to get the feel on the increments.

So when someone does a CreateProcess(...), the handle is in fact
a index into the local processes handle table which internally would
point to the relevant system data structures.

So the conculsion is that HANDLE is process specific while process id
of a given process will always remain the same thoughout. You can
different handles to a process using OpenProcess(...) twice or thrice.

HMODULE you get from GetModuleHandle(NULL,..) is in fact the load address
of the
image. If I remember right, the hInstance that comes in the winmain willbe
the same as
the GetModuleHandle(NULL,...)

--
Vipin Aravind

"Scherbina Vladimir" <vladimir.scherbina@gmail.com> wrote in message
news:OfV6iyoKGHA.2696@TK2MSFTNGP14.phx.gbl...
> Btw, just noticed that my MSDN (April 2003) states that GetProcessId has
> the following prototype:
>
> void GetProcessId(
> HANDLE Process
> );
>
> :)
>
> --
> Vladimir
>
> "Mark Randall" <markyr@gmail.com> wrote in message
> news:u1RENhnKGHA.3492@TK2MSFTNGP09.phx.gbl...
>> H<anything> is a handle; kind of like an internal pointer to special data
>> in the system that you cannot access directly.
>>
>> It can be used via OpenProcess, and get the process ID.
>>
>>
>> <yogpjosh@gmail.com> wrote in message
>> news:1139159482.468622.38340@g44g2000cwa.googlegroups.com...
>>> Hello Alll,
>>> I am learning windows programming and getting confused more and more..
>>> here is my latest confusion...
>>> What is the relation between processId (which we come to know from the
>>> task manager) and hInstance (which is one of the parameter passed in
>>> the winmain function) of a program?
>>>
>>> Or there isn't any relation at all? if yes..why? as both give us the
>>> unique number related to a running program..
>>> Thanks and Regards,
>>> Yogesh Joshi
>>>
>>
>>
>
>



Re: process Id and HINSTANCE...what is the relation betweeen them? by William

William
Sun Feb 05 16:12:56 CST 2006

"Jochen Kalmbach [MVP]" <nospam-Jochen.Kalmbach@holzma.de> wrote in message
news:OD8lzZoKGHA.1236@TK2MSFTNGP10.phx.gbl...
>>>In other words it's just the address where process is mapped in OS
>>>address space.
>>
>> In 32 bit Windows a module's instance handle is its address in the
>> private address space of the process that loads it. I wonder if the same
>> is true in 64 bit Windows?
>
> Yes, its the same... why should it be different???

As I see it, "instance handle" and "module base address" are not correlated,
a priori, except by force of Win32 tradition. I wondered if the tradition
would be carried forward.

Now I know. Thanks.

Regards,
Will



Re: process Id and HINSTANCE...what is the relation betweeen them? by Carl

Carl
Mon Feb 06 05:14:55 CST 2006

GetProcessId was issued as part of XP SP1, so it has been round for quite a
long time.

It works by calling NtQueryInformation querying ProcessBasicInformation. The
fifth element of the PROCESS_BASIC_INFORMATION structure is the unique
process id.

Carly

"James Brown" <not@home> wrote in message
news:gZKdneVMJbtt_nveRVnyiA@pipex.net...
> This must be a new API because it has not existed up til now...
> also note the distinction between a HANDLE to a process - which
> is a user-mode HANDLE to a kernel PROCESS object, and
> a HINSTANCE which is not a handle at all - rather it is a pointer
> in thin disguise which points to the base address of the process/DLL -
> synonymous with a HMODULE. These last two "handles" are really
> just a hang-up from win16 days.
>
> James
>
> --
> Microsoft MVP - Windows SDK
> www.catch22.net
> Free Win32 Source and Tutorials
>
>
> "Scherbina Vladimir" <vladimir.scherbina@gmail.com> wrote in message
> news:OfV6iyoKGHA.2696@TK2MSFTNGP14.phx.gbl...
>> Btw, just noticed that my MSDN (April 2003) states that GetProcessId has
>> the following prototype:
>>
>> void GetProcessId(
>> HANDLE Process
>> );
>>
>> :)
>>
>> --
>> Vladimir
>>
>> "Mark Randall" <markyr@gmail.com> wrote in message
>> news:u1RENhnKGHA.3492@TK2MSFTNGP09.phx.gbl...
>>> H<anything> is a handle; kind of like an internal pointer to special
>>> data in the system that you cannot access directly.
>>>
>>> It can be used via OpenProcess, and get the process ID.
>>>
>>>
>>> <yogpjosh@gmail.com> wrote in message
>>> news:1139159482.468622.38340@g44g2000cwa.googlegroups.com...
>>>> Hello Alll,
>>>> I am learning windows programming and getting confused more and more..
>>>> here is my latest confusion...
>>>> What is the relation between processId (which we come to know from the
>>>> task manager) and hInstance (which is one of the parameter passed in
>>>> the winmain function) of a program?
>>>>
>>>> Or there isn't any relation at all? if yes..why? as both give us the
>>>> unique number related to a running program..
>>>> Thanks and Regards,
>>>> Yogesh Joshi
>>>>
>>>
>>>
>>
>>
>
>



Re: process Id and HINSTANCE...what is the relation betweeen them? by Jugoslav

Jugoslav
Mon Feb 06 05:58:59 CST 2006

yogpjosh@gmail.com wrote:
| Hello Alll,
| I am learning windows programming and getting confused more and more..
| here is my latest confusion...
| What is the relation between processId (which we come to know from the
| task manager) and hInstance (which is one of the parameter passed in
| the winmain function) of a program?
|
| Or there isn't any relation at all? if yes..why? as both give us the
| unique number related to a running program..

To summarize:
HINSTANCE = HMODULE is the "module handle". Although a handle, generally,
is an opaque thingo, in this case it physically represents the address
in process's address space where a module (.exe or .dll) is loaded. (Not
that you should rely on that piece of data). An .exe always has a
hinstance of 0x00400000 in Win32, and dll's have different ones. It is
useful in e.g. resource-handling functions -- basically, e.g.

LoadBitmap(hInstance, IDB_MYBITMAP)

says: "Take a look in the module(image) starting at hInstance, and find
me the bitmap embedded somewhere in there".
HINSTANCEs/HMODULEs are, thus, process private, and you can't "peek"
into another's process's virtual address space and find one (nor it
would be useful even if you could) -- both e.g. explorer.exe and
winword.exe are loaded at the same 0x00400000 *from their point of view*,
but they can't "peek" into each other (unless with "heavy artilery" like
ReadProcessMemory).

DWORD processid is an "unique ID" of a process on the system. You can
do little with that piece of data per se, except...

...HANDLE hProcess is a handle to a process which gives you control over
(in general, another) a process. You obtain it by OpenProcess(...ProcessId)
and with that handle you can TerminateProcess, GetExitCodeProcess or
even ReadProcessMemory or WriteProcessMemory, provided you have sufficient
access rights. [Disclaimer: Don't do that while you're still a beginner].

--
Jugoslav
___________
www.xeffort.com

Please reply to the newsgroup.
You can find my real e-mail on my home page above.

Re: process Id and HINSTANCE...what is the relation betweeen them? by Matt

Matt
Mon Feb 06 08:32:41 CST 2006

Jugoslav Dujic wrote:
> yogpjosh@gmail.com wrote:
> | Hello Alll,
> | I am learning windows programming and getting confused more and more..
> | here is my latest confusion...
> | What is the relation between processId (which we come to know from the
> | task manager) and hInstance (which is one of the parameter passed in
> | the winmain function) of a program?
> |
> | Or there isn't any relation at all? if yes..why? as both give us the
> | unique number related to a running program..
>
> To summarize:
> HINSTANCE = HMODULE is the "module handle". Although a handle, generally,
> is an opaque thingo, in this case it physically represents the address
> in process's address space where a module (.exe or .dll) is loaded. (Not
> that you should rely on that piece of data).

According to this article by Raymond Chen you can rely on it:

http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx

Matt

Re: process Id and HINSTANCE...what is the relation betweeen them? by Ben

Ben
Mon Feb 06 08:47:33 CST 2006

wrote in message
news:1139159482.468622.38340@g44g2000cwa.googlegroups.com...
> Hello Alll,
> I am learning windows programming and getting confused more and more..
> here is my latest confusion...
> What is the relation between processId (which we come to know from the
> task manager) and hInstance (which is one of the parameter passed in
> the winmain function) of a program?
>
> Or there isn't any relation at all? if yes..why? as both give us the
> unique number related to a running program..

The relation is: the HINSTANCE, like all handles, is an indirection to the
process, valid within the running application. The process ID is a globally
unique identifier. You can switch between them using:
DWORD GetProcessId(HANDLE Process);
HANDLE OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD
dwProcessId);


> Thanks and Regards,
> Yogesh Joshi
>



Re: process Id and HINSTANCE...what is the relation betweeen them? by Carl

Carl
Mon Feb 06 09:52:55 CST 2006

> The relation is: the HINSTANCE, like all handles, is an indirection to the
> process, valid within the running application.

The HINSTANCE is the load address of module, be it .exe, .dll and so on. It
has nothing to do with the process apart from the fact that the module is
loaded in the process address space. Processes do need to have modules
loaded in to the address space, the section object for the executable
(Notepad.exe for example) is an argument to
NtCreateProcess/NtCreateProcessEx and both it and Ntdll.dll are mapped into
the process address space during process creation.

The HINSTANCE is not a handle either, not strictly speaking anyway. It is
the base address for the mapped view of a section object. Handles to section
objects do exist in the handle table for the process and for executable
images. The load address and section object are linked in that the section
object describes executable mapping options, the preferred load address
being just one of them.

Carly

The process ID is a globally
> unique identifier. You can switch between them using:
> DWORD GetProcessId(HANDLE Process);
> HANDLE OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD
> dwProcessId);
>
>
>> Thanks and Regards,
>> Yogesh Joshi
>>
>
>