1. Donald Clayton
  2. PowerBuilder
  3. Wednesday, 31 May 2023 22:36 PM UTC

At Intertech we're trying to use the .NET DLL importer, wehave a structure defined in PowerBuilder called columninfo which has four elements: a_name (string), s_dbname(string), l_columnidsource (long), and l_columnidtarget (long).  So the structure has two strings and two longs.

 We then created a C# class with the following code:

 

namespace S_Interface.Models

{

    public class s_columninfo

    {

        public string s_name { get; set; }

        public string s_dbname { get; set; }

        public int? l_columnidsource { get; set; }

        public int? l_columnidtarget { get; set; }

        public s_columninfo()

        {

            s_name = string.Empty;

            s_dbname = string.Empty;

            l_columnidsource = 0;

            l_columnidtarget = 0;

        }

        public bool setter(s_columninfo columninfo)

        {

            s_name = columninfo.s_name;

            s_dbname = columninfo.s_dbname;

            l_columnidsource = columninfo.l_columnidsource;

            l_columnidtarget= columninfo.l_columnidtarget;

            return true;

        }

        public bool test()

        {

            return true;

        }

    }

}

 

We then used the DLL importer and built the wrapper code to make calls into the C# DLL.  BTW there were no errors identified by the .DLL importer.

 The following PowerBuilder code works:

//Declare and Create the .NET assembly wrapper 

nvo_s_columninfo lnv_s_columninfo

lnv_s_columninfo = create nvo_s_columninfo

 

//create the .NET object

boolean b

b = lnv_s_columninfo.of_createondemand()

//passing in the individual elements of the structure works fine

//we can see everything in the SnapDevelop debugger. 

lnv_s_columninfo.set_s_dbname("dbname")

lnv_s_columninfo.set_s_name("name")

lnv_s_columninfo.set_l_columnidsource(1)

lnv_s_columninfo.set_l_columnidtarget(1)

 

 //The following code doesn't work for us.

//We can't seem to pass the structure in entirety, and by the time it gets to the .NET assembly it is null.

nvo_s_columninfo lnv_s_columninfo

lnv_s_columninfo = create nvo_s_columninfo

 

//declare our structure

s_columninfo sc;

//create our .NET wrapper 

boolean b

b = lnv_s_columninfo.of_createondemand()

 //populate the structure

sc.s_dbname = "dbname"

sc.s_name = "name"

sc.l_columnidsource = 1

sc.l_columnidtarget = 1

//pass the structure into the assmebly

lnv_s_columninfo.setter(sc)

 //in the .NET debugger the structure passed in by PB is seen as Null in C#

//The setter method in the C# DLL has received a null value for s_columninfo

Any suggesions would be appreciated.  What is possible when passing structures into .NET?

Donald Clayton Accepted Answer Pending Moderation
  1. Thursday, 1 June 2023 13:23 PM UTC
  2. PowerBuilder
  3. # 1

I guess I was optimistic that since our structure only used supported datatypes that we could pass it if we had an analogous C# class to receive it.  BTW, the C# migration assistant did a brilliant job of migrating the PB structure classes to .NET.  So we were hopeful.

Comment
There are no comments made yet.
Andreas Mykonios Accepted Answer Pending Moderation
  1. Thursday, 1 June 2023 06:18 AM UTC
  2. PowerBuilder
  3. # 2

Hi.

Maybe you could workaround that limitation by using json (or xml)?

Andreas.

Comment
There are no comments made yet.
Francisco Martinez @Appeon Accepted Answer Pending Moderation
  1. Wednesday, 31 May 2023 22:49 PM UTC
  2. PowerBuilder
  3. # 3

Hi Donald,

Passing custom structures to C# is currently not possible. See here for the list of supported data types that can be marshaled from PowerBuilder to C#. It's mostly native types, and Date/Time/DateTime objects. I don't know if there's plans for expanding this support to structs in the future... Hopefully someone from the product team can chime in.

Regards,
Francisco

Comment
  1. Donald Clayton
  2. Tuesday, 4 July 2023 16:04 PM UTC
One thing that threw us off was that the .NET DLL Importer wizard allowed us to map the structure to an identical class defined in our .NET DLL. If it's not possible to do that then the wizard shouldn't allow for that option.

Regardless, it would be a great enhancement to the .NET DLL importer to be able to pass in structures as long as the underlying datatypes in the structure map cleanly. Our intent was to use .NET to serialize a relatively complex structure as JSON, which can be done in about 3 lines of code in .NET. While having DWs describe themselves as JSON is great, it's a partial solution to a larger problem.

Another cool feature for future PB releases would be to allow a PowerObject to be serialized as JSON w/o doing a ton of work to accomplish it. So JSON serialize/deserialize methods for PowerObjects would bring the language in line with .NET CORE and/or NewtonSoft.
  1. Helpful 1
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.