PHP and COM

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • X

    PHP and COM

    When I run this code in PHP, it works for the first time, but when I
    try reloading it again, Apache complains of access violation errors.
    Got any ideas?

    <?php
    // starting word
    $word = new COM("word.appli cation") or die("Unable to instantiate
    Word");
    echo "Loaded Word, version {$word->Version}\n";

    //bring it to front
    $word->Visible = 1;

    //open an empty document
    $word->Documents->Add();

    //closing word
    $word->Quit();

    //free the object
    $word = null;
    ?>
  • Richard

    #2
    Re: PHP and COM


    "X" <xethyr@gmail.c omwrote in message
    news:39e69842-62b6-41ef-b64f-fea18e366f8c@26 g2000hsk.google groups.com...
    When I run this code in PHP, it works for the first time, but when I
    try reloading it again, Apache complains of access violation errors.
    Got any ideas?
    >
    <?php
    // starting word
    $word = new COM("word.appli cation") or die("Unable to instantiate
    Word");
    echo "Loaded Word, version {$word->Version}\n";
    >
    //bring it to front
    $word->Visible = 1;
    >
    //open an empty document
    $word->Documents->Add();
    >
    //closing word
    $word->Quit();
    >
    //free the object
    $word = null;
    ?>
    Which versions of
    PHP
    Word
    Apache
    OS

    etc etc?

    R.


    Comment

    • purcaholic

      #3
      Re: PHP and COM

      On 6 Okt., 17:01, X <xet...@gmail.c omwrote:
      When I run this code in PHP, it works for the first time, but when I
      try reloading it again, Apache complains of access violation errors.
      Got any ideas?
      >
      <?php
      // starting word
      $word = new COM("word.appli cation") or die("Unable to instantiate
      Word");
      echo "Loaded Word, version {$word->Version}\n";
      >
      //bring it to front
      $word->Visible = 1;
      >
      //open an empty document
      $word->Documents->Add();
      >
      //closing word
      $word->Quit();
      >
      //free the object
      $word = null;
      ?>
      The code should work, i suppose this is a bug or a missconfigurati on
      somewhere (Apache, PHP, OS)...

      Regards,
      purcaholic

      Comment

      • Jim Carlock

        #4
        Re: PHP and COM

        "X" wrote...
        When I run this code in PHP, it works for the first time, but when I
        try reloading it again, Apache complains of access violation errors.
        Got any ideas?
        >
        <?php
        // starting word
        $word = new COM("word.appli cation") or die("Unable to instantiate
        Word");
        echo "Loaded Word, version {$word->Version}\n";
        >
        //bring it to front
        $word->Visible = 1;
        >
        //open an empty document
        $word->Documents->Add();
        >
        //closing word
        $word->Quit();
        >
        //free the object
        $word = null;
        ?>
        Try...

        //open an empty document
        $word->Documents->Add();
        $word->Documents->Close();

        I imagine it's possible that you're not closing the document
        you opened when you try to shut down Word. You might need to
        throw an index as the Documents[] may be an array.

        I would use more appropriate variable names as well. Something
        along the lines of...

        $oMS_Word = new COM("word.appli cation");
        // check for $oMS_Word object or check for error.

        When you create a new document, word usually asks if you'd like
        to save the document. So you might want check for return values
        when closing the document.

        I'm interested in this topic for other reasons. I do not want to
        open Word documents, I want to connect to a .dll and create an
        object from a specific DLL file.

        --
        Jim Carlock
        You Have More Than Five Senses


        Comment

        Working...