none
java script can't receive an event from MFC ActiveX control?

    Dotaz

  • Hi all;
     
    I've read "A Complete ActiveX Web Control Tutorial" article at here:
    http://www.codeproject.com/Articles/14533/A-Complete-ActiveX-Web-Control-Tutorial
    I've done the all steps to create my own activex using MFC (C++).
    I'm not familiar with java scripting!
    When I run the downloaded "myactivex" project html files, everything is OK.
    But when I create another html file exactly same as the downloaded project and use my own activex which is currently similar to the "myactivex.ocx", I don't see any event received by html code (java script)!
     
    I mean, when pushing "submit" button, the other page containing "The parameter you entered is:" message is not displayed!!
     
    I think the html code doesn't get any event (ParameterLoaded) from activex!
     
    Because I've not worked with java script, I can't find the problem reason!
     
    Or the problem is from activex or a specific setting miss in system... I don't know?!!
     
    Please help me about this problem...
     
    I don't think to be able to get the response on that article thread.
     
    Thanks in Advance.
    18. června 2012 12:03

Všechny reakce

  • post the idl of the event. Javascript can not handle all events due to its weak type system.


    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP

    18. června 2012 14:00
  • Thanks.

    Here is myocx .idl file contents:

    #include <olectl.h>
    #include <idispids.h>
    
    [ uuid(DD95CE19-20A3-44F7-B370-6A91417C1197), version(1.0),
      helpfile("myocx.hlp"),
      helpstring("myocx ActiveX Control module"),
      control ]
    library myocxLib
    {
    	importlib(STDOLE_TLB);
    
    	//  Primary dispatch interface for CmyocxCtrl
    
    	[ uuid(391171F7-3682-4D6D-B743-06D92AFD3B6D),
    	  helpstring("Dispatch interface for myocx Control")]
    	dispinterface _Dmyocx
    	{
    		properties:
    			[id(1) , helpstring("property InputParameter1")] BSTR InputParameter1;
    			[id(2) , helpstring("property OutputParameter1")] BSTR OutputParameter1;
    	methods:
    		[id(3), helpstring("method LoadParameter")] void LoadParameter(void);
    	};
    
    	//  Event dispatch interface for CmyocxCtrl
    
    	[ uuid(4B5BD691-33C3-4FEF-B6CB-58C663BF559B),
    	  helpstring("Event interface for myocx Control") ]
    	dispinterface _DmyocxEvents
    	{
    		properties:
    			//  Event interface has no properties
    
    		methods:
    			[id(1)] void ParameterLoaded(void);
    	};
    
    	//  Class information for CmyocxCtrl
    
    	[ uuid(8F91127E-A84B-4FBD-AB43-AA63A63C0BE5),
    	  helpstring("myocx Control"), control ]
    	coclass myocx
    	{
    		[default] dispinterface _Dmyocx;
    		[default, source] dispinterface _DmyocxEvents;
    	};
    
    };
    

    As you see, the method ParameterLoaded has ID=1 ( id(1) );

    I've done all the steps mentioned in the tutorial as "MyActiveX" project and myocx.idl file is like MyActiveX.idl file.

    But MyActiveX and related html file runs successfully and my own project (myocx) html file has problem. 

    I don't know which setting I should do to solve the problem?!

    My html file is displayed, but when I push "submit" button to send a text into myocx ActiveX, another page is not displayed.

    I mean java script code doesn't receive event  ParameterLoaded() to be able to display another page!

    But in downloaded project (MyActiveX.ocx), everything is OK.

    And here is my html file:

    <HTML>
    <HEAD>
    <TITLE>myocx</TITLE>
    
    <SCRIPT LANGUAGE="JavaScript">
    
    function PassParameter()
    {
        if (StringInput.value != " ")
        {
            myocx1.InputParameter1 = StringInput.value;
            myocx1.LoadParameter();
        }
    }
    </SCRIPT>
    
    </HEAD>
    <BODY>
    <center>
    myocx ActiveX
    <p></p>
    
    <OBJECT ID="myocx1" WIDTH=100 HEIGHT=51
    CODEBASE ="C:\Documents and Settings\Administrator\Desktop\myocx.cab"
     CLASSID="CLSID:8F91127E-A84B-4FBD-AB43-AA63A63C0BE5">
        <PARAM NAME="_Version" VALUE="65536">
        <PARAM NAME="_ExtentX" VALUE="2646">
        <PARAM NAME="_ExtentY" VALUE="1323">
        <PARAM NAME="_StockProps" VALUE="0">
    </OBJECT>
    <p></p>
    Input Parameter: <INPUT TYPE ="text" NAME="StringInput" VALUE=" ">
    <p></p>
    <INPUT TYPE="button" NAME="Submit" VALUE="Submit" ONCLICK=PassParameter()>
    
    <SCRIPT FOR=myocx1 EVENT=ParameterLoaded()>
    <!-- { window.document.write("The parameter you entered is:<br> " + myocx1.OutputParameter1 + "  ")-->
    </SCRIPT>
    
    </center>
    </BODY>
    </HTML>

    What could be the problem?

    Regards.

    21. června 2012 9:32
  • First check if your ActiveX is running. Your ActiveX is based on the administrator desktop where a protected mode IE process probably has no access. You can expose a property (let's say version number in case you want to check for upgrading purpose) and evaluate in script, or just draw something on the ActiveX.



    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP

    21. června 2012 14:32
  • Thank you Mr. Jiang

    I've posted this question on many forums, but only you could answer to me;

    How can I check if my ActiveX is running?

    I tested it using "TestContainer" tool (that is a sample in VC++ 2008 at this directory: "C:\Program Files\Microsoft Visual Studio 9.0\Samples\AllVCLanguageSamples\C++\MFC\ole\TstCon") and saw the ActiveX (myocx.ocx) is OK and the event is fired and received from TestContainer tool correctly!

    Also, How can I understand that IE process in protected mode?

    If it is in protected mode, why does the downloaded ActiveX and related Html (MyActiveX.ocx) work?

    Should I do any additional setting other than the steps mentioned in the article on my own html or activex file?

    BTW, Within activex, the "OutputParameter1" is a property that is exposed using dispatch interface. Am I right?

    Could you put the required codes here to add into activex for exposing a property or drawing something on the activex?

    Pardon me for my many questions.

    Could you help me again please...

    Regards.

    25. června 2012 8:06
  • You are already exposing two properties, just evaluate them by assign the property's value to a JavaScript variable, like var test=myocx1.OutputParameter1. Or if you want to add painting code, add DrawTextW in OnDraw.

    Another way to test protected mode compatibility quickly is to put the page in a web site and test the ActiveX before and after adding the web site to the trusted zone in IE options. 



    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP

    25. června 2012 12:31