WordPerfect COM Automation Error

0

In c# .Net 4.0 I am attempting to automate WordPerfect.

To do this I add a reference in my project to the wpwin14.tlb file that lives in the WordPerfect program folder.

That has the effect of creating the COM interfaces within my project.

Next I should be able to write code that instantiates a WordPerfect.PerfectScript object that I can use to automate WordPerfect.

However, when I try to instantiate the WordPerfect.PerfectScript object c# throws the error:

"Unable to cast COM object of type 'System.__ComObject' to interface type 'WordPerfect.PerfectScript'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{C0E20006-0004-1000-0001-C0E1C0E1C0E1}' failed due to the following error: The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)."

The thing to zero in on in that message (I do believe) is that the RPC server is unavailable.

I have tried this with WordPerfect running in the background and without. And I have gone to my services and made sure that RPC services were all running and restarting everything.

Is it possible that I am getting blocked by a firewall? That is my only faintest guess

c#-4.0
com
wordperfect
asked on Stack Overflow Mar 5, 2015 by Chad • edited Mar 5, 2015 by GrAnd

2 Answers

1

I just wrap it as an OLE call and clean up my COM object with FinalReleaseComObject.

Here's a simple wrapper class I've been using to open Wp docs and convert them to pdf. It cleans up nicely in our automated process:

public class WpInterop : IDisposable
{
    private bool _disposed;
    private PerfectScript _perfectScript;

    public PerfectScript PerfectScript
    {
        get
        {
            if (_perfectScript == null)
            {
                Type psType = Type.GetTypeFromProgID("WordPerfect.PerfectScript");
                _perfectScript = Activator.CreateInstance(psType) as PerfectScript;
            }
            return _perfectScript;
        }
    }

    protected void Dispose(bool disposing)
    {
        if (disposing)
        {
            Marshal.FinalReleaseComObject(_perfectScript);
        }
        _disposed = true;
    }

    public void Dispose()
    {
        if (_disposed == false)
        {
            GC.SuppressFinalize(this);
            Dispose(true);
        }
    }
}
answered on Stack Overflow Mar 9, 2015 by AlexB
0

Make sure your version of WordPerfect has all of the service packs and hot fixes installed. This step has fixed many random-sounding issues for me over the years. Looks like you are using X4, which is no longer supported by Corel, which means that the updates are no longer on its web site. You should be running version 14.0.0.756 (SP2 plus 2 hotfixes).

I just uninstalled WPX4 and re-installed it, without the service pack updates. Running this code gave the exact error as the OP:

using System.Runtime.InteropServices;
using WordPerfect;

namespace WP14TLB
{


class Program
{
    static void Main(string[] args)
    {

        PerfectScript ps = new PerfectScript();
        ps.WPActivate();
        ps.KeyType("Hello WP World!");

        Marshal.ReleaseComObject(ps);
        ps = null;

    }
}
}

Installing the service packs "magically" fixed the problem.

BTW, for future reference, you can also try the WPUniverse forums. There are quite a few WP experts who regularly answer difficult questions.

There is also a link to the X4 updates here:

answered on Stack Overflow Mar 7, 2015 by Ric Gaudet • edited Mar 7, 2015 by Ric Gaudet

User contributions licensed under CC BY-SA 3.0