Implement .NET Library

Discussion forum about all things Gupta, OpenText and the community.
EwaldP
Austria
Posts: 339
Joined: 07 Mar 2017, 08:00
Location: Austria

Implement .NET Library

Post by EwaldP » 24 Nov 2021, 14:48

Hi,

is there any other way to integrate .NET libraries (C#) than with the .NET Explorer?

Regards
Ewald
Ewald P. Palmetshofer
EDV-Hausleitner GmbH
4020 Linz
www.edv-hausleitner.at

Dave Rabelink
Founder/Site Admin
Founder/Site Admin
Netherlands
Posts: 3145
Joined: 24 Feb 2017, 09:12
Location: Gouda, The Netherlands

Re: Implement .NET Library

Post by Dave Rabelink » 24 Nov 2021, 15:25

Yes.

If the C# .NET library has an exposed COM interface, you can use it as ActiveX/COM from TD.
You use in that case the ActiveX Explorer in TD to generate the TD library to use it.

As an example

Code: Select all

[ComVisible(true), Guid("43c9ad6b-5027-4626-afbb-264922bde0ad")]
    public interface ZipWrapperInterface
    {
        String ZipFiles(String zipFileName, String directory, String[] filesToInclude);
    }
Specifying that the interface and the methods are COM exposed by adding it just in front of the definition.
The method ZipFiles can then be called from TD using COM and also from native .NET.

To enable exposing COM in .NET project (Visual Studio) you check the option in the assembly properties

COM_Visible.png

For 3rd party assemblies it depends if the product has enabled this. I know some components (like GdPicture) can be used both in native .NET and as COM.

Other ways I do not know of.

But to be honest, I would use GAILWrapper when possible over the COM option.
You have to register COM which makes deployment more difficult.
And GAILWrapper in current state (TD 7.4) is stable and supports most of the interface features.

The advantage of COM is that you can expose events and more complex class/parameter types.
You do not have the required permissions to view the files attached to this post.
Regards,
Dave Rabelink

Image
Articles and information on Team Developer Tips & Tricks Wiki
Download samples, documents and resources from TD Sample Vault
Videos on TDWiki YouTube Channel

Michael Ehehalt
Germany
Posts: 65
Joined: 13 Mar 2017, 09:17
Location: Frankfurt, Germany

Re: Implement .NET Library

Post by Michael Ehehalt » 24 Nov 2021, 16:24

Only for the sake of completeness:

There is another way to use .NET assemblies. The static functions in .NET assemblies could be used like normal Win32 DLL functions as external functions in Team Developer. But there is no automatic way with Visual Studio to generate them.

The advantage here is that this have worked long before Team Developer could use .NET assemblies directly. We use this a lot and it works very stable.

The disadvantage is that the interface only knows normal data types (it is not object oriented). The functions to be exported must be static and the effort of converting the assembly is quite high, because you have to do the following steps:

1. Create .NET assembly normally with static functions as interface (e.g. with Visual Studio).
2. disassemble .NET assembly with ildasm.exe to generate MSIL code
3. modify the MSIL code to create the interface for the external functions
4. recompile the .NET assembly with ilasm.exe.

If the .NET Explorer had been around when we wanted to use the .NET assemblies in Team Developer, we certainly wouldn't have gone this way :-)

If you are interested I can describe the way how to change the MSIL code in more detail, but I don't think this is the solution you are looking for ;-)

PS: Here is the underlying article about which we realized our solution of disassemble/modify/assemble:

http://www.blong.com/Articles/DotNetInt ... nterop.htm

PPS: Attached is a sample that use a .NET Assembly with the following .NET code as Win32 DLL in Team Developer:

Code: Select all

namespace MathLibrary
{
    public static class Sum
    {
        public static int AddInt(int a, int b)
        {
            return a + b;
        }

        public static string AddString(string a, string b)
        {
            return a + b;
        }

        public static int AddStringEx(string a, string b, [MarshalAs(UnmanagedType.LPStr)] string c)
        {
            c = a + b;
            return c.Length;
        }

        public static int GetDate(ref int year, ref int month, ref int day)
        {
            year = 2021;
            month = 3;
            day = 24;
            return 0;
        }
    }
}
You do not have the required permissions to view the files attached to this post.
Best regards,
Michael Ehehalt

Dave Rabelink
Founder/Site Admin
Founder/Site Admin
Netherlands
Posts: 3145
Joined: 24 Feb 2017, 09:12
Location: Gouda, The Netherlands

Re: Implement .NET Library

Post by Dave Rabelink » 24 Nov 2021, 22:16

Michael Ehehalt wrote:
24 Nov 2021, 16:24
Only for the sake of completeness:

There is another way to use .NET assemblies. The static functions in .NET assemblies could be used like normal Win32 DLL functions as external functions in Team Developer.
Nice. I haven't seen this before. So thanks for this info !
Regards,
Dave Rabelink

Image
Articles and information on Team Developer Tips & Tricks Wiki
Download samples, documents and resources from TD Sample Vault
Videos on TDWiki YouTube Channel

EwaldP
Austria
Posts: 339
Joined: 07 Mar 2017, 08:00
Location: Austria

Re: Implement .NET Library

Post by EwaldP » 26 Nov 2021, 07:06

Many thanks to Dave and Michael. I will try different the different approaches.
Ewald P. Palmetshofer
EDV-Hausleitner GmbH
4020 Linz
www.edv-hausleitner.at

Return to “General Discussion”

Who is online

Users browsing this forum: [Ccbot] and 0 guests