PowerBuilder(作为 COM)中的 .NET dll 列表问题

发布于 2024-08-14 17:11:12 字数 1539 浏览 2 评论 0原文

所有,我正在尝试访问使用 PowerBuilder 10 注册为 COM 对象的 .NET dll。我不断遇到 .NET 对象返回列表的问题。

我构建了一个非常简单的类来证明概念,并更好地解释我所遇到的情况。请参见下文:

.NET:

public class ListsArrays
{
    public int[] GetArray()
    {
        int[] array = new int[3];
        array[0] = 1;
        array[1] = 10;
        array[2] = 100;

        return array;
    }

    public List<int> GetList()
    {
        List<int> list = new List<int>();
        list.Add(3);
        list.Add(33);
        list.Add(333);
        return list;
    }

    public int[] GetListArray()
    {
        List<int> list = new List<int>();
        list.Add(3);
        list.Add(33);
        list.Add(333);
        return list.ToArray();
    }
}

PowerBuilder:

Integer ls_array[]
Integer obj_return, ID, netVal
String FullName
OleObject lo_dotnetobject
OleObject lo_Value

lo_Value = Create OleObject
lo_dotnetobject = Create OleObject

obj_return = lo_dotnetobject.ConnectToNewObject("XXX.ListsArrays")

//This is the tricky part
ls_array = lo_dotnetobject.GetArray()         // WORKS          (1)
ls_array = lo_dotnetobject.GetList().ToArray()  // DOES NOT WORK  (2)
lo_dotnetobject.GetList().CopyTo(ls_array)    // DOES NOT WORK  (3)
ls_array = lo_dotnetobject.GetListArray()      // WORKS          (4)

对于“不起作用”的每个部分,我都会收到此错误消息:

“在行表达式中使用没有返回值的函数/事件”

显然,我可以换行我的 .NET 程序集,并为每个列表返回一个数组,但我希望能够在 PowerBuilder 端处理列表而不包装 .NET。有人有什么想法吗? (4) 有效而 (2) 无效这一事实让我有点抓狂。

谢谢。

All, I am trying to access a .NET dll registered as a COM Object with PowerBuilder 10. I keep running into problems where .NET objects return lists.

I have built out a very simple class for a proof of concept, and to better explain what I am encountering. See below:

.NET:

public class ListsArrays
{
    public int[] GetArray()
    {
        int[] array = new int[3];
        array[0] = 1;
        array[1] = 10;
        array[2] = 100;

        return array;
    }

    public List<int> GetList()
    {
        List<int> list = new List<int>();
        list.Add(3);
        list.Add(33);
        list.Add(333);
        return list;
    }

    public int[] GetListArray()
    {
        List<int> list = new List<int>();
        list.Add(3);
        list.Add(33);
        list.Add(333);
        return list.ToArray();
    }
}

PowerBuilder:

Integer ls_array[]
Integer obj_return, ID, netVal
String FullName
OleObject lo_dotnetobject
OleObject lo_Value

lo_Value = Create OleObject
lo_dotnetobject = Create OleObject

obj_return = lo_dotnetobject.ConnectToNewObject("XXX.ListsArrays")

//This is the tricky part
ls_array = lo_dotnetobject.GetArray()         // WORKS          (1)
ls_array = lo_dotnetobject.GetList().ToArray()  // DOES NOT WORK  (2)
lo_dotnetobject.GetList().CopyTo(ls_array)    // DOES NOT WORK  (3)
ls_array = lo_dotnetobject.GetListArray()      // WORKS          (4)

For each part that “DOES NOT WORK” I receive this error message:

“Function/event with no return value used in expression at line”

Obviously, I could just wrap my .NET assembly, and return an array for every list, but I would like to be able to handle lists on the PowerBuilder side without wrapping the .NET. Does anyone have any ideas? The fact that (4) works and (2) doesn’t work drives me kind of nuts.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

七度光 2024-08-21 17:11:12

我使用 Powerbuilder 已经有 10 多年了,但我想说 List 不起作用,只是因为它是一个通用列表,我认为它无法正确映射到COM 数组 - 这可以解释为什么 1 和 4 有效,但没有其他作用。您可以使用简单数组而不是通用列表吗?

It's been more than 10 years since I worked with Powerbuilder, but I would say that List<int> would not work simply because it is a generic list which I don't think can be correctly mapped to a COM array - that would explain why 1 and 4 works but nothing else. Can you work with simple arrays instead of generic lists?

找个人就嫁了吧 2024-08-21 17:11:12

我以前每天在向 COM 公开丰富的 .NET API 时都会处理这个问题。 COM 不理解泛型,但不要让它减慢您的速度 - 技巧是将泛型列表公开为 List 已公开的非泛型、com 可见的基本类型,如 IList。将 GetList 返回类型更改为 IList,重建/注册,并确保 Powerbuilder 看到您的固定类型库,一切都应该很好。

I used to deal with this every day when exposing rich .NET APIs to COM. COM doesn't understand generics, but don't let that slow you down- the trick is to expose the generic list as a non-generic, com-visible base type that List<int> already exposes, like IList. Change your GetList return type to IList, rebuild/register, and make sure that Powerbuilder sees your fixed typelib, and all should be well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文