0

I am developing a C++ custom wizard with 1 page UI consisting of a dropdown control. I want to populate this dropdown control with all input languages installed on that machine. (An input language is a culture/keyboard layout pair that determines how the physical keys on a keyboard map or plot to characters in a language.)

I am trying to get this list & have found a way to do in C#.

public void GetLanguages() {
// Gets the list of installed languages. 
foreach(InputLanguage lang in InputLanguage.InstalledInputLanguages) {
   textBox1.Text += lang.Culture.EnglishName + '\n';
}
}

No i want to implement the same using javascript as my custom wizard uses .js I tried doing below, but getting the js runtime error: "Automation Server can't create object".

 <select class="sideBtn" size="1" id="LANGUAGE_LISTBOX" accesskey="L" title="Select Languages:">
                     <script type="text/javascript">
                         var obj = new ActiveXObject("System.Windows.Forms");
                         // Gets the list of installed languages.
                         for (var lang in obj.Windows.Forms.InputLanguage.InstalledInputLanguages)
                         {
                             document.write('<option value="' + lang.Culture.EnglishName + '">' + lang.Culture.EnglishName + '</option>');
                         }
                     </script>
 </select>

I have tried like this as i have referred other articles which shows trigerring a c# dll using javascript ActiveX object. Triggering C# dll using Javascript ActiveX Object

Can some one help me please??

Regards, Deepthi

1 Answer 1

0

You can't do what you want using this code, because there is no COM object registered as System.Windows.Forms. But the question you've linked to, is exactly what you want.

You have two options to implement this and selecting one of them depends on whether you want to have just the culture names in Javascript side or the whole InputLanguage class. I think the first approach will be enough for you here. For the second one, you should define an interface and a new class that contain all the properties of InputLanguage you need in Javascript.

In the interface IHello, change this:

[DispId(1)]
string GetLanguages();

In the class CHello, change this:

public string GetLanguages()
{
    string[] langNames =InputLanguage.InstalledInputLanguages
            .OfType<InputLanguage>()
            .Select(lang => string.Format("{0}", lang.Culture.EnglishName))
            .ToArray(); 

    // This is a simple Join, just to give you the idea
    // You better use a proper serialization like JSON
    return string.Join(";", langNames);
}

And your javascript code (suppose you either reduced the security levels, or signed you ActiveX):

 <script type="text/javascript">

 myAx1 = new ActiveXObject("csharpAx.CHello");
 if(myAx1 != null)
 {
 // Gets the list of installed languages.
     for (var lang in obj.GetLanguages().split(";"))
     {
         document.write('<option value="' + 
         lang + 
         '">' + 
         lang + 
         '</option>');
     }
 }
 </script>
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for reply.But my motive is to use javascript & get the list of all input installed languages & populate my dropdown control.I don't want to add any new class/interface as i have said i am developing a C++ custom wizard which uses only default.htm & default.js file to interact with UI.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.