Reflection Help

bri189a

Senior Contributor
Joined
Sep 11, 2003
Messages
1,004
Location
VA
So this week I've been play with System.Diagnositics and System.Reflection... fun stuff... lot's of potential but I'm having some problems doing what I want to do. Using System.Diagnostics.Process I can open, run, and close another program; but otherwise pretty useless - can really do anything with the program once it's open other than check to see if it's still open and/or close it. Using System.Reflection I can get all the member, methods, properties, values (well the values is being a pain but anyway) and expose the functionality of another program and by using InvokeMember can even get the start up form to display, but doesn't do anything unless I constantly invoke the Refresh member but it's more like I'm painting rather that starting a process as I do with StartProcess even though I'm using the CreateInstance binding flag. Anyway the whole point is I'm trying to control another program with my program without using such primative methods as SendKey's which you're really doing things blindly; whereas if I could determine the value of lables and buttons I'd know what screen I am on and be able to invoke methods and members correctly rather than hoping that the user hasn't closed the other program and that I'm on the right screen and that I've tabbed the right number of times...etc.... follow what I'm trying to do? There's a lot of theory behind the Reflection and Process classes and the documentation is lengthy but not the best... so advise, hints, tricks, etc would be helpful.
 
Reflection is not for controlling other programs. I can't see a reliable way of getting it working - frankly I'm surprised you managed at all. If you manage to create an instance of a .NET assembly's main form, that's all well and good but it won't be running as a separate process.
 
rodger that... then what is the true purpose of reflection then? I mean it exposes all these methods and members; allows you to use them by using InvokeMethod... what good is that for if not controlling other objects you know nothing about (such as foreign DLL's and the possiblity of manipulating it further to control another program)... I know it's all theory stuff... but I'm learning, and the only way to learn is to play with it and ask how come (that's the reason I took a class on Assembly too... not many people are interested in it; but I wanted to know how and why.. and this is the same thing). Thanks though!
 
The framework uses reflection extensively internally for things like security. Reflection is used when you get custom attributes from types that you've written. It can be handy for manipulation of advanced things that aren't exposed, or a developer has forgotten to expose. Also it's all you can use if you want to do late-binding in C#. All these things are in-process though.

You've had an interesting idea there, and I must say I had never thought of using reflection that way.
 
Back
Top