Click here to Skip to main content
14,930,722 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
how can i get my current process handle?

the function GetCurrentProcess return
C#
The return value is a pseudo handle to the current process.


that is it allways return "pseudo handle is a special constant, currently (HANDLE)-1 => 0xFFFFFFFF" (MSDN)

using the code with OpenProcess:

ASM
DWORD pid = GetCurrentProcessId();
HANDLE hProcess2 = OpenProcess(0, FALSE, pid);


return NULL

so i can get the real handle?:confused:

when i used

HANDLE hProcess2 = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);

it looks to work but how can i be sure becuase when i try to use the handle in the VirtualLock i allways get error.
Posted
Updated 21-Aug-10 21:47pm
v2

What error does VirtualLock return? Unless it's something like "invalid process handle" then it could be something else going wrong like you're trying to lock too much address space.

To be honest VirtualLock is probably one of the more useless functions in the Win32. All it says is "I may, if I'm feeling generous, guarentee not to invalidate this page" which isn't stunning endorsement of the functions utility. And even if you get your pages to lock remember to profile your app to see if it actually makes any sort of difference to it's performance.

Cheers,

Ash
   
Comments
pascal.schwartz 22-Aug-10 11:24am
   
Hi The Error is 'Insufficient quota to complete the requested service'
it looks like the OpenProcess works ok after but the problem is really VirtualLock.
i need to lock about 2giga of memory in the physical memory (using x64 pc with 6 giga ) to pass it to me driver (where it will fill it with data from the PCI board).
could help me with that? is there any other way more promising to acomplish the task?
Aescleal 22-Aug-10 12:48pm
   
Not surprised that VirtualLock is failing - it generally only lets you lock ~32 pages at any one time (it might be more in Vista and Windows 7).

You don't need to lock memory to pass it to a driver. I'd really suggest looking up how drivers work - you'll need to do all the address translation within the driver. To be honest I'm not sure if you're going to get away with such a big lump of reserved driver memory as 2Gb - all the drivers I've written have reserved small buffers so it's outside of my experience.

Good luck and sorry I can't be anymore help.

Ash
Why dont you try using a real handle rather than the pseudo handle returned by the GetCurrentProcess. Create a handle using the function DuplicateHandle
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900