Find object's method and

M

Mr. X.

I have the classname and the windows' handle of an object.
I want to know all the list of methods of the class of the above (some
APIs), and all of its exposed properties.
(Maybe by some reflections functions ...)

Thanks :)
 
M

Marcel Müller

I have the classname and the windows' handle of an object.
I want to know all the list of methods of the class of the above (some
APIs), and all of its exposed properties.
(Maybe by some reflections functions ...)

Type.GetType(string) is your friend.


Marcel
 
M

Marcel Müller

When I do : Type.GetType(<myClassName>) I get null value.

Did you forget the namespace?
Is your class already loaded? (Static constructor has run.)


Marcel
 
M

Mr. X.

I have only the handle+name (there is application outside C#, and I have
only the handle of the class).

"Marcel Müller" wrote in message

When I do : Type.GetType(<myClassName>) I get null value.

Did you forget the namespace?
Is your class already loaded? (Static constructor has run.)


Marcel
 
M

Mr. X.

I found:
Type.GetTypeFromHandle(h)
h should be hwnd, but what if I need to convert it from IntPtr - How can I
convert IntPtr to hwnd type?

Thanks :)


"Mr. X." wrote in message
I have only the handle+name (there is application outside C#, and I have
only the handle of the class).

"Marcel Müller" wrote in message

When I do : Type.GetType(<myClassName>) I get null value.

Did you forget the namespace?
Is your class already loaded? (Static constructor has run.)


Marcel
 
M

Mr. X.

Sorry h is RuntimeTypeHandle
Anyway - conversion is needed.
Thanks :)

"Mr. X." wrote in message
I found:
Type.GetTypeFromHandle(h)
h should be hwnd, but what if I need to convert it from IntPtr - How can I
convert IntPtr to hwnd type?

Thanks :)


"Mr. X." wrote in message
I have only the handle+name (there is application outside C#, and I have
only the handle of the class).

"Marcel Müller" wrote in message

When I do : Type.GetType(<myClassName>) I get null value.

Did you forget the namespace?
Is your class already loaded? (Static constructor has run.)


Marcel
 
M

Mr. X.

Ok.
The code look like :
....
[DllImport("user32.dll", EntryPoint = "MessageBoxA")]
static extern int MsgBox(int hWnd,
string msg,
string caption,
int type);
....
public static bool WindowEnumProc(IntPtr hwnd, int lParam)
{
RuntimeTypeHandle hh;
Type t;
PropertyInfo[] pi;
object o;

hh = Type.GetTypeHandle(hwnd);
t = Type.GetTypeFromHandle(hh);

pi = t.GetProperties();

for (int i = 0; i < pi.Length; i++)
{
propName = pi.ElementAt(i).Name;
p = t.GetProperty(propName);
o = p.GetValue(hwnd, null);
MsgBox(0, text + ".." + propName + ".." + o.ToString(),
"property", 0);
}

// there is only one property exposed (for my case is: Size, and always =
4).
// For my concusion for now, a control doesn't necessaraly expose all of
it's child controls or properties ...


"Mr. X." wrote in message
Sorry h is RuntimeTypeHandle
Anyway - conversion is needed.
Thanks :)

"Mr. X." wrote in message
I found:
Type.GetTypeFromHandle(h)
h should be hwnd, but what if I need to convert it from IntPtr - How can I
convert IntPtr to hwnd type?

Thanks :)


"Mr. X." wrote in message
I have only the handle+name (there is application outside C#, and I have
only the handle of the class).

"Marcel Müller" wrote in message

When I do : Type.GetType(<myClassName>) I get null value.

Did you forget the namespace?
Is your class already loaded? (Static constructor has run.)


Marcel
 
M

Marcel Müller

I found:
Type.GetTypeFromHandle(h)
h should be hwnd, but what if I need to convert it from IntPtr - How can
I convert IntPtr to hwnd type?

Ehm...
I think you are really confusing things. A managed class type *never*
has a window handle (hwnd) and vice versa.
Are you talking about a *window* class? If yes, then you will not be
able to use reflections. Window classes respond to window messages in a
certain way. But you cannot examine this behavior by reflection. All you
have is the class name. And either you know what it is doing or not.
There are some exceptions if you have COM windows.


Marcel
 
M

Mr. X.

As my previous post (see the following code on C# again), I overcome the
problem of converting IntPtr to RuntimeTypeHandle (it's RuntimeTypeHandle.
not hwnd, and now, that I have the handle of that class - It make scenes,
because when I get its class name, by WinAPI: GetClassNameW, I get the class
name I expected).

I have the control's handle (the following code, get a hwnd as IntPtr input
parameter).
The code uses reflection, but what I have found nothing special - only one
property (maybe, by mistake, or something default : size, that has the
length of 4).
As I stated on previous post, I think a control doesn't necessarily expose
all of its properties - but when it does?
What should be necessary that I can use reflection to a specific control?

(The goal is - There is a 3rd-party class, I don't know nothing about it,
but I need to change some of it's elements).

public static bool WindowEnumProc(IntPtr hwnd, int lParam)
{
RuntimeTypeHandle hh;
Type t;
PropertyInfo[] pi;
object o;

hh = Type.GetTypeHandle(hwnd);
t = Type.GetTypeFromHandle(hh);

pi = t.GetProperties();

for (int i = 0; i < pi.Length; i++)
{
propName = pi.ElementAt(i).Name;
MessageBox.Show(propName, "property name");
p = t.GetProperty(propName);
o = p.GetValue(hwnd, null);
MessageBox.Show(text + ".." + propName + ".." + o.ToString(),
"property");
}
}

// there is only one property exposed (for my case is: Size, and always =
4).

// For my concusion for now, a control doesn't necessaraly expose all of

it's child controls or properties ...


"Marcel Müller" wrote in message

I found:
Type.GetTypeFromHandle(h)
h should be hwnd, but what if I need to convert it from IntPtr - How can
I convert IntPtr to hwnd type?

Ehm...
I think you are really confusing things. A managed class type *never*
has a window handle (hwnd) and vice versa.
Are you talking about a *window* class? If yes, then you will not be
able to use reflections. Window classes respond to window messages in a
certain way. But you cannot examine this behavior by reflection. All you
have is the class name. And either you know what it is doing or not.
There are some exceptions if you have COM windows.


Marcel
 
M

Mr. X.

It seems mistake on following lines.
hh = Type.GetTypeHandle(hwnd);
t = Type.GetTypeFromHandle(hh);
(The convert to type isn't good).

If I inspect hwnd on "watch window", I see that it has one static property
"size", with value 4 (That's seems the structure of IntPtr).
In other words: just need to find the control, by having its handle only ...

Thanks :)

"Mr. X." wrote in message
As my previous post (see the following code on C# again), I overcome the
problem of converting IntPtr to RuntimeTypeHandle (it's RuntimeTypeHandle.
not hwnd, and now, that I have the handle of that class - It make scenes,
because when I get its class name, by WinAPI: GetClassNameW, I get the class
name I expected).

I have the control's handle (the following code, get a hwnd as IntPtr input
parameter).
The code uses reflection, but what I have found nothing special - only one
property (maybe, by mistake, or something default : size, that has the
length of 4).
As I stated on previous post, I think a control doesn't necessarily expose
all of its properties - but when it does?
What should be necessary that I can use reflection to a specific control?

(The goal is - There is a 3rd-party class, I don't know nothing about it,
but I need to change some of it's elements).

public static bool WindowEnumProc(IntPtr hwnd, int lParam)
{
RuntimeTypeHandle hh;
Type t;
PropertyInfo[] pi;
object o;

hh = Type.GetTypeHandle(hwnd);
t = Type.GetTypeFromHandle(hh);

pi = t.GetProperties();

for (int i = 0; i < pi.Length; i++)
{
propName = pi.ElementAt(i).Name;
MessageBox.Show(propName, "property name");
p = t.GetProperty(propName);
o = p.GetValue(hwnd, null);
MessageBox.Show(text + ".." + propName + ".." + o.ToString(),
"property");
}
}

// there is only one property exposed (for my case is: Size, and always =
4).

// For my concusion for now, a control doesn't necessaraly expose all of

it's child controls or properties ...


"Marcel Müller" wrote in message

I found:
Type.GetTypeFromHandle(h)
h should be hwnd, but what if I need to convert it from IntPtr - How can
I convert IntPtr to hwnd type?

Ehm...
I think you are really confusing things. A managed class type *never*
has a window handle (hwnd) and vice versa.
Are you talking about a *window* class? If yes, then you will not be
able to use reflections. Window classes respond to window messages in a
certain way. But you cannot examine this behavior by reflection. All you
have is the class name. And either you know what it is doing or not.
There are some exceptions if you have COM windows.


Marcel
 
M

Marcel Müller

As my previous post (see the following code on C# again), I overcome the
problem of converting IntPtr to RuntimeTypeHandle (it's
RuntimeTypeHandle. not hwnd, and now, that I have the handle of that
class - It make scenes, because when I get its class name, by WinAPI:
GetClassNameW, I get the class name I expected).

GetClassNameW returns the name of a *window class* while reflection
works on *.NET class types*. These two really have nothing in common,
except for the five letters c l a s s.

The code uses reflection, but what I have found nothing special - only
one property (maybe, by mistake, or something default : size, that has
the length of 4).

No wonder. You inspected IntPtr, nothing else.
*You won't get any further with reflection.*

(The goal is - There is a 3rd-party class, I don't know nothing about
it, but I need to change some of it's elements).

No way to do this straight forward. You can examine the sub controls
window handles and types by reverse engineering. A window inspector tool
will show you the parent child relations, the window classes and the
IDs. But only for standard controls the output is useful. For custom 3rd
party controls yo have to decompile the original application to examine
details. But custom controls often are often a compositions of standard
controls.


Marcel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top