How can I detirmen what kind of handle hHandle is? (Window handle, File handle, ect...) Is there some kind of API for this?
How can I detirmen what kind of handle hHandle is? (Window handle, File handle, ect...) Is there some kind of API for this?
From the function which returned it in the first place?
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
No, I know nothing about this handle only that it exists and that it is valid.
There are no API's to reference the Windows internal representation of a handle. There is no need to reference the internal representation. You give Windows the handle and Windows locates the data associated with the handle. Handles are just a way to reference items that are managed by the OS.
But anyway there are 13 different handle types defined in windows.h. So, you have a 1 out 13 chance of getting the right handle type.
There is more than thirteen:
HBITMAP
HBRUSH
HCOLORSPACE
HDC
HDESK
HFONT
HICON
HKEY
HMONITOR
HTERMINAL
HWINEVENTHOOK
HMENU
HMETAFILE
HINSTANCE
HPEN
HTASK
HWND
These are just a few of the kind I would want, there are a lot more though.
To check if it is a HWND, I try to use SendMessage() but that doesn't work.
And SetPixel() doesn't seem to work for HDCs.
The only way out is to make your own function...
Also the best way to check if it's a HWND is IsWindow().
Also your list doesn't have HANDLE in it.
"The Internet treats censorship as damage and routes around it." - John Gilmore
I knew there was somthing like that, thats I thought there might be a IsBitmap() func.
Plus HANDLE may be different things...
"The Internet treats censorship as damage and routes around it." - John Gilmore
I stand corrected. I misread Dr. Newcomer's detailed description on the concept of handles in his Win32 Programming book. Per his description there are actually 26 handles defined in windows.hThere is more than thirteen
You can differentiate between GDI object handles using the GetObjectType function.
Do you know the HMODULE of the owner process?
It seems to me that HMODULE and HINSTANCE are the same things... sometimes I use GetModuleHandle() to get the HINSTANCE for some controls in my program...
I'll try to complete this list
HWND - IsWindow()
HPEN,HDC,HMETAFILE,HBRUSH,HBITMAP,HFONT,HMETAFILE, HENHMETAFILE,HPALETTE,HRGN - GetObjectType()
HCOLORSPACE - GetLogColorSpace()
HPROFILE - GetColorProfileHeader()
HMONITOR - GetMonitorInfo()
HINSTANCE - OpenProcess() (GetLastError() should mention that the process doesn't exist...)
HICON - GetIconInfo()
HTASK - IsTask() ?? This seems to be a very old handle type... maybe from Win 3.x? IsTask() at least existed before Win95
HMENU - GetMenuInfo()
HDESK,HWINSTA - GetUserObjectInformation()
HTERMINAL - MSDN search says nothing, it's defined, but I couldn't find any functions for it...
HWINEVENTHOOK- IsWinEventHookInstalled()
HACCEL - TranslateAccelerator()
HGLRC - wglMakeCurrent()
HKEY - RegQueryInfoKey()
HRSRC - SizeOfResource()
HKL - ActivateKeyboardLayout() (Couldn't find a better one...)
HFILE - GetFileSize() (usually used just as HANDLE)
HCURSOR - CopyCursor()
And then you make a function that basically checks them all.
Last edited by maxorator; 01-07-2007 at 11:38 AM.
"The Internet treats censorship as damage and routes around it." - John Gilmore
You shouldn't ever have any ambiguity problems in the first place except for kernel object HANDLEs. Everything else has a distinct type, and you damn well shouldn't cast it in a way that this type information is lost.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
Oh no, I would never loose my handle type inside of my own code. The thing is, this handle belongs to another process.Originally Posted by CornedBee
I don't understand this fascination with manipulating other processes. So many questions are about it. I've seen ReadProcessMemory() so often, but only on boards such as this one. People want to enumerate other apps' windows, find their windows, close the processes, start them, turn them inside out and upside down, inject code, extract data, do this and that ...
... and all the time I keep asking myself, why??? Isn't is much more satisfying to write a beautiful program of your own rather than messing with other programs?
Sorry, I needed that rant. Don't take it too personal.
How did you find the handle in the other process? Shouldn't the place where you found it give you a hint what it is?
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law