I would like to use C++ / C to call a method of an running application. So it should work the following way:
An application is running, let's say Chrome and another application is running (plugin.exe). The other application should call a Chrome c++ method from the outside. Is that possible?
The method that I would like to call is the method displaying auto suggests. I would like to develop an omnibox with multiple keywords.
Somehow I would like to hook into the application and send / receive events and call methods. I guess event reeving can be done, since it's possible to use the Microsoft debugger with an executable and catch a lot of events.
While researching a bit I found out how to load a dll plugin in Chrome:
https://developer.chrome.com/extensions/npapi
I've done the same in Pepper API as well, but from there I can't reach any further.
Related
I have a C++ COM (multi-threaded apartment model) application that I build with Visual C++ 2019. I am playing with the COM-based Active Script interfaces and classes. I have a JavaScript ("JScript" really, CLSID {F414C260-6AC0-11CF-B6D1-00AA00BBBB58}) Active Script COM object created and set up. Everything works surprisingly well (for something that is falling into obscurity, unfortunately).
Is there an idiomatic approach to registering and calling event listeners where a script can use an API like like https://dom.spec.whatwg.org/#dom-eventtarget-addeventlistener and where I can dispatch events from the script host (C++)? To clarify, I am well able to call IDispatch interface methods from scripts, I want to call script functions that were passed earlier with such methods to the program, from the program. GetScriptDispatch is something else -- it lets me call methods available in the global script namespace, but I need to call functions that I pass to a proxied (from the script) "addEventListener" method.
I depend on this functionality because I want to dispatch events. Basically I want addEventListener to be available on certain proxied (e.g. objects added to script namespace with AddNamedItem) objects and I need to call event listeners added through calls to that method, when certain events in the C++ application happen.
I have read something about IConnectionPoint, and the Active Script documentation briefly mentions "event sinks" a couple of times, without there being examples on how and for what these can be used for. There is also the IBindEventHandler interface, without much explanation again as to what to use it for.
I understand this is ancient stuff, but I like COM and Active Script interface has several implementations, which to me adds utility.
You need to create an object that implements events (see IConnectionPoint).
After starting the script you can call AddNamedItem. The script now knows the interface of you object. If it implements it can register to this events when the state changes to SCRIPTSTATE_CONNECTED.
If an event is fired, the script will receive the event and will execute the appropriate code section.
There are old samples:
Q168214 SAMPLE: MFCAXS (you might find it in the wayback engine)
And there is a sample here in code project
For ATL samples for Events look here
I have written a simple dialog based MFC application using a thirdd party soft tree control. I am trying to write a automation client for the application. For this I wrote a singleton out-of-process COM Testing Agent for the dialog based application sample app. The Com server exposes a Run method to the automation client. This Run method access the gut of the mfc app and actually mimicks a click on the GUI. The problem i am facing is when the automation client tries to invoke Run method on the Com object it is able to invioke it but when the Run method crashes when it tries to access the control's methods such as getCaretInedx.
I have tried to cach the exception and log the message to a file but have not been able to do so.
My question is: Is there any limitation in the way a com object can access the application? Or am i missing anything to facilitate this.
Any help or pointer is greatly appreciated. Since this is my first in COM I have not been able to make much progress.
Thanks
Is your client's window actually being created? If not, the hwnd doesn't exist, which is probably why it crashes. Furthermore, your client may be hidden behind another window when it is started, and may exhibit different behavior than when the user called it through regular interaction.
In general, calling code that relies on or interacts with the UI from a COM server is fraught with peril, especially when that code is not written in the first place to behave like this. Most UI isn't that defensive about HWND's existing etc.
I have a Windows local service that may spawn off a process to execute a JScript script (in a .js file) via the Windows Script Host. The issue is that I need to notify my service of the results generated by the script in the .js file. A transfer or a simple 32-bit integer, or a string would suffice. What would be the way to do this?
PS. The code must run on Windows XP SP3 or later OS.
Your best bet is to create an out of process COM object that executes within your service. Just implement the necessary scripting interfaces and provide a member function to match the notification and call it from your script as such:
newObj = new ActiveXObject("localserver.mynotify");
newObj.Notify("finished");
Would the exit code of the process be enough?
Windows Scripting host has has a .Quit(errorCode) method that allows you to set the exit code.
You should be able to call WSH directly from the service and get the return code with GetProcessExitCode() by passing the process handle that you received after spawning it.
Note that almost everything you can do from a JScript file can also be done with native code.
Do you have to execute the .js file as an external process? Windows Scripting has COM objects that an app can use to run scripts within its own process. I use this to execute script files within my service processes, and it works fine. The hosting process can even implement its own IDispatch-based classes and pass them to the scripting engine to expose to scripts as global objects so the scripts can communicate with the hosting process without having to use new ActiveXObject or CreateObject() to access those objects.
I see your script is written in JScript and your app in C++.
Perhaps the easiest way to accomplish what you want is by writing a file, say, to programdata folder which your service should have access to. Maybe use a GUID for the particular request, pass that to the JScript so it's guaranteed to be a unique file. Not ideal.
Another way to get JScript output ... Can you call out to managed code (C#)? If so, you could use a .NET-based or .NET-callable JavaScript compiler/interpreter. This would allow you to avoid IActiveScript and also to grab the values right out of the script context or from function return. I've used Jurassic and JavaScriptDotNet, both very easy to use and extend.
This might open a problem if you heavily rely on ActiveXObject calls (ie: FileSystemObject) and don't want to write components. JuraScript wraps the Jurassic engine and add ActiveXObject support to it for COM automation.
I am a C++ newb, so I don't know how much of a leap this is for you although I know it's possible to interop between managed/C++.
Just thought I'd mention these scenarios as I didn't see them listed in answers.
I am using blazeDS in my web application. I am facing issue with Java and flex.
I have used function to load service in creation complete event of application. And I need to get value in combo box and do some manipulation. But my function which will trace the value, is being called before service is loading. for that reason function is not returning any value.
you can overcome by doing following changes
1) call webservice in Application initizlize event
2) Call your method in ResultEvent triggers on result of Webservice
or
3) IF Still you face same issue you can call it using callLater()
or
4)IF callLater() wont work to, then you can use Event collectionchange of ListCollectionView a Parent Class of ArrayCollection, XMLListCollection
I personaly recommend DO Steps 1 and 4 Only.
Hopes that helps
I'm trying to develop a browser plugin using Firebreath framework. The first thing I would like to achieve is to make the plugin able to do traceroute. For now I'm doing it on Windows7. Currently I chose to use Win32API CreateProcess to call the command shell. By setting dwFlags = STARTF_USESHOWWINDOW , I'm able to hide the command shell window during execution.
PROBLEM : The createProcess is implemented in a method called run() where I called it using JS for testing. When I called plugin().run(), the traceroute is working well, and the output was succesfully written in a textfile as I wanted. However during the execution, the browser become unresponsive and lastly the plugin crashed seconds after the traceroute completed. As I am new to plugin development and only have a little knowledge on c++ , I wonder why this problem arisen. FYI, if I did not hide the commandshell window, the plugin worked wonder - the browser was responsive while the traceroute was executed.
It is very important in any NPAPI plugin (with FireBreath or otherwise) that you don't block the main (the javascript) thread. What you're trying to do could be done in a couple of ways; I'd probably pass in a callback, start a new thread, do the createprocess there, and then fire the js callback when it completes with the result.
See FireBreath Tips: Asynchronous Javascript Calls.
The one thing to watch out for is you need to be able to terminate the thread (and the process) if the plugin is shut down during the call.