From C# to SAL. Need a help

Discussion forum about all things Gupta, OpenText and the community.
aspurga
Lithuania
Posts: 54
Joined: 06 Mar 2017, 08:54
Location: Lithuania

From C# to SAL. Need a help

Post by aspurga » 07 Mar 2019, 15:28

Hello,

Just need to convert this piece of code written in C# to Gupta Sal.
I have no idea with System.Runtime.InteropServices.Marshal.AllocHGlobal and System.Runtime.InteropServices.Marshal.Copy in Gupta Sal?

Arunas


byte[] byte_buffer = File.ReadAllBytes(input_file);
IntPtr buffer = System.Runtime.InteropServices.Marshal.AllocHGlobal(byte_buffer.Length);
try {
System.Runtime.InteropServices.Marshal.Copy(byte_buffer, 0, buffer, byte_buffer.Length);
}
Finally {
System.Runtime.InteropServices.Marshal.FreeHGlobal(buffer);
}
PDFDoc doc = new PDFDoc(buffer, (uint)byte_buffer.Length);

thomas.uttendorfer
Site Admin
Site Admin
Germany
Posts: 167
Joined: 05 Mar 2017, 17:19
Location: Munich Germany

Re: From C# to SAL. Need a help

Post by thomas.uttendorfer » 08 Mar 2019, 09:37

Hi Arunas,

first you have to make a .apl via .NET Explorer (or ActiveX explorer if your PDF-component is a COM-Object).
This builds a wrapper so the methods from you PDF-component are then exposed to Gupta.

Include the created .apl-File in your project.

Regards Thomas
Thomas Uttendorfer
[ frevel & fey ] Software-System GmbH
https://thomasuttendorfer.wordpress.com/

aspurga
Lithuania
Posts: 54
Joined: 06 Mar 2017, 08:54
Location: Lithuania

Re: From C# to SAL. Need a help

Post by aspurga » 08 Mar 2019, 12:26

Hi Thomas,

Sure I did it.
In apl I see
Function: OpenMemFile
Description:
Returns
Boolean:
Parameters
Number: pBuffer
Number: size
String: Password
Receive Boolean: returnValue
Static Variables
Local variables
Boolean: tmpret
Actions

I understand that I need to allocate memory.

Arunas

thomas.uttendorfer
Site Admin
Site Admin
Germany
Posts: 167
Joined: 05 Mar 2017, 17:19
Location: Munich Germany

Re: From C# to SAL. Need a help

Post by thomas.uttendorfer » 08 Mar 2019, 12:55

Hi Arunas,
just take a String (or maybe a Binary) and set it's buffer with SalSetBufferLength(..)
You should be able to pass that one to the PDF-Control.
Regards Thomas
Thomas Uttendorfer
[ frevel & fey ] Software-System GmbH
https://thomasuttendorfer.wordpress.com/

aspurga
Lithuania
Posts: 54
Joined: 06 Mar 2017, 08:54
Location: Lithuania

Re: From C# to SAL. Need a help

Post by aspurga » 08 Mar 2019, 13:16

First parameter Number: pBuffer
I can't to pass string or binary to this parameter

thomas.uttendorfer
Site Admin
Site Admin
Germany
Posts: 167
Joined: 05 Mar 2017, 17:19
Location: Munich Germany

Re: From C# to SAL. Need a help

Post by thomas.uttendorfer » 08 Mar 2019, 14:45

Could you please post your .apl for the PDF-component?
Thomas Uttendorfer
[ frevel & fey ] Software-System GmbH
https://thomasuttendorfer.wordpress.com/

aspurga
Lithuania
Posts: 54
Joined: 06 Mar 2017, 08:54
Location: Lithuania

Re: From C# to SAL. Need a help

Post by aspurga » 11 Mar 2019, 06:53

Hi Thomas,

Please find the attached apl file.

It is an ActiveX pdf control from https://developers.foxitsoftware.com/pdf-sdk/download/
Pros - a control has a lot good features. Cons - price.

Arunas
You do not have the required permissions to view the files attached to this post.

thomas.uttendorfer
Site Admin
Site Admin
Germany
Posts: 167
Joined: 05 Mar 2017, 17:19
Location: Munich Germany

Re: From C# to SAL. Need a help

Post by thomas.uttendorfer » 11 Mar 2019, 11:20

Hi,
I'm not able to open the .apl (I have TD7.0.2)
Could you please save it as text (.apt) and post it again?
Regards Thomas
Thomas Uttendorfer
[ frevel & fey ] Software-System GmbH
https://thomasuttendorfer.wordpress.com/

aspurga
Lithuania
Posts: 54
Joined: 06 Mar 2017, 08:54
Location: Lithuania

Re: From C# to SAL. Need a help

Post by aspurga » 11 Mar 2019, 11:35

Sorry,
Please find zipped apt file
You do not have the required permissions to view the files attached to this post.

thomas.uttendorfer
Site Admin
Site Admin
Germany
Posts: 167
Joined: 05 Mar 2017, 17:19
Location: Munich Germany

Re: From C# to SAL. Need a help

Post by thomas.uttendorfer » 12 Mar 2019, 12:47

Hi Arunas,

if you want to call function OpenMemFile(..)
you have to pass a pointer to allocated memory of some given size.
You can achieve that by including cstructl.apl.

Code: Select all

File Include: cstructl.apl
This .apl is from gupta (you can find it in the program directory of Gupta)
and it includes itself STRCi71.dll (the 71 can differ - it depends on your gupta version).
This one gives you functions with which you can allocate memory and get pointer to it.
Use it like that

Code: Select all

Set size = WhatEverSizeYouNeed
Set pBuffer = CStructAllocFarMem( size )
After you got your data you can transfer the content
of the buffer to a string or binary with

Code: Select all

Set bOk = CStructCopyFromFarMem(pBuffer, sData, size)
If you don't need the memory any more then call

Code: Select all

CStructFreeFarMem(pBuffer)
Hope this helps.

Keep in mind that up to a specific gupta version the size is limited to 64kByte I think.
There is a thread on this forum for details.
viewtopic.php?f=6&t=8&p=10&hilit=cstruct+64k#p10

Regards Thomas
Thomas Uttendorfer
[ frevel & fey ] Software-System GmbH
https://thomasuttendorfer.wordpress.com/

aspurga
Lithuania
Posts: 54
Joined: 06 Mar 2017, 08:54
Location: Lithuania

Re: From C# to SAL. Need a help

Post by aspurga » 13 Mar 2019, 11:05

Hi Thomas,

Thanks a lot for your help. I modified a sample found in forum to open a gif file, save to memory and write from memory to the file.
Something wrong, I can't open a new file.
See please the attached sample.

Regards,

Arunas
You do not have the required permissions to view the files attached to this post.

thomas.uttendorfer
Site Admin
Site Admin
Germany
Posts: 167
Joined: 05 Mar 2017, 17:19
Location: Munich Germany

Re: From C# to SAL. Need a help

Post by thomas.uttendorfer » 14 Mar 2019, 14:26

Hi Arunas,

you have to use CStructCopyToFarMem(..) for copying content from a string to far mem.
If you use CStructCopyFromFarMem(..) you get data from far mem to a gupta string which you don't want here.

Maybe the comments for these two functions in cstruct.apl led you in the wrong direction. I think they are wrong.

Code: Select all

! Call CStructCopyFromFarMem( nPointer1, sBuffer,  nSize)
Call CStructCopyToFarMem( nPointer1, sBuffer,  nSize)
This one works on my site.

Regards Thomas
Thomas Uttendorfer
[ frevel & fey ] Software-System GmbH
https://thomasuttendorfer.wordpress.com/

aspurga
Lithuania
Posts: 54
Joined: 06 Mar 2017, 08:54
Location: Lithuania

Re: From C# to SAL. Need a help

Post by aspurga » 20 Mar 2019, 07:32

Thanks a lot Thomas.

Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 0 guests