- Donald Clayton
- PowerBuilder
- Wednesday, 31 May 2023 10: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?
Find Questions by Tag
Helpful?
If a reply or comment is helpful for you, please don’t hesitate to click the Helpful button. This action is further confirmation of their invaluable contribution to the Appeon Community.