Create COM-Object from own C# Dll in Progress 4GL

2019-05-21 02:05发布

问题:

I'm wondering how I can create a Com-Object from my own C# DLL.

I made the following Class in C#:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace ProgressNet
{
    [Guid("a9b1e34d-3ea3-4e91-a77a-5bcb25875485")]
    [ClassInterface(ClassInterfaceType.AutoDual)]
    [ComVisible(true)]
    [ProgId("ProgressNet.Server")]
    public class NetServer
    {
        public NetServer() {}

        [DispId(1)]
        public string GetString()
        {
            return "Some String";
        }
    }
}

In Properties I checked Register for COM Interop.

Then I registered the DLL with regasm.

regasm G:\ProgressTestApp\ProgressNet.dll /tlb:G:\ProgressTestApp\ProgressNet.tlb /codebase

Then I tried in Progress 4GL this Code:

DEFINE VARIABLE NetServer AS COM-HANDLE.
CREATE "ProgressNet.NetServer" NetServer.  
MESSAGE NetServer:GetString().

But then I get "The automation server for ProgressNet.NetServer is not registered properly"..

Any Suggestions? :)

回答1:

IN case anyone is still reading this, the answer turns out to be pretty simple: The following line is wrong.

MESSAGE NetServer::GetString().

It should be

MESSAGE NetServer:GetString().


回答2:

The error is in the create com-handle statement. It should be create "ProgressNet.Server" NetServer. and not "ProgressNet.NetServer" as specified by the ProgId call.

I registered the DLL with regasm as you mentioned and used the code below to test and it worked fine.

def var ch as com-handle no-undo.

create "ProgressNet.Server" ch.

MESSAGE ch:GetString()
    VIEW-AS ALERT-BOX INFO BUTTONS OK.