How do I create a DLL to interface with JavaScript

Posted on 2011-04-19
Last Modified: 2012-06-27
I am new to DLL development so I followed the following tutorial on how I can create a COM DLL along with a Win32 application that calls its functions:
The Simplest COM Tutorial in Visual Studio 2008

This all worked as expected but my ultimate goal is to run the DLL from a scripting interface like JavaScript e.g.
try {
    var app = new ActiveXObject("SimpleCOM.SimpleChatServer.1");
    app.CallMe("Test 1","Test 2");
catch (e) {
    alert("Error: " +e.message);

Open in new window

The following example just returns the following error message:
"Error: 'app' is null or not an object"

I am also aware that the DLL needs to be registered which Visual Studio 2008 seems to do automatically. Using RegDllView I was able to see the DLL listed (Sorry for the lack of formatting)
Class ID       Name       ProgID       Control       Version       Threading Model       Last Write Time
{3C32480D-2799-41EC-8E9F-6CBFFC20D51B}      SimpleChatServer Class      SimpleCOM.SimpleChatServer.1      No             Apartment      19/04/2011 19:42:12

Does any one know what further steps are required so it can start interfacing with it via JavaScript e.g. allowing me to call setters and getters from within the DLL file.

Question by:4fingers
    LVL 8

    Accepted Solution

    you have to use dual interfaces, i.e. interfaces that support both early binding and late binding through IDispatch.
    to do so, you have to implement IDispatch.
    scripting languages (such as javascript or vbscript) discover your interface's capabilities (methods, properties and events) through IDispatch.
    LVL 8

    Expert Comment

    for a brief introduction to early binding and late binding read here:
    LVL 1

    Author Closing Comment

    I decided to create a new ATL project and I made sure "Support COM+ 1.0" was checked. Then when I came to creating a new class I enssured the "ATL Simple Object Wizard" had the "Interface" set to "Dual".

    Featured Post

    Live - One-on-One C++ Help from Top Experts

    Solve your toughest problems, fast.
    C++ experts are online now and ready to help you.

    Join & Write a Comment

    In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
    This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
    The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
    The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now