6 Replies Latest reply: Jun 24, 2009 3:34 PM by TulipWin RSS

    Flash ActiveX's CallFunction method always fails (E_FAIL)

    AJet1234 Community Member
      Hi,

      I likely have collected all information in the web, but still facing the problem.

      I am trying to host the Flash ActiveX in a C# program and establish two-way communication between the host application and the ActionScript contained in my SWF file.

      On the ActionScript side, I use the ExternalInterface class.

      On the ActiveX side, for callbacks, I use the IShockwaveFlash:: FlashCall event, which works perfectly in all host applications I have experimented with. For direct calls, I use IShockwaveFlash:: CallFunction() method, which doesn't work on some host applications (unfortunately those I need). It fails with COM error (HRESULT E_FAIL, "Unspecified error").

      Here is what I have done so far:

      1) Installed the latest Flash Player 9, registered Flash9c.ocx ActiveX.
      2) Granted Flash security permission to the folder where my SWF is located by prescribing it in
      "C:\Documents and Settings\myname\Application Data\Macromedia\Flash Player\#Security\FlashPlayerTrust\myapp.cfg"
      Before I did this, the FlashCall event caused a SecurityError reported from the Flash player. So it makes me think that my problem is not a security issue any more.
      3) Tested the SWF file hosted in a browser (both IE and Firefox). The two-way communication with JavaScript works perfectly in both ways, so it means there's no mistake in my ActionScript code, and the way I call ExternalInterface methods is correct.
      4) From JavaScript, I tried the following two ways of calling the ActionScript function (called "Handshake") in the SWF movie object:

      // JavaScript code
      // call directly
      swfMovieObject.Handshake( "hello world" );
      // call via CallFunction
      swfMovieObject.CallFunction( "<invoke name="Handshake" returntype="xml"><arguments><string>hello world</string></arguments></invoke>" );

      the both methods also worked perfectly, which means the <invoke> xml string I am passing is correct.
      5) When hosted in VB6 and on MS Access 2003 Form, the CallFunction method works perfectly.
      6) Finally, the CallFunction method fails to work when hosted in Word 2003 document, Excel 2003 worksheet, VBA form in Word 2003 or Excel 2003, and also in a C# program written in Visual Studio 2005.


      I've seen others reporting this problem, but seen no resolution so far. It may be that this problem occurs only on some machines? For example, the sample .NET program here http://www.codeproject.com/cs/media/flashexternalapi.asp?df=100&forumid=226349&exp=0&selec t=1518421 doesn't work on my machine, although it should have worked on the author's machine.

      Please help!
        • 1. Re:  Flash ActiveX's CallFunction method always fails (E_FAIL)
          FeyFre Community Member
          Hello, AJet1234

          I have this problem too and I think I found why this error ocurs, but I still do not know ho to reslove it.
          Not only C# projects have such bug, C++ and Assembler code also failed with it.

          My task for now is to write plugin for some program. This plugin provides user interface for some internal beings of program. User interface done using Flash movie(Flex 2) played usnig ActiveX Flash control. To comunicate between plugin and movie I use CallFunction method of IShockwaveFlash interface.

          On the first steps I wrote simple application which emualtes behavior of program. All works perfectly. But when I ported communcation code into a DLL CallFunction begun to return E_FAIL value.

          I think the reason is that ActiveX Control checks in which module it was created. If it was created in startup module(someprogam.exe) it works perfectly. But when it was created in DLL module(various plugins etc) it disables some features(I think for security reason). One of those features is method callFunction. I lost 3 month trying reslove this problem.
          quote:

          I've seen others reporting this problem, but seen no resolution so far. It may be that this problem occurs only on some machines? For example, the sample .NET program here http://www.codeproject.com/cs/media/flashexternalapi.asp?df=100&forumid=226349&exp=0&selec t=1518421 doesn't work on my machine, although it should have worked on the author's machine.

          I tried 5 different machine with different configurations but that don't reslove problem.

          Best regards
          • 2. Re:  Flash ActiveX's CallFunction method always fails (E_FAIL)
            AJet1234 Community Member
            Thanks FeyFre,

            I guess you are right. I've got another suspicion that this bug may be due to some multi-threading issues but it's hard to tell.

            I wonder if Adobe can hear us and fix this bug in the following version of Flash Player. Through the previous versions, this bug survived over and over again :(

            Currently, I've created the following workaround: in Flash movie, I set a timer which sends (e.g. 10 times a second) the hosting program a request for a command(s) to execute. In this way the direct call (CallFunction) is no longer needed and replaced with callback (ExternalInterface.call). I know it's an ugly solution, but it works and I don't observe any tangible performance issues. Hope this can be helpful to others.
            • 3. Re:  Flash ActiveX's CallFunction method always fails (E_FAIL)
              FeyFre Community Member
              Hello, AJet1234

              Workaround, you offered, is widely used among other programmers, but it looks like sadism. I offer you to try another way, but you must be a litle familiar with writing COM servers(I have no other choice;-( ). I'll try it soon and advice you to try it. I offer to write own AxtiveX Control whitch will create Flash control. The thing is that the server which serves control must be LocalServer i.e. exe program, in order to use all feature of Flash Control instance createt by it(including CallFunction which calls now must be successfully completed). This is very simple to Aggregation(in COM terminology), and hope it will be working.
              Best regards
              PS: I understand my workaround also looks like sadism, but "What can I do?"
              • 4. Re:  Flash ActiveX's CallFunction method always fails (E_FAIL)
                Community Member

                Hi Ajet,

                Would you please have a code snippet on the workaround?

                I couldn't get it worked so I guess I may understand it wrong.

                 

                Thanks!

                • 5. Re:  Flash ActiveX's CallFunction method always fails (E_FAIL)
                  mikezeli Community Member

                  Just figured this one out. I'm using VC++ 6 with ActiveX Flash 10. The code snippets here will call the Flash function testFunction from VC++ using the CallFunction command and the appropriate XML. In VC++, make the following call assuming that m_flashGUI is the CShockwaveFlash object added to your dialog.

                   

                  CString ret = m_flashGUI.CallFunction("<invoke name=\"testFunction\" returntype=\"xml\">"

                       "<arguments><string>something</string></arguments></invoke>");

                   

                  The key item in the xml string is the "name" parameter. It must match the name in the addCallback function in the Flash movie.

                   

                  In the flash movie, have something like the following. The addCallback call is important. Without it the CallFunction from C++ will throw an exception.

                   

                  // Import the flash items

                  import flash.events.*;
                  import flash.external.ExternalInterface;


                  // Associate the flash function with the external call

                  flash.external.ExternalInterface.addCallback("testFunction", testFunction);

                   

                  function testFunction(str:String):Boolean
                  {
                      // Do something here...
                      return (true);
                  }

                   

                  Good luck!

                  Mike

                  • 6. Re:  Flash ActiveX's CallFunction method always fails (E_FAIL)
                    Community Member

                    Hi,

                    Thanks for your response.

                    That was what I did in C#, but it didn't work when our application is launched inside Excel, outside Excel, everything works.

                     

                    Thanks,

                    Thao