Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. ATL / WTL / STL
  4. Handle VC++ ATL COM Event in Java Script ?? [modified]

Handle VC++ ATL COM Event in Java Script ?? [modified]

Scheduled Pinned Locked Moved ATL / WTL / STL
c++javacomtoolstutorial
9 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    garammasala
    wrote on last edited by
    #1

    How to handle COM Events in Java script How to use ATL COM in java script and handle COM event in java script if the ATL COM is developed in C++ Abhiraj

    modified on Tuesday, April 29, 2008 2:43 AM

    S 1 Reply Last reply
    0
    • G garammasala

      How to handle COM Events in Java script How to use ATL COM in java script and handle COM event in java script if the ATL COM is developed in C++ Abhiraj

      modified on Tuesday, April 29, 2008 2:43 AM

      S Offline
      S Offline
      Stephen Hewitt
      wrote on last edited by
      #2

      You can call JavaScript functions from C++ using the IHTMLDocument::get_Script[^] function.

      Steve

      G 1 Reply Last reply
      0
      • S Stephen Hewitt

        You can call JavaScript functions from C++ using the IHTMLDocument::get_Script[^] function.

        Steve

        G Offline
        G Offline
        garammasala
        wrote on last edited by
        #3

        Hi Steve You took the question wrong ... The question is how to handle events in Java script which are fired from ATL COM I am able to call COM interface methods in java scripts but not able to handle events fired from the same ATL COM Component and not "call java script functions in C++" with regards Abhiraj

        S 1 Reply Last reply
        0
        • G garammasala

          Hi Steve You took the question wrong ... The question is how to handle events in Java script which are fired from ATL COM I am able to call COM interface methods in java scripts but not able to handle events fired from the same ATL COM Component and not "call java script functions in C++" with regards Abhiraj

          S Offline
          S Offline
          Stephen Hewitt
          wrote on last edited by
          #4

          You haven't explained properly. How is the ATL COM object hosted? If it's hosted on the page you can simply handle it like any other event in HTML. It it's not on the page you would sink the events with an interface implemented in C/C++ and the methods would delegate to the web page as described in my previous post.

          Steve

          G 1 Reply Last reply
          0
          • S Stephen Hewitt

            You haven't explained properly. How is the ATL COM object hosted? If it's hosted on the page you can simply handle it like any other event in HTML. It it's not on the page you would sink the events with an interface implemented in C/C++ and the methods would delegate to the web page as described in my previous post.

            Steve

            G Offline
            G Offline
            garammasala
            wrote on last edited by
            #5

            Hi Steve I would like to change my question... How to use ATL COM in java script and handle COM event in java script if the ATL COM is developed in C++ Abhiraj

            S 1 Reply Last reply
            0
            • G garammasala

              Hi Steve I would like to change my question... How to use ATL COM in java script and handle COM event in java script if the ATL COM is developed in C++ Abhiraj

              S Offline
              S Offline
              Stephen Hewitt
              wrote on last edited by
              #6

              Firstly, I’ll assume you’re embedding a COM object in a HTML page (you haven’t explicitly stated this). Here’s what my page looks like:

              <html>
               
              <head>
              <title>CallMe</title>
              </head>
               
              <body>
              <object id="my_obj" classid="clsid:7815559F-240E-406E-A0F0-974B7272C65F">
              </object>
              <script type="text/javascript" for="my_obj" event="Hello">
              window.alert("Hello!");
              </script>
              <input type="button" value="Call into COM object" onclick="my_obj.CallMe();" />
              </body>
               
              </html>

              Note that I used MSVC6, but other versions will have equivalent functionality. You’ll have to use connection points to implement an outgoing interface. Here’s the IDL of my project:

              // HostMe.idl : IDL source for HostMe.dll
              //
               
              // This file will be processed by the MIDL tool to
              // produce the type library (HostMe.tlb) and marshalling code.
               
              import "oaidl.idl";
              import "ocidl.idl";
              [
              object,
              uuid(4E413D85-21DC-48FC-AD65-B8635B74CBFF),
              dual,
              helpstring("IHostMeObj Interface"),
              pointer_default(unique)
              ]
              interface IHostMeObj : IDispatch
              {
              [id(1), helpstring("method CallMe")] HRESULT CallMe();
              };
               
              [
              uuid(9598F3A4-B8DE-4BA8-9AE1-90903ED9EF38),
              version(1.0),
              helpstring("HostMe 1.0 Type Library")
              ]
              library HOSTMELib
              {
              importlib("stdole32.tlb");
              importlib("stdole2.tlb");
               
              [
              uuid(5C211D24-97D2-4AA1-AB93-EE605DC97614),
              helpstring("_IHostMeObjEvents Interface")
              ]
              dispinterface _IHostMeObjEvents
              {
              properties:
              methods:
              [id(1), helpstring("method Hello")] void Hello();
              };
               
              [
              uuid(7815559F-240E-406E-A0F0-974B7272C65F),
              helpstring("HostMeObj Class")
              ]
              coclass HostMeObj
              {
              [default] interface IHostMeObj;
              [default, source] dispinterface _IHostMeObjEvents;
              };
              };

              It’s also important to implement the IProvideClassInfo and IProvideClassInfo2 interfaces or the callbacks will not work. The following articles (on the Wayback Machine, as the originals seem to have been deleted) may help: http://web.archive.org/web/20060915111734/http://msdn.microsoft.com/archive/en-us/dnarguion/html/drgui082399.asp[^]

              G 1 Reply Last reply
              0
              • S Stephen Hewitt

                Firstly, I’ll assume you’re embedding a COM object in a HTML page (you haven’t explicitly stated this). Here’s what my page looks like:

                <html>
                 
                <head>
                <title>CallMe</title>
                </head>
                 
                <body>
                <object id="my_obj" classid="clsid:7815559F-240E-406E-A0F0-974B7272C65F">
                </object>
                <script type="text/javascript" for="my_obj" event="Hello">
                window.alert("Hello!");
                </script>
                <input type="button" value="Call into COM object" onclick="my_obj.CallMe();" />
                </body>
                 
                </html>

                Note that I used MSVC6, but other versions will have equivalent functionality. You’ll have to use connection points to implement an outgoing interface. Here’s the IDL of my project:

                // HostMe.idl : IDL source for HostMe.dll
                //
                 
                // This file will be processed by the MIDL tool to
                // produce the type library (HostMe.tlb) and marshalling code.
                 
                import "oaidl.idl";
                import "ocidl.idl";
                [
                object,
                uuid(4E413D85-21DC-48FC-AD65-B8635B74CBFF),
                dual,
                helpstring("IHostMeObj Interface"),
                pointer_default(unique)
                ]
                interface IHostMeObj : IDispatch
                {
                [id(1), helpstring("method CallMe")] HRESULT CallMe();
                };
                 
                [
                uuid(9598F3A4-B8DE-4BA8-9AE1-90903ED9EF38),
                version(1.0),
                helpstring("HostMe 1.0 Type Library")
                ]
                library HOSTMELib
                {
                importlib("stdole32.tlb");
                importlib("stdole2.tlb");
                 
                [
                uuid(5C211D24-97D2-4AA1-AB93-EE605DC97614),
                helpstring("_IHostMeObjEvents Interface")
                ]
                dispinterface _IHostMeObjEvents
                {
                properties:
                methods:
                [id(1), helpstring("method Hello")] void Hello();
                };
                 
                [
                uuid(7815559F-240E-406E-A0F0-974B7272C65F),
                helpstring("HostMeObj Class")
                ]
                coclass HostMeObj
                {
                [default] interface IHostMeObj;
                [default, source] dispinterface _IHostMeObjEvents;
                };
                };

                It’s also important to implement the IProvideClassInfo and IProvideClassInfo2 interfaces or the callbacks will not work. The following articles (on the Wayback Machine, as the originals seem to have been deleted) may help: http://web.archive.org/web/20060915111734/http://msdn.microsoft.com/archive/en-us/dnarguion/html/drgui082399.asp[^]

                G Offline
                G Offline
                garammasala
                wrote on last edited by
                #7

                Hi Steve I have implemented the IProvideClassInfo and IProvideClassInfo2 interfaces for the callbacks and the callback are working fine Now the issue is even if I fire Event from ATL COM once , its shown more than once on the web page as if i have fired event from ATL COM many times and everytime the count is getting increased .... I have used this ATL Component in VB also , in VB its working fine if event is fired once the event is shown once and not more than that... Here is the code snippet ...... MessageBox(NULL,TEXT("Fire Event Reached"),TEXT("OK"),MB_OK); hr = pConnection->Invoke(1, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &params, &varResult, NULL, NULL); MessageBox(NULL,TEXT("Fire Event Complete"),TEXT("OK"),MB_OK); ......... I have used two message boxes just for the sake for debugging... Now in VB whenever there is event i have shown a msg box so once event is fired only 3 messages boxes comes one after the other 1. Fired Event Reached 2. Event Message Box (When "pConnection->Invoke" is fired) 3. Fire Event Complete Now in Internet Explorer its different.. whenever event is fired by ATL COM Event Message Box is shown many times in the Internet Explorer and everytime the count is getting increased What can be the problem... with regards Abhiraj

                S 1 Reply Last reply
                0
                • G garammasala

                  Hi Steve I have implemented the IProvideClassInfo and IProvideClassInfo2 interfaces for the callbacks and the callback are working fine Now the issue is even if I fire Event from ATL COM once , its shown more than once on the web page as if i have fired event from ATL COM many times and everytime the count is getting increased .... I have used this ATL Component in VB also , in VB its working fine if event is fired once the event is shown once and not more than that... Here is the code snippet ...... MessageBox(NULL,TEXT("Fire Event Reached"),TEXT("OK"),MB_OK); hr = pConnection->Invoke(1, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &params, &varResult, NULL, NULL); MessageBox(NULL,TEXT("Fire Event Complete"),TEXT("OK"),MB_OK); ......... I have used two message boxes just for the sake for debugging... Now in VB whenever there is event i have shown a msg box so once event is fired only 3 messages boxes comes one after the other 1. Fired Event Reached 2. Event Message Box (When "pConnection->Invoke" is fired) 3. Fire Event Complete Now in Internet Explorer its different.. whenever event is fired by ATL COM Event Message Box is shown many times in the Internet Explorer and everytime the count is getting increased What can be the problem... with regards Abhiraj

                  S Offline
                  S Offline
                  Stephen Hewitt
                  wrote on last edited by
                  #8

                  Why are you firing the event manually using IDispatch::Invoke. The ATL wizard generates that code for you when you select the “Implement Connection Point…” option in the IDE.

                  Steve

                  G 1 Reply Last reply
                  0
                  • S Stephen Hewitt

                    Why are you firing the event manually using IDispatch::Invoke. The ATL wizard generates that code for you when you select the “Implement Connection Point…” option in the IDE.

                    Steve

                    G Offline
                    G Offline
                    garammasala
                    wrote on last edited by
                    #9

                    I am not firing the event manually.. i am using the code generated by the ATL Wizard as such.. For firing event from worker thread .... microsoft has given link to be implemented for the same thats the only change i have done and rest of the code i have not touched... with regards Abhiraj

                    modified on Wednesday, May 7, 2008 12:27 AM

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups