Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Find object's method and

15 views
Skip to first unread message

Mr. X.

unread,
May 24, 2012, 8:19:25 AM5/24/12
to
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 :)

Marcel Müller

unread,
May 24, 2012, 8:25:45 AM5/24/12
to
Type.GetType(string) is your friend.


Marcel

Mr. X.

unread,
May 24, 2012, 8:52:30 AM5/24/12
to
When I do : Type.GetType(<myClassName>) I get null value.

"Marcel Müller" wrote in message
news:4fbe28c9$0$6559$9b4e...@newsspool4.arcor-online.net...

Marcel Müller

unread,
May 24, 2012, 9:47:24 AM5/24/12
to
On 24.05.12 14.52, Mr. X. wrote:
> 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

Mr. X.

unread,
May 24, 2012, 9:55:45 AM5/24/12
to
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
news:4fbe3bec$0$6547$9b4e...@newsspool4.arcor-online.net...

Peter Duniho

unread,
May 24, 2012, 10:26:40 AM5/24/12
to
On Thu, 24 May 2012 16:55:45 +0300, Mr. X. wrote:

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

Please post a concise-but-complete code example that reliably reproduces
the problem.

Fact is, the phrase "handle of the class" makes no sense, and "there is
application outside C#" doesn't really add much either. Unless you show
_exactly_ what you are doing, and also describe _exactly_ whatever error
messages or other output occurs, it's going to waste a lot of time for
other people to try to figure out what you mean.

If you want help, stop making people guess. Post better questions.

Pete

Mr. X.

unread,
May 24, 2012, 10:30:48 AM5/24/12
to
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 news:jplel1$h7i$1...@dont-email.me...

Mr. X.

unread,
May 24, 2012, 10:34:53 AM5/24/12
to
Sorry h is RuntimeTypeHandle
Anyway - conversion is needed.
Thanks :)

"Mr. X." wrote in message news:jplgmp$v1t$1...@dont-email.me...

Mr. X.

unread,
May 24, 2012, 11:23:05 AM5/24/12
to
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 news:jplgue$ps$1...@dont-email.me...

Marcel Müller

unread,
May 24, 2012, 12:53:40 PM5/24/12
to
On 24.05.12 16.30, Mr. X. wrote:
> 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

Peter Duniho

unread,
May 24, 2012, 3:10:36 PM5/24/12
to
On Thu, 24 May 2012 18:23:05 +0300, Mr. X. wrote:

> Ok.
> The code look like :

You may find these links useful:

http://www.yoda.arachsys.com/csharp/complete.html
http://www.yoda.arachsys.com/csharp/incomplete.html
http://sscce.org/

Mr. X.

unread,
May 28, 2012, 2:06:54 AM5/28/12
to
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
news:4fbe6795$0$9505$9b4e...@newsspool1.arcor-online.net...

Mr. X.

unread,
May 28, 2012, 3:02:12 AM5/28/12
to
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 news:jpv4lv$pf0$1...@dont-email.me...

Marcel Müller

unread,
May 29, 2012, 2:23:34 AM5/29/12
to
On 28.05.2012 08:06, Mr. X. wrote:
> 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
0 new messages