PC Review Forums Newsgroups Microsoft DotNet Microsoft Dot NET Compact Framework Re: GetCurrentProcessId import prblem

Reply

Re: GetCurrentProcessId import prblem

 
Thread Tools Rate Thread
Old 08-07-2003, 04:42 PM   #1
Alex Feinman [MVP]
Guest
 
Posts: n/a
Default Re: GetCurrentProcessId import prblem


Both these functions are defined as inline in the SDK. Current process ID
and current process handle are pseudo id and pseudo handle:

_inline HANDLE GetCurrentProcess(void) {
return ((HANDLE)(SH_CURPROC+SYS_HANDLE_BASE));
}

_inline DWORD GetCurrentThreadId(void) {
return ((DWORD)(((HANDLE *)(PUserKData+SYSHANDLE_OFFSET))[SH_CURTHREAD]));
}

_inline DWORD GetCurrentProcessId(void) {
return ((DWORD)(((HANDLE *)(PUserKData+SYSHANDLE_OFFSET))[SH_CURPROC]));

I've put together a sample that shows how to access this information on PPC:

http://www.alexfeinman.com/download.asp?doc=kfuncs.zip

Alex



"Timo Meier" <t.meier@contrigo.de> wrote in message
news:4thqt-6h.ln1@news.dt.contrigo.de...
> Hi, i want to import the following function but i always get an Exception:
> System.MissingMethodException
>
> What is wrong?
>
> [DllImport("coredll.dll")]
>
> public static extern int GetCurrentProcessId();
>
> [DllImport("coredll.dll")]
>
> public static extern int GetCurrentProcess();
>
>
>
>



  Reply With Quote
Old 21-07-2003, 03:34 PM   #2
zeppi
Guest
 
Posts: n/a
Default Re: GetCurrentProcessId import prblem

Alex,

I have tried to use your sample, but have some problems: I get an id,
but
this is a negative number. I use the ID in SetWindowsHookEx, which
fails with a NotSupportedException, and I don't know, if this has
something to do with the ID.

The function for getting the current thread id:

static int GetCurrentThreadID()
{
uint PUserKData = GetCPUArchitecture()
==PROCESSOR_ARCHITECTURE.PROCESSOR_ARCHITECTURE_ARM?
PUserKDataARM:PUserKDataX86;
IntPtr pBase = new IntPtr((int) (PUserKData + SYSHANDLE_OFFSET));
return Marshal.ReadInt32(pBase, SH_CURPROC * 4);
}

PUserKDataARM = 0xFFFFC800, SYSHANDLE_OFFSET = i think 4 in my case.
This is uint. Converting it to int results in a negative number, is
that correct?
Thanks,
Tibor


"Alex Feinman [MVP]" <public_news@alexfeinman.com> wrote in message news:<u93V0$WRDHA.3236@TK2MSFTNGP10.phx.gbl>...
> Both these functions are defined as inline in the SDK. Current process ID
> and current process handle are pseudo id and pseudo handle:
>
> _inline HANDLE GetCurrentProcess(void) {
> return ((HANDLE)(SH_CURPROC+SYS_HANDLE_BASE));
> }
>
> _inline DWORD GetCurrentThreadId(void) {
> return ((DWORD)(((HANDLE *)(PUserKData+SYSHANDLE_OFFSET))[SH_CURTHREAD]));
> }
>
> _inline DWORD GetCurrentProcessId(void) {
> return ((DWORD)(((HANDLE *)(PUserKData+SYSHANDLE_OFFSET))[SH_CURPROC]));
>
> I've put together a sample that shows how to access this information on PPC:
>
> http://www.alexfeinman.com/download.asp?doc=kfuncs.zip
>
> Alex
>
>
>
> "Timo Meier" <t.meier@contrigo.de> wrote in message
> news:4thqt-6h.ln1@news.dt.contrigo.de...
> > Hi, i want to import the following function but i always get an Exception:
> > System.MissingMethodException
> >
> > What is wrong?
> >
> > [DllImport("coredll.dll")]
> >
> > public static extern int GetCurrentProcessId();
> >
> > [DllImport("coredll.dll")]
> >
> > public static extern int GetCurrentProcess();
> >
> >
> >
> >

  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off