1. Malek Taha
  2. PowerBuilder
  3. Monday, 11 April 2022 19:32 PM UTC

Hi

   I have a .net assembly that i am trying to import into a powerbuilder 2019 R3 app. some classes fail.

The advise is to create a .net wrapper before importing.

I dont know how to do create a .net wrapper. 

Can you please help with a sample of how to create such wrapper?

 

Thanks

Malek

 

Attachments (1)
Andreas Mykonios Accepted Answer Pending Moderation
  1. Tuesday, 12 April 2022 06:52 AM UTC
  2. PowerBuilder
  3. # 1

Hi.

This is a sample of a wrapper for methods of PrintFunctions.

using System;
using GMaPSCommon;

namespace gmapscommonw
{
    public class gmapsSample
    {
        public void PrintRawText(string sText, string sPrinterName)
        {
            GMaPSCommon.PrintFunctions.PrintRawText(sText, sPrinterName);
        }
        public void PrintRawText(string sText, string sPrinterName, bool bDisplayDialog)
        {
            GMaPSCommon.PrintFunctions.PrintRawText(sText, sPrinterName, bDisplayDialog);
        }

    }
}

This is the easy part. The others have intPtr datatype, which is used to represent a pointer or a handle. I'm not sure how it should be wrapped as I don't really know how they should be called (we don't have any documentation). But I guess most of them should be used before calling PrintRawText. Anyway, it's harder to help you at this point, as I'm really not familiar with this class.

What you can do is to write a class with a method that will implement the whole logic in c# (I guess you want to somehow print something). You will test that your method works fine in c#. Your method should not be static, and should be public. Also it can should get as params only datatypes supported from powerbuilder. Following table can be found in the link John provided:

PowerBuilder

C#

Array (one and two dimension)

Reference

Generic Nullable<T>

int

short

Supported

Supported

Supported

uint

ushort

Supported

Supported

Supported

long

int

Supported

Supported

Supported

longptr

int32/int64

Supported

Supported

Supported

ulong

uint

Supported

Supported

Supported

longlong

long/Int64

Supported

Supported

Supported

boolean

bool

Supported

Supported

Supported

char

string/char

Supported

Supported

Supported

string

string

Supported

Supported

Unsupported

real

float

Supported

Supported

Supported

double

double

Supported

Supported

Supported

decimal

decimal

Supported

Supported

Supported

blob

byte[]

Supported

Supported

Supported

Date

DateTime

Supported

Supported

Supported

DateTime

DateTime

Supported

Supported

Supported

Time

DateTime

Supported

Supported

Supported

At the end you will have to use your class in PB, but you will have to deploy it with GMaPSCommon.dll.

Andreas.

Comment
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Monday, 11 April 2022 20:53 PM UTC
  2. PowerBuilder
  3. # 2

Hi, Malek - 

I found this in the PB documentation:

https://docs.appeon.com/pb2019r3/application_techniques/ch05s01.html

In particular, look on this web page for the heading "Adding an adapter for unsupported features".

HTH, John

Comment
There are no comments made yet.
Roland Smith Accepted Answer Pending Moderation
  1. Monday, 11 April 2022 20:57 PM UTC
  2. PowerBuilder
  3. # 3

A wrapper is just an assembly that you write in C# that has simple argument/return data types so that PowerBuilder can understand it. Then in your C# code you call functions in the assembly you need to work with.

Comment
There are no comments made yet.
Malek Taha Accepted Answer Pending Moderation
  1. Tuesday, 12 April 2022 17:31 PM UTC
  2. PowerBuilder
  3. # 4

Thanks Andreas

      Your response was very helpful. I was more concerned with the class using the pointer.

Yes i am trying to print a UPS label they send us via xml. The string is in the attached.

If i could just send that to a Zebra printer from powerbuilder would be great. if not a sample .net would be helpful.

I am totally not familiar with sending raw text and commands to a printer.

 

Please advise

Thanks again for the helpful response with the Wrapper

Thanks

Malek

 

 

Attachments (1)
Comment
  1. Andreas Mykonios
  2. Wednesday, 13 April 2022 07:08 AM UTC
Information in label txt is encoded? It is expected to be sent to the printer after some transformation or it should be sent as it is?

Gmapscommon.dll is part of some SDK? Is there any documentation? I do see available functions but some params aren't clear to me.

Andreas.
  1. Helpful
There are no comments made yet.
Malek Taha Accepted Answer Pending Moderation
  1. Wednesday, 13 April 2022 19:02 PM UTC
  2. PowerBuilder
  3. # 5

Hi Andreas

   Thanks again for helping me with this.

attached are two files one is the function call from Powerbuilder written in PB.net that we are trying to upgrade to 2019 R3.

The other is the visual studio solution of gmapscommon,

 

In answer to your questions : 

 

information in label txt is encoded? No It is expected to be sent to the printer after some transformation or it should be sent as it is? As is

Gmapscommon.dll is part of some SDK? Is there any documentation? I do see available functions but some params aren't clear to me. solution attached

Attachments (2)
Comment
There are no comments made yet.
Andreas Mykonios Accepted Answer Pending Moderation
  1. Thursday, 14 April 2022 08:42 AM UTC
  2. PowerBuilder
  3. # 6

Based on printraw.txt you call:

GMaPSCommon.PrintFunctions.PrintRawText( asDoc, asPrinter)

PrintRawText with two string arguments expects a base64 string:

sLabel = System.Text.Encoding.Default.GetString(Convert.FromBase64String(sText));

But contents of label.txt isn't base64: 0x53546773515377774D44454B5430514B635467784D6770524D5459774D4377794E41...

If you have a valid label (which is base64) then you can use the first method from following class:

using System;
/*using GMaPSCommon;*/

namespace gmapscommonw
{
    public class gmapsSample
    {
        public void PrintRawText(string sText, string sPrinterName)
        {
            GMaPSCommon.PrintFunctions.PrintRawText(sText, sPrinterName);
        }
        public void PrintRawText(string sText, string sPrinterName, bool bDisplayDialog)
        {
            GMaPSCommon.PrintFunctions.PrintRawText(sText, sPrinterName, bDisplayDialog);
        }

    }
}

This class can be compiled using c# to the framework you want to use (you have to choose one of those supported in powerbuilder).

.NET Standard

1.0

1.1

1.2

1.3

1.4

1.5

1.6

2.0

2.1

.NET Core

1.0

1.0

1.0

1.0

1.0

1.0

1.0

2.0

3.0

.NET Framework

4.5

4.5

4.5.1

4.6

4.6.1

4.6.1

4.6.1

4.6.1

N/A

You can add gmapscommon.cs to the new project. Otherwise you can add a reference to the appropriate dll and uncomment "using GMaPSCommon;" in the code above.

Andreas.

Comment
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.