how to dynamically access to a function or to its name?
-
Hello, I started to develop an application with MFC, using Document/views and OCX components, My application works fine but I just realized (and hope it not too late) that I need a same feature as reflection provided by .NET. So my question is should I throw my application into the bean and develop a new one with C# or managed C++ or can I use my application by mixing MFC and managed C++ . Or probably is there something else existing for unmanaged C++ that provides the same features as reflection. Actually what I need to do is to dynamically access to the member functions and member variables of my application by their name. For example I would like to type in the name of a function from an edit control to call that function. You will probably suggest me to map the functions and data types but frankly I think it is not elegant. Of course this solution could be considered if nothing else is better. Please what do you suggest me to do?
-
Hello, I started to develop an application with MFC, using Document/views and OCX components, My application works fine but I just realized (and hope it not too late) that I need a same feature as reflection provided by .NET. So my question is should I throw my application into the bean and develop a new one with C# or managed C++ or can I use my application by mixing MFC and managed C++ . Or probably is there something else existing for unmanaged C++ that provides the same features as reflection. Actually what I need to do is to dynamically access to the member functions and member variables of my application by their name. For example I would like to type in the name of a function from an edit control to call that function. You will probably suggest me to map the functions and data types but frankly I think it is not elegant. Of course this solution could be considered if nothing else is better. Please what do you suggest me to do?
One option would be to COM-ize the classes/functions that need to be available to your application, and let them implement IDispatch. Then you have GetIdsOfNames and Invoke. Hope this helps, Daníel
Wenn ist das Nunstück git und Slotermeyer? Ja! Beierhund das oder die Flipperwaldt gersput!
-
One option would be to COM-ize the classes/functions that need to be available to your application, and let them implement IDispatch. Then you have GetIdsOfNames and Invoke. Hope this helps, Daníel
Wenn ist das Nunstück git und Slotermeyer? Ja! Beierhund das oder die Flipperwaldt gersput!
Thanks for proposing this solution. I am 100% newbee with COM, so where do you suggest me to start? a good book or just to search some articles in code project? Does Invoke mean that I will be able to call the function on runtime by typing in its name and parameters from an edit control?
-
Thanks for proposing this solution. I am 100% newbee with COM, so where do you suggest me to start? a good book or just to search some articles in code project? Does Invoke mean that I will be able to call the function on runtime by typing in its name and parameters from an edit control?
Arris7 wrote:
Does Invoke mean that I will be able to call the function on runtime by typing in its name and parameters from an edit control?
Yes, if you already have a IDispatch pointer to an object which implements the functions you want to call, then you can first call GetIdsOfNames to get the DISPID of the function, then use Invoke to call a function with a given DISPID. This is how it is done the hard way (pure C++), but you could also use scripting mechanics which take care of all this. One article which talks about similar things is this one: http://www.codeproject.com/com/scripter.asp[^], you can surely find other similar. Hope this helps, Daníel
Wenn ist das Nunstück git und Slotermeyer? Ja! Beierhund das oder die Flipperwaldt gersput!