Common Controls Replacement Project - How to get started? - javascript

I want to use the Common Controls Replacement Project in my Windows Scripting Host (WSH) HTML Application (HTA). In particular the Extended File Dialogs DLL.
How do I get started?
In my JavaScript I have:
var fso = new ActiveXObject('Scripting.FileSystemObject'), WshShell = new ActiveXObject('WScript.Shell'), OpenDialog = new ActiveXObject('ccrpFileDialog')
The first two work OK, but on the third I get an error, "Automation server can't create object." I have already registered "ccrpFD6.dll" using regsvr32.
I don't see any newbie FAQs or discussion groups, so I don't know who else to turn to.
Are there better documented alternatives I can use instead?
Thanks!!

As far as I can tell, it doesn't work that way. It looks like these controls are only intended to be used from VB 5/6 projects, not from VBScript or HTAs.
I registered the DLL version which puts a "ccrpFD_DLL6.ccrpFileDialogDLL" ProgId in the registry.
Calling it with set fd = WScript.CreateObject("ccrpFD_DLL6.ccrpFileDialogDLL") produced "H:\projects\ccrpFileDialogTest.vbs(5, 1) ccrpFD_DLL6: Invalid procedure call or argument"
I then registered the OCX version which created a ProgId of "ccrFileDialogs6.ccrpFileDialogs".
Calling this in a similar way produced this error: "H:\projects\ccrpFileDialogTest.vbs(6, 1) WScript.CreateObject: Could not locate automation class named "ccrpFileDialogs"."

Related

Getting access to a XML from javascript without Node-Without JQuery

I am trying to developp modifications to a game. The thing is the game is already compiled and the developpers prefer not to decompile the game (for the time beeing). Because of the compilation probably, everytime I try to load JQuery or Node.js whatever version I get the error "that a key already exists in the dictionary". The thing is everything is fine without Node.js or JQuery.js.
What I am trying to achieve is add some features to the game that unfortunately aren't available through the Game's API function call itself. I want to be able to get access to data Inside .xml files used for items/weapons/devices/engines spécifications of items Inside the game. I've tried pretty much all I could find on Stackexchange with what I searched for which was Node and JQuery. Im sorry if you guys think this is a duplicate question. Because it isn't. I can't use Node.js neither can i use JQuery. What else could I try? can someone help me please.
I am a bit new to programing with only 1 year experience in c# and Javascript. Sorry if this feels really noObish to you guys.
What you need is ajax. Modern browsers provide a pretty functional XMLHttpRequest, so you don’t even need a framework anymore.
One important thing to know: you most likely won’t be able to download the xml file using ajax if it’s on a distant server, due to the same-origin policy. You need a reliable access to it. The most convenient solution is to have a copy of the file on a local server such as WAMP, XAMPP, and the like.
I’m not going to write yet another ajax tutorial. Insteal I’ll just provide you with a working minimal HTML page, and point you towards XMLHttpRequest documentation.
<button>Request</button>
<script>
'use strict';
document.querySelector('button').addEventListener('click',
function () {
let req = new XMLHttpRequest();
req.onload = function () {
if (this.responseXML) {
console.log(this.responseXML);
}
else {
console.log(this.responseText);
}
};
req.open('GET', xmlURL); // xmlURL should be the location of the .xml file
req.send();
});
</script>
When you click on the button, the script will request, and then display the server’s response, if any, in your browser console. To open the console, press F12 and select the console tab.
Be aware that the responseXML property will only be populated if the xml sent by the server is strictly well-formed. Xml parsing in JS is somewhat finicky, so you may want to rely on responseText as a fallback.

Replacing XML DataIsland Files in asp.net

The app I am working on, currently uses XML dataisland files to retrieve the dropdown data. Below is the code that defines the file.
<xml id="DefaultDataIslands" src="../XMLData/DataIslands-<%=((User.Identity).Database)%>.xml">
</xml>
Below is an example code that uses these XML dataislands.
var oDataIsland = document.getElementById("DefaultDataIslands");
var oXmlNodes = oDataIsland.XMLDocument.selectNodes("XMLDataIslands/DataIsland[#ID='DIMRGroup']/Option");
This oDataIsland line is used about 4k times total in the application. The application itself is intranet, so, I can even ask the users to download the xml files directly. Whole point is to keep the changes required to minimum, while removing all traces of XML tags. I want to make sure that application works on Chrome once this thing is completed.
I checked the link from mozilla regarding the dataislands here. https://developer.mozilla.org/en/docs/Using_XML_Data_Islands_in_Mozilla
Below is the code based on that mozilla link.
var doc = document.getElementById(strDataSource).contentDocument;
var mainNode = doc.getElementsByTagName("DataIsland");
var oXmlNodes;
var strOptions = "";
//finds the selected node based on the id, and gets the options for that id
for (i = 0; i < mainNode.length; i++) {
if (mainNode[i].getAttributeNode("ID").nodeValue == strDataMember) {
oXmlNodes = mainNode[i].getElementsByTagName("Option");
}
}
This code reads the data properly, works perfectly in IE (10 with standards mode, no quirks), was easy enough change to do in the full solution.
Only problem is, document.getElementById(strDataSource).contentDocument; line fails in Chrome. This is the same line as what was mentioned in Mozilla's documentation. But somehow contentDocument property is undefined on chrome.
So, I need some other suggestion on how to get this fixed. I tried other methods, using HTTPRequest (too many request per page), using JSON (requires changing existing methods completely), using backend to process XML instead of doing it client side (requires architectural changes). Till now, all these ideas failed.
Is there any other method that I can use? Or should I fix the contentDocument issue?
To allow contentDocument in Chrome, you will have to use --allow-file-access-from-files. Following are the steps for doing so:
Get the url of your Chrome Installation path to your chrome
installation e.g
C:\Users-your-user-name\AppData\Local\Google\Chrome\Application>
Launch the Google Chrome browser from the command line window with
the additional argument ‘–allow-file-access-from-files’. E.g ‘path
to your chrome installation\chrome.exe
--allow-file-access-from-files’
Temporary method you can use each time you are testing
Copy the existing chrome launcher
Do as above and save it with a new name e.g chrome - testing
Alternatively, you can simply create a new launcher with the above and use it to start chrome.
Source

firefox bootstrap addon: install event is not executed

I'm trying to create a bootstrapped addon that just sets the new tab url at install to a new value and resets it to the old one when it gets uninstalled.
Here is my bootstrap.js. I think the install function throws an exception because require is not defined, but I'm not sure if the debugger executes the code I write in Scratchpad in the right scope.
I read somewhere that the api is the same for bootstrapped extensions as the with the add-on sdk, so the require should be fine. If this is not the case, could you please direct me to a page that describes the code I can use in the bootstrap.js, I didn't find anything :(
function startup(data, reason){
}
function shutdown(data, reason){
}
function install(data, reason){
var prev_new_tab_url = require("sdk/preferences/service").get("browser.newtab.url");
var data = require("sdk/self").data;
var url = data.url("startpage.html");
require("sdk/preferences/service").set("browser.newtab.url", url);
var ss = require("sdk/simple-storage");
ss.storage.prev_new_tab_url = prev_new_tab_url;
}
function uninstall(data, reason){
var ss = require("sdk/simple-storage");
var prev_new_tab_url = ss.storage.prev_new_tab_url;
require("sdk/preferences/service").set("browser.newtab.url", prev_new_tab_url);
}
from: https://forums.mozilla.org/viewtopic.php?f=7&t=22621&sid=4ea13ebd794f85600d6dcbcf6cc590a7
in bootstrap you dont have access to sdk stuff like that. im not sure how to access that stuff.
but i made exactly what you are looking for with localization :D took like 10min :D
https://github.com/NoitForks/l10n/tree/setpref-install-uninstall
note: the quirk that localization files are not available during the uninstall procedure. so i had to move this to shutodwn proc while testing for aReason of ADDON_DISABLE. it makes sense that files are not available in uninstall
you asked:
How do you know the Services.prefs.getCharPref method?
i responded:
I first imported the Services.jsm module then i looked on MDN for what all it had:
https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/Services.jsm?redirectlocale=en-US&redirectslug=JavaScript_code_modules%2FServices.jsm
then i saw prefs then it linked to nsIPrefBranch and that documented all of it. nsIPrefBranch2 is deprecated so I knew it wasn't that.
MDN is your friend :)
Plain bootstrapped add-ons do not automatically get access to the SDK, i.e. there is no require.
Either use non-SDK stuff exclusively, like nsIPrefBranch, Services.jsm, etc.
Or write an SDK add-on in the first place
Or hook up the SDK loader for your add-on yourself. Only instance I know other than SDK add-ons themselves (heh) that does such a thing is Scriptish.

Why is Export to Excel and CSV javascript function not working?

I am trying to export an html table to excel using JavaScript. However I keep getting the following error.
ActiveXObject is not defined
[Break On This Error] var ExcelApp = new ActiveXObject("Excel.Application");
Here is a link to my code in JSFiddle:
http://jsfiddle.net/BxV9E/
I presume you are receiving the following JavaScript error (or similar - I captured in IE9)?
SCRIPT429: Automation server can't
create object
I believe you'll find that the script works fine when run locally, but not from a remote location. This is a restriction in your IE settings. Not sure what you need to change, but check for OLE Automation or some other scripting permission setting.

How can I hook up to Excel events in Javascript

In a client-side web application, I would like to:
open an Excel spreadsheet,
export some application data to Excel,
allow the user to work with it, and
when they are done, read the (potentially changed) data back into my application.
I would like the user to have a fluid experience and detect when they are done with excel by hooking up to the BeforeClose event, but I find that I am unable to hook up to Excel's events in javascript/HTML.
function BeforeCloseEventHandler(cancel) {
// TODO: read values from spreadsheet
alert("Closing...");
}
function openExcel() {
var excel = new ActiveXObject("Excel.Application");
var workbook = excel.Workbooks.Add();
var worksheet = workbook.Worksheets(1);
worksheet.Cells(1, 1).Value = "First Cell";
worksheet.Cells(1, 2).Value = "Second Cell";
workbook.BeforeClose = BeforeCloseEventHandler; // THIS DOESN'T WORK
excel.Visible = true;
excel.UserControl = true;
}
Does anyone have any suggestions?
After doing some research, I have discovered that I cannot hook up events to dynamic ActiveX objects (i.e., the ones that are created by the new ActiveXObject constructor) in javascript.
One idea is that I create a wrapper Windows Form user control that would be hosted inside of an <object> tag in the web app. The user control would call Excel and receive events, and raise events back to javascript, which I could hook up to using the <script for="..." event="..."> mechanism. Not sure that this will work, but I will try it.
Even if it does work, I am not particularly happy about this solution. There are too many layers--the javascript is being called from a silverlight control meaning that my data has to cross 3 boundaries there and back: Silverlight -> Javascript -> Hosted Winform User Control -> Excel.
It would be nice to eliminate some of these boundaries.
I think also your second approach using a Windows From control hosted in IE will not work.
IE behaves different as a scripting host. There are certain limitations as a blog post by Eric Lippert mentions:
Implementing Event Handling, Part Two
I don't believe this is possible. The reason being, when you call the following code:
var excel = new ActiveXObject("Excel.Application");
You're actually opening up Excel. So with the following line:
workbook.BeforeClose = BeforeCloseEventHandler;
Its like you're telling the Excel application to run Javascript, which isn't possible. I've tried researching alternatives, like creating an event object, defining the code behind it, then assigning it to workbook.BeforeClose, but I would run into the same problem: Excel events can't be detected by javascript. Mainly because it runs as a seperate process.
So here's some more alternatives you may consider:
Save the Excel data on the user's computer, then when the user loses excel, have them click somewhere that calls your 1st method, which reads that file and displays it.
Read the data from the excel file and then display it.
Don't close your excel object (this will probably leave excel open as a process on your computer), and have a timer event in javascript. Every 5 seconds, check if Excel is still open, and if it is not open, read the file and display it.
Sorry I couldn't be anymore help, and I'm not too sure if any of those alternatives would work, but good luck!

Categories

Resources