3 Replies Latest reply on Sep 1, 2012 12:13 PM by wimdecorte

    ActiveX Automation With C++

    klein

      Dear community

      Has anybody ever managed to run a FM script from a C++ appliaction via ActiveX?

       

      I've spent quite a few hours on this now and have been partly successful, i.e. I could add the type library to the C++ project and compile it with all objects (TApplication, TDocuments and TDocument) declared. Some stuff even works, i.e. I can open FM dbs or toggle the FM application visibility. However, the TDocuments and TDocument objects remain "empty" at runtime, i.e. the list of open FM documents in TDocuments is empty, and so I couldnt run any of their scripts.

       

      Neither FM help nor google could provide me with the necessary hint. Does anybody have some sample project (or even a manual) of how to automate Filemaker via MS Visual C++ or preferably Borland C++-Builder 6.0?

      Any help is very much appreciated, thank you very much!

       

      PS: I'd also be interested in a VBScript example that runs a FM script, if this is possible in VBS at all.. It would help me to figure out, whether my C++ code is bad or rather something with the C++ environment or the FM db.

       

      My software:
      Win XP Pro SP3
      FM Pro Advanced 11 v3
      Borland C++-Builder v6

        • 1. Re: ActiveX Automation With C++
          wimdecorte

          Very generic VBscript to launch FM, open a file and run a script:

           

          ' turn off standard error handling:

          On Error Resume Next

           

          Set objFM = WScript.CreateObject ("FMPRO7.Application")  'open FileMaker

           

              ' check whether there was an error:

              if not err.Number=0 then

                  ' error occured

                  cause = err.description

                  if cause="" then

                      cause = "unknown error, code: " & err.Number

                  end if

                  MsgBox "Could not launch FileMaker: " & cause & " (" & err.Number & ")."

                  ' clear error condition and quit

                  err.clear

                  wscript.quit

              end if

           

           

          objFM.Visible = True ' show FileMaker for testing only.  Hidden by default.

           

           

          Set objFMfiles = objFM.Documents.Open("c:\VBS_fm.fp7","admin", "")  ' open test FileMaker file, no pw.

           

              ' check whether there was an error:

              if not err.Number=0 then

                  ' error occured

                  cause = err.description

                  if cause="" then

                      cause = "unknown error, code: " & err.Number

                  end if

                  MsgBox "Could not find the test file: " & cause & " (" & err.Number & ")."

                  ' clear error condition, quit FileMaker and quit the script

                  err.clear

                  objFM.Quit   ' quit FileMaker

                  wscript.quit

              end if

           

          objFMfiles.DoFMScript ("ShowMessage")  ' call the ShowMessage script in the test file.

           

              ' check whether there was an error:

              if not err.Number=0 then

                  ' error occured

                  cause = err.description

                  if cause="" then

                      cause = "unknown error, code: " & err.Number

                  end if

                  MsgBox "Could not locate the correct script: " & cause & " (" & err.Number & ")."

                  ' clear error condition, quit FileMaker and quit the script

                  objFM.Quit   ' quit FileMaker

                  wscript.quit

              end if

           

          objFM.Quit   ' quit FileMaker

          1 of 1 people found this helpful
          • 2. Re: ActiveX Automation With C++
            klein

            Thanks, Wim! Above code worked immediately, I just had to replace "FMPRO7.Application" with "FMPRO.Application" in line 4.

             

            Btw, I contacted Filemaker directly and asked them for an example of ActiveX automation with C++. They couldnt give me one either.

             

            Yet, with Wim's example given here, I could find an acceptable workaround: my C++ app now calls a VB script (FM script name as argument). This VB script then calls the FM script. Nothing noble, but has run fast and stable so far. Plus, it worked fine at first go.

            • 3. Re: ActiveX Automation With C++
              wimdecorte

              Glad it worked.

               

              I believe my C# source code for fmDotNet (www.fmdotnet.org) contains some commented out C# code to use the ActiveX interface.  That may give you some pointers as to how to do it from C++?