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

落爺英雄遲暮 提交于 2020-01-13 19:53:28

问题


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.


来源:https://stackoverflow.com/questions/11688009/create-com-object-from-own-c-sharp-dll-in-progress-4gl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!