ActiveX for Sidebar best practices

I am interested in further exploring the possibilities of using/developing an ActiveX object for use in a Sidebar gadget but havent done anything like this before. What are the best ways of proceeding with this Can i use Visual Studio 2005 to create an ActiveX object i tried using ATL project, i was able to compile it but not to register it

Answer this question

ActiveX for Sidebar best practices

  • Wildert

    I uploaded my entire TestActiveX Visual Studio 2005 solution as a zip here; I am basically following Bruce’s "Powering Your Gadgets with ActiveX Articles" Part1 and Part2 very carefully, but perhaps I am missing something
  • Meelis

    Hello Bruce,

    I am using Visual Studio 2005 following your tutorial i selected: File -> New Project ->Visual C++ -> ATL -> ATL Project

    Your tutorial is well written and the screenshots are complementing well; i really much doubt me having made a silly mistake, i even tried it twice now,

    I follow the rest of the tutorial carefully and build my solution; but how do i register this activex control If i debug run or start without debugging i get the
    "Executable For Debug Session" dialog where i can choose the Executable file name i.e. Internet Explorer, ActiveX Control Test Container, regsvr32, Browse...

    i tried to manually do regsvr32 TestActiveX.dll which reports success but it doesnt seam to work


  • Matthew42

    Go through and replace all the weird quotation marks with real ones.
  • GethWho

    lol i guess when i posted the html code it rendered like that on the msdn page but i do have it proper, no script errors... btw when i check all my ActiveX objects on my machine i cannot find TestActiveX TestControl i still dont think despite regsvr reporting success that it never gets registered
  • pfd

    and put a quotation mark after 'onload=' in the body element.
  • WPF Fan

    Check and make sure you're selecting the basic ATL COM object option when setting up your project or adding an ATL object to it. The "IE" and "control test container" options you mention make me think that you instead selected an ATL UI control, which is a somewhat more complex animal that contains a number of interfaces used to interact with the UI container that is hosting your UI control. (Unless you are actually trying to create a UI control, in which case my tutorial may not be that useful.)
  • rahoward

    Ignore the F7 then, just build the DLL, it will auto register once it's built it.

  • MunishGupta

    Hi Jonathan,

    Are you sure I am using Visual Studio 2005 Professional and i get to choose either regsvr32, IE or ActiveX control test container am i missing something It compiles fine, i am running as admin but my TestActiveXControl never gets registered


  • scenedamaged

    Thanks for your responses; to clarify I have formatted my Vista system just in case, I use Visual Studio 2005 and follow Bruce’s Tutorial Part1 and Part2 I compile the DLL and use regsvr32 TestActiveX.dll in the command prompt (Running all as Admin) I get notification that the DLL is registered successfully.

    Next I use the following HTML:

    <HTML>
    <SCRIPT>

    function main(){

    try

    { var myControl = new ActiveXObject(“TestActiveX.TestControl”);

    out(myControl.Echo(“Bruce Williams”));

    }

    catch (e)

    {

    content.innerText = "ERROR: " + e + " : " + e.name + " : " + e.message;

    }

    }

    function out(text)

    {

    content.innerHTML += "<DIV style='height:20;overflow:hidden'>" + text + "</DIV>";

    }

    </SCRIPT>

    </HEAD>

    <BODY STYLE="height:300;width:600;background-color:gray" onload=main();">

    <DIV id="content" style="height:270;width:580;border-style:solid;overflow:auto">

    </DIV>

    </BODY>

    </HTML>

    But it still doesn’t work I am starting to feel silly L


  • MartinMalek

    Compiled, built and registered on mine okay, with F7. I also tested it with the following code:

    var oTest=new ActiveXObject("TestActiveX.TestControl");
    oTest.Echo

    Check you're not getting a compiler error, I had to do a rebuild to get it to compile the first time (right click on TestActiveX and select Rebuild)

  • m.a.fuchs

    You won't be able to run my sample control directly from inside VS 2005, because its not a UI control. (Caveat - there probably is some way to configure it to work, but its not going to be as simple as "F5".) You should instead try running a gadget, web page, or javascript file that uses the control you've compiled. My tutorial gives directions on setting up the gadget option of those.
  • Jobr77

    yes his article looks good but he says: "Now our initial ActiveX control implementation is complete – you can press F7 to build and register your new ActiveX control." when following his instructions F7 doesnt do anything furthermore i dont have that option


  • Bandile

    Yes you can use VS2005, Bruce wrote a very good an article on this, part 1, part 2, part 3. To register, just use REGSVR32 as an elevated Administrator.

    If you want to distribute it with the Gadget, you need to find out what reg entries it creates under HKLM and progammatically put them into HKCU as the Gadget loads. I have noticed that this only works if the user is not an elevated Administrator. For it to work as an elevated Administrator, you need to register to HKLM.

    Here's the code I use in my Media Player Gadget, which handles both user types:

    //register graphics library
    var ImgXLib, ImgXLibOK;
    var regRoot = "HKCU";

    //try HKCU first
    if (!activeDLL()) {
    //HKCU failed, so try HKLM
    regRoot = "HKLM";
    if (!activeDLL())
    System.Debug.outputString("Error creating ActiveX object ("+err.name+" - "+err.message+")");
    }



    // Try to register the DLL
    function activeDLL() {
    try{
    RegisterImgXLib(regRoot);
    ImgXLib = new ActiveXObject("ImgXLib.ImgX");
    ImgXLibOK = true;
    } catch(err) {
    // DLL not working under this Reg root, so remove the registry entries
    ImgXLib = null;
    ImgXLibOK = false;
    UnregisterImgXLib(regRoot);
    }
    return ImgXLibOK;
    }


    // Register Thumbnail ActiveX component
    function RegisterImgXLib(root) {
    try{
    oShell.RegWrite(root + "\\Software\\Classes\\CLSID\\{EBECE075-E4AE-4A77-89BF-9C85C0EFF82F}\\","ImgXLib.ImgX", "REG_SZ");
    oShell.RegWrite(root + "\\Software\\Classes\\CLSID\\{EBECE075-E4AE-4A77-89BF-9C85C0EFF82F}\\Implemented Categories\\{40FC6ED5-2438-11CF-A3DB-080036F12502}\\", "", "REG_SZ");
    oShell.RegWrite(root + "\\Software\\Classes\\CLSID\\{EBECE075-E4AE-4A77-89BF-9C85C0EFF82F}\\InprocServer32\\", gadgetPath + "\\ImgXLib.dll", "REG_SZ");
    oShell.RegWrite(root + "\\Software\\Classes\\CLSID\\{EBECE075-E4AE-4A77-89BF-9C85C0EFF82F}\\InprocServer32\\ThreadingModel", "Apartment", "REG_SZ");
    oShell.RegWrite(root + "\\Software\\Classes\\CLSID\\{EBECE075-E4AE-4A77-89BF-9C85C0EFF82F}\\ProgID\\", "ImgXLib.ImgX", "REG_SZ");
    oShell.RegWrite(root + "\\Software\\Classes\\CLSID\\{EBECE075-E4AE-4A77-89BF-9C85C0EFF82F}\\TypeLib\\", "{E82BEFB5-939E-449F-A975-062F2BEDCFC2}", "REG_SZ");
    oShell.RegWrite(root + "\\Software\\Classes\\CLSID\\{EBECE075-E4AE-4A77-89BF-9C85C0EFF82F}\\VERSION\\", "2.0", "REG_SZ");
    oShell.RegWrite(root + "\\Software\\Classes\\ImgXLib.ImgX\\", "ImgXLib.ImgX", "REG_SZ");
    oShell.RegWrite(root + "\\Software\\Classes\\ImgXLib.ImgX\\Clsid\\", "{EBECE075-E4AE-4A77-89BF-9C85C0EFF82F}", "REG_SZ");
    oShell.RegWrite(root + "\\Software\\Classes\\TypeLib\\{E82BEFB5-939E-449F-A975-062F2BEDCFC2}\\2.0\\", "ImgXLib", "REG_SZ");
    oShell.RegWrite(root + "\\Software\\Classes\\TypeLib\\{E82BEFB5-939E-449F-A975-062F2BEDCFC2}\\2.0\\0\\win32\\", gadgetPath + "\\ImgXLib.dll", "REG_SZ");
    oShell.RegWrite(root + "\\Software\\Classes\\TypeLib\\{E82BEFB5-939E-449F-A975-062F2BEDCFC2}\\2.0\\FLAGS\\", "0", "REG_SZ");
    oShell.RegWrite(root + "\\Software\\Classes\\TypeLib\\{E82BEFB5-939E-449F-A975-062F2BEDCFC2}\\2.0\\HELPDIR\\", gadgetPath, "REG_SZ");
    } catch(err) {System.Debug.outputString("RegisterImgXLib: "+err.name+" - "+err.message)}
    }



    // Unregister Thumbnail ActiveX component
    function UnregisterImgXLib(root) {
    try{
    oShell.RegDelete(root + "\\Software\\Classes\\CLSID\\{EBECE075-E4AE-4A77-89BF-9C85C0EFF82F}\\Implemented Categories\\{40FC6ED5-2438-11CF-A3DB-080036F12502}\\");
    oShell.RegDelete(root + "\\Software\\Classes\\CLSID\\{EBECE075-E4AE-4A77-89BF-9C85C0EFF82F}\\Implemented Categories\\");
    oShell.RegDelete(root + "\\Software\\Classes\\CLSID\\{EBECE075-E4AE-4A77-89BF-9C85C0EFF82F}\\InprocServer32\\");
    oShell.RegDelete(root + "\\Software\\Classes\\CLSID\\{EBECE075-E4AE-4A77-89BF-9C85C0EFF82F}\\ProgID\\");
    oShell.RegDelete(root + "\\Software\\Classes\\CLSID\\{EBECE075-E4AE-4A77-89BF-9C85C0EFF82F}\\TypeLib\\");
    oShell.RegDelete(root + "\\Software\\Classes\\CLSID\\{EBECE075-E4AE-4A77-89BF-9C85C0EFF82F}\\VERSION\\");
    oShell.RegDelete(root + "\\Software\\Classes\\CLSID\\{EBECE075-E4AE-4A77-89BF-9C85C0EFF82F}\\");
    oShell.RegDelete(root + "\\Software\\Classes\\ImgXLib.ImgX\\Clsid\\");
    oShell.RegDelete(root + "\\Software\\Classes\\ImgXLib.ImgX\\");
    oShell.RegDelete(root + "\\Software\\Classes\\TypeLib\\{E82BEFB5-939E-449F-A975-062F2BEDCFC2}\\2.0\\0\\win32\\");
    oShell.RegDelete(root + "\\Software\\Classes\\TypeLib\\{E82BEFB5-939E-449F-A975-062F2BEDCFC2}\\2.0\\0\\");
    oShell.RegDelete(root + "\\Software\\Classes\\TypeLib\\{E82BEFB5-939E-449F-A975-062F2BEDCFC2}\\2.0\\FLAGS\\");
    oShell.RegDelete(root + "\\Software\\Classes\\TypeLib\\{E82BEFB5-939E-449F-A975-062F2BEDCFC2}\\2.0\\HELPDIR\\");
    oShell.RegDelete(root + "\\Software\\Classes\\TypeLib\\{E82BEFB5-939E-449F-A975-062F2BEDCFC2}\\2.0\\");
    oShell.RegDelete(root + "\\Software\\Classes\\TypeLib\\{E82BEFB5-939E-449F-A975-062F2BEDCFC2}\\");
    } catch(err) {System.Debug.outputString("UnregisterImgXLib: "+err.name+" - "+err.message)}
    }


  • drew_p

    Show us the code you're using to create the object. Either that's wrong, or the DLL is the wrong type if it's not working.

  • ActiveX for Sidebar best practices