xsharp.eu • Use X# code in VO app
Page 1 of 1

Use X# code in VO app

Posted: Wed Dec 04, 2019 3:21 pm
by Juraj
Hi All,

I would need to insert a module written in XSharp core dialect, into an older VO application. Does anyone have experience? Any advice good

Juraj

Use X# code in VO app

Posted: Wed Dec 04, 2019 4:28 pm
by wriedmann
Hi Juraj,

GUI or GUI-less?
If you can make that GUI-less, COM may be the best choice.
Nearly all my VO applications are now using at least one COM module in X#.
You can find details and samples here:
https://docs.xsharp.it/doku.php?id=com_module_sample
https://docs.xsharp.it/doku.php?id=com_module_sample_vs
https://www.riedmann.it/download/SendMailCOM.zip

Wolfgang

Use X# code in VO app

Posted: Thu Dec 05, 2019 6:58 am
by Jamal
Hi Juraj,

This is my approach. Tested and it works. Adjust any file paths accordingly.

Run Visual Studio as an administrator; this is for critical for assembly registration.

In Solution Explorer, click Properties, then double click AssemblyInfo.prg.

Add the following to proper sections in the AssemblyInfo.prg.

using System.Runtime.InteropServices

[assembly: ComVisible(true)]
[assembly: Guid("BAEB8513-5171-4AF7-A963-75085462232")]


Edit: Robert will automate the above in the next build just like in C#. Will update post when I have may hands on it and confirm functionality.

Change the GUID. To obtain a unique GUID, click the Visual Studio Tools menu, choose Create GUID. Keep default in registry format. Then Copy and Paste and replace above and remove the { } from the copied string.

Here is an example of the X# code:

Code: Select all

USING System
USING System.Collections.Generic
USING System.Linq
USING System.Text
using System.Windows.Forms   // just for this sample. Add to project references.
using System.Runtime.InteropServices

BEGIN NAMESPACE XSharpVOClassLibraryCOM
        
    [ClassInterface(ClassInterfaceType.AutoDual)];    
	public CLASS Test
	CONSTRUCTOR() STRICT
		RETURN
        
   public method SayHello() as void 
        MessageBox.Show("Hello")
    return 

	END CLASS
END NAMESPACE
In the Build Event, Post-build Event Command Line:
add .NET regasm.exe to register the assembly. For example: C:WindowsMicrosoft.NETFrameworkv4.0.30319regasm.exe "C:testXSharpVOClassLibraryCOMbinReleaseXSharpVOClassLibraryCOM.dll" /tlb

Build your project in release mode.

Now, VS should display something similar to the following in the build output window:

Build started: Project: XSharpVOClassLibraryCOM, Configuration: Release Any CPU ------
XSharpVOClassLibraryCOM -> C:testXSharpVOClassLibraryCOMbinReleaseXSharpVOClassLibraryCOM.dll
Microsoft .NET Framework Assembly Registration Utility version 4.8.3752.0
for Microsoft .NET Framework version 4.8.3752.0
Copyright (C) Microsoft Corporation. All rights reserved.
Types registered successfully
Assembly exported to 'C:testXSharpVOClassLibraryCOMbinReleaseXSharpVOClassLibraryCOM.tlb', and the type library was registered successfully


In VO, go to Tools menu, select Automation Server and find the XSharpVOClassLibraryCOM class and generate the _Test class.

Test in VO:

Code: Select all

METHOD XSharpCOM_Call_Button( ) CLASS MyForm
   local t := _Test{} as _Test
   
   t:SayHello()
   
   t := null_object
RETURN NIL
Make sure you copy the BINRelease DLLs to your VO app exe folder.

Note: if you distribute your VO app, you must regasm the COM DLL as an admin.

Good luck.

Jamal

Use X# code in VO app

Posted: Fri Sep 24, 2021 10:08 am
by frinchis
Jamal, using VS Community and XSharp Cahors 2.8a I've followed your post (and others) and have successfully get a .dll which I can use from VO by OleAutoObject approach (it works fine).., BUT the library does not appear in the Automation Server window. The output for C:WindowsMicrosoft.NETFrameworkv4.0.30319Regasm.exe $(TargetDir)$(TargetFileName) /tlb is successful, so I have no idea what am I doing wrong.
I would prefer to get a class the same way I do with other COM objects. ¿Any idea?

Windows 10 21H1 here.

Use X# code in VO app

Posted: Fri Sep 24, 2021 11:25 am
by wriedmann
Hi Carlos,
maybe you can find some informations here:
https://docs.xsharp.it/doku.php?id=com_module_sample_vs
https://docs.xsharp.it/doku.php?id=com_module_sample
As far as I have understand, you have created a TLB file, and therefore you should create the VO class using that TLB file.
Personally, I would prefer to work without registration - otherwise you have to register the assemblies on every machine you need to run your software.
Wolfgang

Use X# code in VO app

Posted: Fri Sep 24, 2021 11:42 am
by frinchis
Wolfgang, Thx for answering. I did read your samples too, and have followed your advices.

Yes, VS has created a DLL and a TLB file as well but I wasnt aware that I can create the classes from the TLB file... done it now. Something to learn everyday :)

Thx again!