WebBrowser InvokeScript() - winforms

I need to execute an JavaScript function from my Visual C++ Code with the return value of the JavaScript function. In my Windows Visual C++ CLR project I have an Windows Form with an WebBrowser in it.
I tried:
Object^ result = webBrowser1->Document->InvokeScript("document.getElementById('communication').innerHTML;");
String^ resutlString = result->ToString();
Using this i get the Error 'System.NullReferenceException As far as I know this means smth like result equals null.
Actually not even this
webBrowser1->Document->InvokeScript("document.getElementById('communication').innerHTML = 'test';")
is doing anything.
Edit:
It seems I did't understand the method InvokeScript right you have to pass a JavaScript function name not just any JavaScript Code webBrowser1->Document->InvokeScript("jsFunction") is working but I'm still getting 'System.NullReferenceException when trying to Convert result to a string

Ok everything seems to work I had a typo in my JavaScript so the function never returned anything

Related

AngularJS getting value from function in ng-if and using that value in element

My question lies in the following code. Though the code is not working now. I wan't to rewrite it in proper way so that it works.
<span ng-if="community = vm.getCommunity(invite.community_id)!=null" grv-icon-comm-type="vm.communityViewHelper.getTypeIcon(community)" ng-class="vm.communityViewHelper.getColorClass(community)"></span>
In the above code vm.getCommunity(invite.community_id) returns either null or community object. If community object is returned then I wish to call two more function in the same element where I wish to use the recently receivedcommunity value on those two function.
It's just killing my time. Please help.
Alternatively, you could use a watcher on "invite.community_id" to set community inside a controller function. Could look a bit cleaner depending on the rest of the code.
This function could even set all three values if you like.

Unterminated string literal error while storing lesson_location

I have this error that doesnt give any indication as to what is the problem:
I'm trying to store this string in lesson_location field:
B^$eNrT0srLywNiLRANpiAsMAknoMKognlwdUi6ERrQuDARmCwmE2EMslOQ9aFaguw6dKyllQxhJcNp TFBTk1iSWhBvYBhvYGAKABXXVRI&#3d;
but it throws SyntaxError: unterminated string literal
when I've modified the way the reload stores the data in ReloadAPIAdaptor.js
from using eval on entire string:
eval("this.cmi.core.lesson_location.cmivalue =\"B^$eNrT0srLywNiLRANpiAsMAknoMKognlwdUi6ERrQuDARmCwmE2EMslOQ9aFaguw6dAzXnJwMozFB TU1ual4pAMimU3Q&#3d;\";");
to evaluate object first:
var o = eval("this." + element);
console.log("o",o);
if(o) o.cmivalue = value;
then it stores data without error,
now I can't modify the code in any lms so this was only to identify if the string can't be stored but it can. Just evil doesnt work so the question is what is in the given string that eval doesnt like and how to fix it.
There is nothing wrong with your string if you're doing the following:
API.SetValue("cmi.core.lesson_location", "B^$eNrT0srLywNiLRANpiAsMAknoMKognlwdUi6ERrQuDARmCwmE2EMslOQ9aFaguw6dKyllQxhJcNp TFBTk1iSWhBvYBhvYGAKABXXVRI&#3d;");
(where API is a reference to the window's API object)
The string is valid as far as SCORM is concerned, and the length falls within the acceptable character limit.
If you're encountering an issue, it might be a bug within the Reload wrapper. Frankly, the code in the Reload wrapper (as found on SourceForge) is TEN years old. It uses eval() and other JavaScript techniques that have been identified as problematic, and are highly discouraged by leading JavaScript developers. Your bug might very well be related to the wrapper's use of eval().
I'd try using a different wrapper and see if it makes a difference.

How to access a main document class array from a movieclip?

I have an array in my main
public var graphArray:Array = [1,2,3,4,5,6];
And I'm trying to access it from within a MovieClip that I've put on my timeline using:
var graph1scale:Number = MovieClip(root).graphArray[0]
It looks like it would make sense to me but when I try to run it I get this error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
Am I wrong to be using MovieClip(root) to try and access it? I've only just started using external classes (this is my first project doing so) and usually I just do everything on the timeline. So MovieClip(root) is familiar to me but I guess it's not the right thing to do here.
Is there a way I can access vars from Main.as?
-----SOLVED-----
I realised MovieClip(root) did work all along but I was just calling on the array before the array was being defined in Main.as. I put a delay on calling graphArray and it worked.
Not sure how that makes sense though because the graphArray is the first thing I've defined in the whole main.as class
Try using this instead
MovieClip(this.root)
This works for me on a test that you can see here:
http://marksost.com/test/as3arrayaccess/
And the source files here:
http://marksost.com/test/as3arrayaccess/test.zip

ironjs: returning objects to JS

Using Ironjs. I have a c# function registered as a JS function (via SetGlobal)
It gets called , but I want to return a value to from that function. The value is an IEnumerable of CLR objects. Using Jint this just works: I return the object and can foreach it etc, how do I do the same thing in IronJS (Why not use Jint, well it has bugs, for example it wont compile underscore.js)
EDIT: Since I am not a fluent F# person I cannot answer this question myself by reading the code. So instead I fixed Jint. However it would still be nice to know the answer
We are still working on our .NET interop. As such, the foreach in IronJS is not set up to enumerate IEnumerables, but instead works on CommonObject type objects.

Ruby C Extension using Singleton

I only wanted to allow one instance of my C extension class to be made, so I wanted to include the singleton module.
void Init_mousetest() {
VALUE mouseclass = rb_define_class("MyMouse",rb_cObject);
rb_require("singleton");
VALUE singletonmodule = rb_const_get(rb_cObject,rb_intern("Singleton"));
rb_include_module(mouseclass,singletonmodule);
rb_funcall(singletonmodule,rb_intern("included"),1,mouseclass);
### ^ Why do I need this line here?
rb_define_method(mouseclass,"run",method_run,0);
rb_define_method(mouseclass,"spawn",method_spawn,0);
rb_define_method(mouseclass,"stop",method_stop,0);
}
As I understand it, what that line does is the same as Singleton.included(MyMouse), but if I try to invoke that, I get
irb(main):006:0> Singleton.included(MyMouse)
NoMethodError: private method `included' called for Singleton:Module
from (irb):6
from C:/Ruby19/bin/irb:12:in `<main>'
Why does rb_include_module behave differently than I would expect it to? Also any tangential discussions/explanations or related articles are appreciated. Ruby beginner here.
Also it seems like I could have just kept my extension as simple as possible and just hack some kind of interface later on to ensure I only allow one instance. Or just put my mouse related methods into a module... Any of that make sense?
according to http://www.groupsrv.com/computers/about105620.html the rb_include_module() is actually just Module#append_features.
Apparently Module#include calls Module#append_features and Module#included. So in our C code we must also call included. Since clearly something important happens there.

Resources