Reflection Help

bri189a

Well-known member
Joined
Sep 11, 2003
Messages
1,004
Location
VA
So this week Ive been play with System.Diagnositics and System.Reflection... fun stuff... lots of potential but Im 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 its open other than check to see if its 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 doesnt do anything unless I constantly invoke the Refresh member but its more like Im painting rather that starting a process as I do with StartProcess even though Im using the CreateInstance binding flag. Anyway the whole point is Im trying to control another program with my program without using such primative methods as SendKeys which youre really doing things blindly; whereas if I could determine the value of lables and buttons Id know what screen I am on and be able to invoke methods and members correctly rather than hoping that the user hasnt closed the other program and that Im on the right screen and that Ive tabbed the right number of times...etc.... follow what Im trying to do? Theres 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 cant see a reliable way of getting it working - frankly Im surprised you managed at all. If you manage to create an instance of a .NET assemblys main form, thats all well and good but it wont 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 DLLs and the possiblity of manipulating it further to control another program)... I know its all theory stuff... but Im learning, and the only way to learn is to play with it and ask how come (thats 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 youve written. It can be handy for manipulation of advanced things that arent exposed, or a developer has forgotten to expose. Also its all you can use if you want to do late-binding in C#. All these things are in-process though.

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