> I have written a C++ XPCOM object. I would like to call a javascript > function from this object which is defined in html page hosting XPCOM > object. > > In other words, I am looking for something equivalent to the following in IE > pIHTMLWindow->execScript (bstrScript,NULL,&vtResult); > > where bstrScript could have any JavaScript code. Hey man, I struggled with this concept a bit myself. It seemed natural to me to want to write a function in JavaScript and then call it in C++, so that's what I set out to do. Unfortunately, I don't think they've really finished support for this yet as I had no luck getting this working at the time. The second option I thought of was to write the JavaScript as an XPCOM component, which is fine *IF* you are running XPCOM and JavaScript in Mozilla. I wasn't. I was using a standalone build of XPCOM and JavaScript and have not to this day been able to get a good build of XPCOM and JavaScript that work together. Needless to say I was rather frustrated, but it turned out I was simply looking in the wrong place all along. You can create functions in C++ and export them to JavaScript. While toying around with those, I decided to rather expose a few functions to JavaScript that would allow the JavaScript code to manipulate the internal data of my C++ application. Then, I would create a script and execute it directly. It would use the previously defined functions to manipulate whatever data I wanted it to manipulate. I actually think this turned out much better than calling a function from JavaScript. I've been forced to create a standard set of routines that JavaScript can use (which makes my JavaScript code far more usefull). The various JavaScripts themselves (each acting basically as if they themselves were a sub routine call) are easy to organize as well. The more functionality I expose to JavaScript, the better things look, because I can code all the important pieces as function calls in C++ and use the JavaScript to basically glue it together. Just think yourself out of the little box (I know what it's like, I was in it at first) and you might like what you see. The JavaScript stuff is really flexible and really nice, you just have to figure out how to use it effectively first. Sent via Deja.com http://www.deja.com/
