R
Roberto Huezo
Hello, my name is Roberto. I have used late binding of events using Delegate
in other projects before,
but my current project uses another approach. On the first project I use,
for example:
Assembly assembly = Assembly.LoadFrom(myapp);
UserControl myusercontrol = assembly.CreateInstance("MyAppNamespace") as
UserControl;
EventInfo eventinfo = myusercontrol.GetType().GetEvent("MyAppResize",
(BindingFlags.Public | BindingFlags.Instance));
Delegate hanlder = Delegate.CreateDelegate(eventinfo.EventHandlerType, this,
"this_MyAppResize");
eventinfo.AddEventHandler(myusercontrol, handler);
* where myapp is a string with the path to my project.exe; "MyAppResize" is
an event in my project; "this_MyAppResize" is a method in THIS file
On my current project, which is a MS Office Add-In, I need to use the
Extensibility.EDTExtensibility2 classes and using object for the loading
application (it can be any MS Office program). The entry point of my dll is
the method
OnConnection(object application, Extensibility.ext_ConnectMode connectMode,
object addInInst, ref System.Array custom)
*Where application is the calling application (Word, Excel, Outlook, etc)
and from this moment on I am forced to use the following synthax to call
methods and get or set properties:
string appName = (string)applicationType.InvokeMember("Name",
BindingFlags.GetProperty, null, applicationObject, null);
oRange.GetType().InvokeMember("NumberFormat", BindingFlags.SetProperty,
null, oRange, new object[]{"@"});
oRange.GetType().InvokeMember("Select",BindingFlags.InvokeMethod,null,oRange,
null);
In summary, I can get/set properties, and InvokeMethods with parameters, but
I can not bind an event from the applicationObject variable above.
Has anyone ran into this problem?
Thank you in advance
Roberto
in other projects before,
but my current project uses another approach. On the first project I use,
for example:
Assembly assembly = Assembly.LoadFrom(myapp);
UserControl myusercontrol = assembly.CreateInstance("MyAppNamespace") as
UserControl;
EventInfo eventinfo = myusercontrol.GetType().GetEvent("MyAppResize",
(BindingFlags.Public | BindingFlags.Instance));
Delegate hanlder = Delegate.CreateDelegate(eventinfo.EventHandlerType, this,
"this_MyAppResize");
eventinfo.AddEventHandler(myusercontrol, handler);
* where myapp is a string with the path to my project.exe; "MyAppResize" is
an event in my project; "this_MyAppResize" is a method in THIS file
On my current project, which is a MS Office Add-In, I need to use the
Extensibility.EDTExtensibility2 classes and using object for the loading
application (it can be any MS Office program). The entry point of my dll is
the method
OnConnection(object application, Extensibility.ext_ConnectMode connectMode,
object addInInst, ref System.Array custom)
*Where application is the calling application (Word, Excel, Outlook, etc)
and from this moment on I am forced to use the following synthax to call
methods and get or set properties:
string appName = (string)applicationType.InvokeMember("Name",
BindingFlags.GetProperty, null, applicationObject, null);
oRange.GetType().InvokeMember("NumberFormat", BindingFlags.SetProperty,
null, oRange, new object[]{"@"});
oRange.GetType().InvokeMember("Select",BindingFlags.InvokeMethod,null,oRange,
null);
In summary, I can get/set properties, and InvokeMethods with parameters, but
I can not bind an event from the applicationObject variable above.
Has anyone ran into this problem?
Thank you in advance
Roberto