Highlighted
Absent Member.
Absent Member.
1470 views

VC to NE

Jump to solution

Hi,

Ive got the VC code below that I need to work in NetExpress which I presume will use x"91" can anyone advise how I need to code it?

The program EscapeSequence is written in C# or C++

declare pDC as type System.IntPtr = e::Graphics::GetHdc
set ws-string to w-st-unlock-settings
set escape-string-length to size of ws-string::TrimEnd(" ")
invoke type EscapeSequence.ClassCode::Print(pDC, xstart, ystart, ws-string, escape-string-length, w-align, ws-drawcolor, x-size1, xrotate, escape-font-style, escape-font-name);
invoke e::Graphics::ReleaseHdc(pDC)

 

Convert using :-

call x"91" using ????

0 Likes
1 Solution

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

If you wish to call managed .NET code from native code then you would have to compile the .NET assembly as a Class Library (.DLL) and register it for COMInterop. You could then use the OLE class library support in native NX (or VC) to create an instance of the class and then invoke its methods.

The Print method that you are using may have a problem because it is expecting the hDC to be an IntPtr and I cannot find a method of passing a native pointer to a managed IntPtr without getting a parameter error.

Do you have control over the sources for EscapeSequence.ClassCode?

The alternative would be to create a wrapper .NET class, perhaps in COBOL that would accept the parameter as a binary-long instead of an IntPtr and then convert it before making the call to the actual Print method.

The other alternative is to handle all of the print functionality including the hDC functions within the .NET side.

You did not show what your parameters looked like so I just guessed here:

This is what a wrapper class might look like:

 

       interface-id IClassCode.
       method-id PrintWrapper.
       procedure division using by value pDC as binary-long,
                                         xstart as binary-long, 
                                         ystart as binary-long,
                                by reference ws-string as string,
                                by value escape-string-length as binary-long,
                                         w-align as binary-long, 
                                         ws-drawcolor as binary-long, 
                                         x-size1 as binary-long, 
                                         xrotate as binary-long, 
                                         escape-font-style as binary-long, 
                                         by reference escape-font-name as string.
       end method.
       end interface.
       class-id EscapeSequence.ClassCode implements type IClassCode.
       
       working-storage section.
       01 hDC binary-long.
       method-id PrintWrapper.
       local-storage section.
       01 pDC   type IntPtr.
       procedure division using by value hDC as binary-long,
                                         xstart as binary-long, 
                                         ystart as binary-long,
                                by reference ws-string as string,
                                by value escape-string-length as binary-long,
                                         w-align as binary-long, 
                                         ws-drawcolor as binary-long, 
                                         x-size1 as binary-long, 
                                         xrotate as binary-long, 
                                         escape-font-style as binary-long, 
                                         by reference escape-font-name as string.
           set pDC to hDC as type IntPtr
           *> make the actual call to your Print method here:

           goback.
       end method.

       end class.



and the NX client could look like: (this is adapted from the demo code for the PC_PRINT_INFO function and allows the user to select the printer and then gets information about it including the hDC.


      $set ooctrl(+p)
       identification division.
       program-id. EscapeClient.

       environment division.
       class-control.
           EscapeClass is class "$OLE$EscapeSequence.ClassCode".
       
       data division.
       working-storage section.
       copy "cbltypes.cpy".
       01 print-info.
          03 pi-struct-size      cblt-os-size.
          03 hdc                 cblt-pointer.
          03 hDC-binary redefines hDC pic x(4) comp-5.
          03 hps                 cblt-os-size.
          03 orientation         pic x(4) comp-5.
          03 rows                pic x(4) comp-5.
          03 cols                pic x(4) comp-5.
          03 rows-left           pic x(4) comp-5. 
          03 max-horiz           pic x(4) comp-5.
          03 max-vert            pic x(4) comp-5.
          03 min-horiz           pic x(4) comp-5.
          03 min-vert            pic x(4) comp-5.
          03 curr-horiz          pic x(4) comp-5.
          03 curr-vert           pic x(4) comp-5.
          03 copies              pic 9(4) comp-5.
          03 quality             pic 9(4) comp-5.
          03 color               pic 99 comp-5.
          03 reserved1           pic x comp-5.
          03 driver-ver          pic 9(4) comp-5.
          03 pname.
             05 cbsize            cblt-os-size.
             05 buffer            pointer.
          03 ptype.
             05 cbsize            cblt-os-size.
             05 buffer            pointer.
          03 pdevice.
             05 cbsize            cblt-os-size.
             05 buffer            pointer.
          03 plocation.
             05 cbsize            cblt-os-size.
             05 buffer            pointer.
          03 pcomment.
             05 cbsize            cblt-os-size.
             05 buffer            pointer.
          03 ppapersize.
             05 cbsize            cblt-os-size.
             05 buffer            pointer.
       01.
          03 document-title.
             05 title-len         pic x(2) comp-5.
             05 title-text        pic x(20).
          03 font-family.
             05 font-family-namelen  pic x(2) comp-5 value 80.
             05 font-family-name     pic x(80).
          03 abort               pic x(4) comp-5 value 1.
          03 control1            pic x(4) comp-5 value 2.
          03 flags               pic x(4) comp-5 value 3.
          03 handle              pic x(4) comp-5.
       01 cblt-pi-printer-name          pic x(255).
       01 cblt-pi-printer-type          pic x(255).
       01 cblt-pi-printer-device        pic x(255).
       01 cblt-pi-printer-location      pic x(255).
       01 cblt-pi-printer-comment       pic x(255).
       01 cblt-pi-printer-papersize     pic x(255).
       01 xstart pic x(4) comp-5 value zeroes.
       01 ystart pic x(4) comp-5 value zeroes.
       01 ws-string pic x(100) value "test".
       01 escape-string-length pic x(4) comp-5 value zeroes.
       01 w-align pic x(4) comp-5 value zeroes.
       01 ws-drawcolor pic x(4) comp-5 value zeroes.
       01 x-size1 pic x(4) comp-5 value zeroes.
       01 xrotate pic x(4) comp-5 value zeroes. 
       01 escape-font-style pic x(4) comp-5 value zeroes.
       01 escape-font-name pic x(100) value "Times New Roman".
       01 anInstance    object reference. 
      * copy "MFOLE.CPY".
       procedure division.
           perform 100-open-printer
           if return-code = zero
              perform 105-printer-info
              if return-code = zero
                 perform 110-display-printer-info
                 perform 115-managed-print-function
              end-if
              perform 120-close-printer
           end-if
           goback.

       100-open-printer.

           move 17 to title-len
           move "Printer Info Test" to title-text
           call "PC_PRINTER_OPEN" using by reference handle
                                 by reference document-title
                                 by value flags
                                 by value 0
           end-call.

       105-printer-info.

           move all x"0" to print-info
           move length of print-info to pi-struct-size
           set buffer of pname of print-info
              to address of cblt-pi-printer-name
           move 255 to cbsize of pname of print-info
           set buffer of ptype of print-info
              to address of cblt-pi-printer-type
           move 255 to cbsize of ptype of print-info
           set buffer of pdevice of print-info
              to address of cblt-pi-printer-device
           move 255 to cbsize of pdevice of print-info
           set buffer of plocation of print-info
              to address of cblt-pi-printer-location
           move 255 to cbsize of plocation of print-info
           set buffer of pcomment of print-info
              to address of cblt-pi-printer-comment
           move 255 to cbsize of pcomment of print-info
           set buffer of ppapersize of print-info
              to address of cblt-pi-printer-papersize
           move 255 to cbsize of ppapersize of print-info
           call "PC_PRINTER_INFO" using by reference handle
                                        by reference print-info
           end-call.

       110-display-printer-info.
               
           display "Orientation   : " orientation of print-info
           display "Rows          : " rows of print-info
           display "Cols          : " cols of print-info
           display "Rows Left     : " rows-left of print-info
           display "Max horz      : " max-horiz of print-info
           display "Max vert      : " max-vert of print-info
           display "Min horz      : " min-horiz of print-info
           display "Min vert      : " min-vert of print-info
           display "Current horz  : " curr-horiz of print-info
           display "Current vert  : " min-vert of print-info
           display "Copies        : " copies of print-info
           display "Quality       : " no advancing
           evaluate quality of print-info
              when 0 display "Draft"
              when 1 display "Low"
              when 2 display "Medium"
              when 3 display "High"
              when 4 display "printers default used"
              when other display quality of print-info " DPI"
           end-evaluate
           display "Color         : " no advancing
           if color of print-info equals 0
              display "Mono Chrome"
           else
              display "Color"
           end-if
           if cbsize of pname of print-info equal 0
              display "Printer name  : not available"
           else
              display "Printer name  : "
                 cblt-pi-printer-name(1:cbsize of pname of print-info)
              display "Printer name  size : "
                 cbsize of pname of print-info
           end-if
           if cbsize of ptype of print-info equal 0
              display "Printer type  : not available"
           else
              display "Printer type  : "
                 cblt-pi-printer-type(1:cbsize of ptype of print-info)
              display "Printer type size : "
                 cbsize of ptype of print-info
           end-if
           if cbsize of pdevice of print-info equal 0
              display "Printer device: not available"
           else
              display "Printer device(s): "
                 cblt-pi-printer-device(1:
                    cbsize of pdevice of print-info)
              display "Printer device size : "
                 cbsize of pdevice of print-info
           end-if
           if cbsize of plocation of print-info equal 0
              display "Printer location: not available"
           else
              display "Printer location: "
                 cblt-pi-printer-location(1:
                    cbsize of plocation of print-info)
              display "Printer location size : "
                 cbsize of plocation of print-info
           end-if
           if cbsize of pcomment of print-info equal 0
              display "Printer comment: not available"
           else
              display "Printer comment: "
                 cblt-pi-printer-comment(1:
                   cbsize of pcomment of print-info)
              display "Printer comment size : "
                   cbsize of pcomment of print-info
           end-if
           if cbsize of ppapersize of print-info equal 0
              display "Printer papersize: not available"
           else
              display "Printer papersize: "
                 cblt-pi-printer-papersize(1:
                     cbsize of ppapersize of print-info)
              display "Printer papersize size : "
                 cbsize of ppapersize of print-info
           end-if
           display "Driver version : "driver-ver of print-info.
          
       115-managed-print-function.

           invoke EscapeClass "New" returning anInstance
           
           invoke anInstance "PrintWrapper" 
              using by value hDC-binary,
                             xstart, 
                             ystart,
                    by reference ws-string, 
                    by value escape-string-length,
                             w-align, 
                             ws-drawcolor,
                             x-size1,
                             xrotate, 
                             escape-font-style,
                    by reference escape-font-name
            end-invoke.
       
       120-close-printer.

           call "PC_PRINTER_CONTROL" using by reference handle
                                    by value abort
           end-call

           call "PC_PRINTER_CLOSE" using by reference handle
           end-call.
    .
       

View solution in original post

0 Likes
7 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

There is no x"91" function available for manipulating the Device Context in native code but you can do this either through WinAPI calls like GetDC or GetDCEx or indirectly through our PC_PRINTER library routines like PC_PRINTER_INFO which will return an hDC value for a specified printer.

What is it exactly that you are attempting to do?

0 Likes
Highlighted
Absent Member.
Absent Member.
Ok thanks Chris, so what would that code look like using a WinAPI call?

We have written a piece of code in C++ to print something using VC however we also support older versions of this program written using NetExpress.

We know the function works in VC just need to know how to call it in NetExpress native code.

We call EscapeSequence.ClassCode::Print and past it parameters
0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert
I am a bit confused about what it is you wish to do here.

Do you wish to call the VC managed code version of EscapeSequence.ClassCode from a native NX program or do you have a native version of this same code written in C++ that you wish to call from a native NX program?
0 Likes
Highlighted
Absent Member.
Absent Member.
Ok I want to call EscapeSequence.ClassCode from a native NX program.
0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

If you wish to call managed .NET code from native code then you would have to compile the .NET assembly as a Class Library (.DLL) and register it for COMInterop. You could then use the OLE class library support in native NX (or VC) to create an instance of the class and then invoke its methods.

The Print method that you are using may have a problem because it is expecting the hDC to be an IntPtr and I cannot find a method of passing a native pointer to a managed IntPtr without getting a parameter error.

Do you have control over the sources for EscapeSequence.ClassCode?

The alternative would be to create a wrapper .NET class, perhaps in COBOL that would accept the parameter as a binary-long instead of an IntPtr and then convert it before making the call to the actual Print method.

The other alternative is to handle all of the print functionality including the hDC functions within the .NET side.

You did not show what your parameters looked like so I just guessed here:

This is what a wrapper class might look like:

 

       interface-id IClassCode.
       method-id PrintWrapper.
       procedure division using by value pDC as binary-long,
                                         xstart as binary-long, 
                                         ystart as binary-long,
                                by reference ws-string as string,
                                by value escape-string-length as binary-long,
                                         w-align as binary-long, 
                                         ws-drawcolor as binary-long, 
                                         x-size1 as binary-long, 
                                         xrotate as binary-long, 
                                         escape-font-style as binary-long, 
                                         by reference escape-font-name as string.
       end method.
       end interface.
       class-id EscapeSequence.ClassCode implements type IClassCode.
       
       working-storage section.
       01 hDC binary-long.
       method-id PrintWrapper.
       local-storage section.
       01 pDC   type IntPtr.
       procedure division using by value hDC as binary-long,
                                         xstart as binary-long, 
                                         ystart as binary-long,
                                by reference ws-string as string,
                                by value escape-string-length as binary-long,
                                         w-align as binary-long, 
                                         ws-drawcolor as binary-long, 
                                         x-size1 as binary-long, 
                                         xrotate as binary-long, 
                                         escape-font-style as binary-long, 
                                         by reference escape-font-name as string.
           set pDC to hDC as type IntPtr
           *> make the actual call to your Print method here:

           goback.
       end method.

       end class.



and the NX client could look like: (this is adapted from the demo code for the PC_PRINT_INFO function and allows the user to select the printer and then gets information about it including the hDC.


      $set ooctrl(+p)
       identification division.
       program-id. EscapeClient.

       environment division.
       class-control.
           EscapeClass is class "$OLE$EscapeSequence.ClassCode".
       
       data division.
       working-storage section.
       copy "cbltypes.cpy".
       01 print-info.
          03 pi-struct-size      cblt-os-size.
          03 hdc                 cblt-pointer.
          03 hDC-binary redefines hDC pic x(4) comp-5.
          03 hps                 cblt-os-size.
          03 orientation         pic x(4) comp-5.
          03 rows                pic x(4) comp-5.
          03 cols                pic x(4) comp-5.
          03 rows-left           pic x(4) comp-5. 
          03 max-horiz           pic x(4) comp-5.
          03 max-vert            pic x(4) comp-5.
          03 min-horiz           pic x(4) comp-5.
          03 min-vert            pic x(4) comp-5.
          03 curr-horiz          pic x(4) comp-5.
          03 curr-vert           pic x(4) comp-5.
          03 copies              pic 9(4) comp-5.
          03 quality             pic 9(4) comp-5.
          03 color               pic 99 comp-5.
          03 reserved1           pic x comp-5.
          03 driver-ver          pic 9(4) comp-5.
          03 pname.
             05 cbsize            cblt-os-size.
             05 buffer            pointer.
          03 ptype.
             05 cbsize            cblt-os-size.
             05 buffer            pointer.
          03 pdevice.
             05 cbsize            cblt-os-size.
             05 buffer            pointer.
          03 plocation.
             05 cbsize            cblt-os-size.
             05 buffer            pointer.
          03 pcomment.
             05 cbsize            cblt-os-size.
             05 buffer            pointer.
          03 ppapersize.
             05 cbsize            cblt-os-size.
             05 buffer            pointer.
       01.
          03 document-title.
             05 title-len         pic x(2) comp-5.
             05 title-text        pic x(20).
          03 font-family.
             05 font-family-namelen  pic x(2) comp-5 value 80.
             05 font-family-name     pic x(80).
          03 abort               pic x(4) comp-5 value 1.
          03 control1            pic x(4) comp-5 value 2.
          03 flags               pic x(4) comp-5 value 3.
          03 handle              pic x(4) comp-5.
       01 cblt-pi-printer-name          pic x(255).
       01 cblt-pi-printer-type          pic x(255).
       01 cblt-pi-printer-device        pic x(255).
       01 cblt-pi-printer-location      pic x(255).
       01 cblt-pi-printer-comment       pic x(255).
       01 cblt-pi-printer-papersize     pic x(255).
       01 xstart pic x(4) comp-5 value zeroes.
       01 ystart pic x(4) comp-5 value zeroes.
       01 ws-string pic x(100) value "test".
       01 escape-string-length pic x(4) comp-5 value zeroes.
       01 w-align pic x(4) comp-5 value zeroes.
       01 ws-drawcolor pic x(4) comp-5 value zeroes.
       01 x-size1 pic x(4) comp-5 value zeroes.
       01 xrotate pic x(4) comp-5 value zeroes. 
       01 escape-font-style pic x(4) comp-5 value zeroes.
       01 escape-font-name pic x(100) value "Times New Roman".
       01 anInstance    object reference. 
      * copy "MFOLE.CPY".
       procedure division.
           perform 100-open-printer
           if return-code = zero
              perform 105-printer-info
              if return-code = zero
                 perform 110-display-printer-info
                 perform 115-managed-print-function
              end-if
              perform 120-close-printer
           end-if
           goback.

       100-open-printer.

           move 17 to title-len
           move "Printer Info Test" to title-text
           call "PC_PRINTER_OPEN" using by reference handle
                                 by reference document-title
                                 by value flags
                                 by value 0
           end-call.

       105-printer-info.

           move all x"0" to print-info
           move length of print-info to pi-struct-size
           set buffer of pname of print-info
              to address of cblt-pi-printer-name
           move 255 to cbsize of pname of print-info
           set buffer of ptype of print-info
              to address of cblt-pi-printer-type
           move 255 to cbsize of ptype of print-info
           set buffer of pdevice of print-info
              to address of cblt-pi-printer-device
           move 255 to cbsize of pdevice of print-info
           set buffer of plocation of print-info
              to address of cblt-pi-printer-location
           move 255 to cbsize of plocation of print-info
           set buffer of pcomment of print-info
              to address of cblt-pi-printer-comment
           move 255 to cbsize of pcomment of print-info
           set buffer of ppapersize of print-info
              to address of cblt-pi-printer-papersize
           move 255 to cbsize of ppapersize of print-info
           call "PC_PRINTER_INFO" using by reference handle
                                        by reference print-info
           end-call.

       110-display-printer-info.
               
           display "Orientation   : " orientation of print-info
           display "Rows          : " rows of print-info
           display "Cols          : " cols of print-info
           display "Rows Left     : " rows-left of print-info
           display "Max horz      : " max-horiz of print-info
           display "Max vert      : " max-vert of print-info
           display "Min horz      : " min-horiz of print-info
           display "Min vert      : " min-vert of print-info
           display "Current horz  : " curr-horiz of print-info
           display "Current vert  : " min-vert of print-info
           display "Copies        : " copies of print-info
           display "Quality       : " no advancing
           evaluate quality of print-info
              when 0 display "Draft"
              when 1 display "Low"
              when 2 display "Medium"
              when 3 display "High"
              when 4 display "printers default used"
              when other display quality of print-info " DPI"
           end-evaluate
           display "Color         : " no advancing
           if color of print-info equals 0
              display "Mono Chrome"
           else
              display "Color"
           end-if
           if cbsize of pname of print-info equal 0
              display "Printer name  : not available"
           else
              display "Printer name  : "
                 cblt-pi-printer-name(1:cbsize of pname of print-info)
              display "Printer name  size : "
                 cbsize of pname of print-info
           end-if
           if cbsize of ptype of print-info equal 0
              display "Printer type  : not available"
           else
              display "Printer type  : "
                 cblt-pi-printer-type(1:cbsize of ptype of print-info)
              display "Printer type size : "
                 cbsize of ptype of print-info
           end-if
           if cbsize of pdevice of print-info equal 0
              display "Printer device: not available"
           else
              display "Printer device(s): "
                 cblt-pi-printer-device(1:
                    cbsize of pdevice of print-info)
              display "Printer device size : "
                 cbsize of pdevice of print-info
           end-if
           if cbsize of plocation of print-info equal 0
              display "Printer location: not available"
           else
              display "Printer location: "
                 cblt-pi-printer-location(1:
                    cbsize of plocation of print-info)
              display "Printer location size : "
                 cbsize of plocation of print-info
           end-if
           if cbsize of pcomment of print-info equal 0
              display "Printer comment: not available"
           else
              display "Printer comment: "
                 cblt-pi-printer-comment(1:
                   cbsize of pcomment of print-info)
              display "Printer comment size : "
                   cbsize of pcomment of print-info
           end-if
           if cbsize of ppapersize of print-info equal 0
              display "Printer papersize: not available"
           else
              display "Printer papersize: "
                 cblt-pi-printer-papersize(1:
                     cbsize of ppapersize of print-info)
              display "Printer papersize size : "
                 cbsize of ppapersize of print-info
           end-if
           display "Driver version : "driver-ver of print-info.
          
       115-managed-print-function.

           invoke EscapeClass "New" returning anInstance
           
           invoke anInstance "PrintWrapper" 
              using by value hDC-binary,
                             xstart, 
                             ystart,
                    by reference ws-string, 
                    by value escape-string-length,
                             w-align, 
                             ws-drawcolor,
                             x-size1,
                             xrotate, 
                             escape-font-style,
                    by reference escape-font-name
            end-invoke.
       
       120-close-printer.

           call "PC_PRINTER_CONTROL" using by reference handle
                                    by value abort
           end-call

           call "PC_PRINTER_CLOSE" using by reference handle
           end-call.
    .
       

View solution in original post

0 Likes
Highlighted
Absent Member.
Absent Member.
Hi Chris,

Ok I tried above but its not working can you pls advise?

We registered the .dll on the machine, using RegAsm based on the correct .NET version, and it registered successfully. However the error message makes me think it might not be visible to the project for some reason.

The "cut down" Cobol Code is:-

$set ooctrl(+p)
identification division.
program-id. EscapeClient.

environment division.
class-control.
EscapeClass is class "$OLE$EscapeSequence.EscapeWrapper".

*****************

01 anInstance object reference.

********************

115-managed-print-function.

invoke EscapeClass "New" returning anInstance *> where the error message is arising

invoke anInstance "Print"
using by value hDC-binary,
xstart,
ystart,
by reference ws-string,
by value escape-string-length,
w-align,
ws-drawcolor,
x-size1,
xrotate,
escape-font-style,
by reference escape-font-name
end-invoke.

The error message Im getting is:-

Exception 65537 not trapped by the class oleexceptionmanager.
Description: "Server Defined OLE Exception"
<000401F3>: Invalid class string

The C# code Im calling is:-

using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Runtime.InteropServices;

namespace EscapeSequence
{
class EscapeWrapper
{

public EscapeWrapper(IntPtr Graphics)
{

Handle = Graphics;

}



[DllImport("gdi32.dll", EntryPoint = "Escape",
CharSet = CharSet.Auto, SetLastError = true)]
private static extern int Escape
(IntPtr Hdc, int nEscape, int ncount, IntPtr inData, IntPtr outData);

private const int PASSTHROUGH = 19;
private IntPtr Handle;
private Graphics graphics;

public static IntPtr IntToPtr(System.Int64 pnt)

{
IntPtr pointer = new IntPtr(pnt);
return pointer;
}


public bool SendPassThroughExt(string PassthroughData)
{
return sendPassThrough(PassthroughData, Handle);
}

private bool sendPassThrough(string Passthroughdata, IntPtr handle)
{
IntPtr grp = handle;
bool RetVal = false;
IntPtr pData = string2Global(Passthroughdata, true);
try
{
int id = Escape(grp, PASSTHROUGH, 0, pData, IntPtr.Zero);
RetVal = id > 0;
}
finally
{
Marshal.FreeHGlobal(pData);
}
return RetVal;
}
public bool SendPassThrough(string PassthroughData)
{
bool RetVal = false;
IntPtr grp = graphics.GetHdc();
try
{
RetVal = sendPassThrough(PassthroughData, grp);
}
finally
{
graphics.ReleaseHdc(grp);
}
return RetVal;
}
private IntPtr string2Global(string Data, bool includeSize)
{
int l = Data.Length;
int offset = 0;
if (includeSize)
{
l += 2;
offset = 2;
}
IntPtr RetVal = Marshal.AllocHGlobal(l);
short s = (short)Data.Length;
byte[] buf = new byte;
if (includeSize)
{
buf[1] = (byte)(s >> 8);
buf[0] = (byte)s;
}

System.Text.Encoding.Default.GetBytes(Data, 0, Data.Length, buf, offset);
for (int i = 0; i < buf.Length; i++)
{
Marshal.WriteByte(RetVal, i, buf);
}
return RetVal;
}

/* main function to call and setup print. Accepts color, hdc context, xstart, ystart, string, string length, alignment
*/
static public bool Print(Int64 hdc, int nXStart, int nYStart,
string lpString, int cbString, uint align, Color color, int fontHeight, int xrotate, int fontStyle, string fontName)
{


IntPtr hdc1 = IntToPtr(hdc);


//// Create font. Escapement sets rotation. Set height manually and width is chosen automatically.
//// Must pass in font face as string, but it will be ignored as printer will use escape sequence to override the chosen font.
//// find docs here: msdn.microsoft.com/.../dd183499(v=vs.85).aspx
//HFONT CreateFont(
// _In_ int nHeight,
// _In_ int nWidth,
// _In_ int nEscapement,
// _In_ int nOrientation,
// _In_ int fnWeight,
// _In_ uint fdwItalic,
// _In_ uint fdwUnderline,
// _In_ DWORD fdwStrikeOut,
// _In_ DWORD fdwCharSet,
// _In_ DWORD fdwOutputPrecision,
// _In_ DWORD fdwClipPrecision,
// _In_ DWORD fdwQuality,
// _In_ DWORD fdwPitchAndFamily,
// _In_ LPCTSTR lpszFace
//);
IntPtr hFont = CreateFont(fontHeight, 0, xrotate, 0, 300, 0, 0, 0, 0, 1,
0, 0, 0, fontName);
SelectObject(hdc1, hFont); // select font into context


String newString = lpString;

EscapePrintHelper escapeHelper = new EscapePrintHelper(hdc1);

newString = newString.TrimEnd(' ');
escapeHelper.SendPassThroughExt(newString);


return true;
}


//set font
[System.Runtime.InteropServices.DllImport("gdi32.dll")]
static public extern IntPtr CreateFont(int nHeight, int nWidth, int nEscapement,
int nOrientation, int fnWeight, uint fdwItalic, uint fdwUnderline, uint
fdwStrikeOut, uint fdwCharSet, uint fdwOutputPrecision, uint
fdwClipPrecision, uint fdwQuality, uint fdwPitchAndFamily, string lpszFace);

//select object sets current object context
[System.Runtime.InteropServices.DllImport("gdi32.dll")]
static public extern IntPtr SelectObject(IntPtr hdc, IntPtr hgdiobj);

}
}
0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

What is the target CPU type of the C# class? It should be either x86 or x64 and not anyCPU and the bitism of the NX program must match so either 32-bit or 64-bit. You must also use the correct REGASM version for the bitism you are using.

Net Express has a tool called Type Library Assistant that can generate the COBOL client code snippets for any registered COM Server. On the NX Tools menu run Type Library Assistant, scroll through the list of available COM Servers until you locate yours and select it and choose to generate the code for it using Dual Interface. This will generate some COBOL sources that you can use as a reference for calling your various methods.

You may have to also mark your C# methods with the COMVisible attribute and create an interface for them so that they will be visible to COM.

Please see the Microsoft article here:

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.