I have a legacy application written in .Net. No sources available. It uses vb scripting to extend it inner logic via events handling. So it's a mix of com and .net.
I used SpyUI app and observed that UI is written with Windows Forms. Controls are titled in .Net style & it looks like windows forms one (vc++ and vb UI looks completely different).
I want to extend application UI by achieving System.Windows.Forms.Form instance for the main form and modify controls tree.
So i write code in vb script that creates my com object, something like:
Set obj = CreateObject("MyUiExtender")
obj.InjectIntoUi()
I try to get the main form handle for the process object was loaded into and this code works:
Process.GetCurrentProcess().MainWindowHandle; // a meaningfull value
Process.GetCurrentProcess().MainWindowTitle; // the title of the application
So far so good, but the following doesn't work -> it returns null
var mainForm = Control.FromHandle(Process.GetCurrentProcess().MainWindowHandle)
My object was loaded into executable and I try to get form instance for the same process. I suppose it's a kind of app boundaries problem. My code work perfect if my com object is loaded into .net app via
t = Type.GetTypeFromProgID("MyUiExtender")
dynamic c = Activator.CreateInstance(t)
c.InjectIntoUi();
I suppose using vb scripting ruins application boundaries somehow...
Is it still possible to get main application form instance as an instance of Windows.Forms.Form class ?