jeudi 15 juillet 2021

How to subscribe to the WndProc method and receive it's parameters

I am trying to subscribe to the WndProc(ref Message m) method via reflection.

Currently, I have the next code:

Assembly winFormsAssembly = AppDomain.CurrentDomain.GetAssemblies()
                                     .FirstOrDefault(asm => asm
                                                           .FullName
                                                           .Contains("System.Windows.Forms"));

Type formType = winFormsAssembly?.GetType("System.Windows.Forms.Form");
Type messageType = winFormsAssembly?.GetType("System.Windows.Forms.Message");

MethodInfo wndProcInfo = formType.GetMethod("WndProc",
                                            BindingFlags.NonPublic | BindingFlags.Instance,
                                            null,
                                            new[] {messageType.MakeByRefType()}, null);

It is necessary to receive an event when the method was invoked and get its parameters. Please give an advise which step should be the next.





Aucun commentaire:

Enregistrer un commentaire