Welcome, Guest
Username: Password: Remember me
Visual Objects

Please use this forum to post questions about Visual Objects and Vulcan.NET
  • Page:
  • 1

TOPIC:

Use X# code in VO app 04 Dec 2019 16:21 #12093

  • Juraj
  • Juraj's Avatar
  • Topic Author


  • Posts: 159
  • 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

    Please Log in or Create an account to join the conversation.

    Use X# code in VO app 04 Dec 2019 17:28 #12094

    • wriedmann
    • wriedmann's Avatar


  • Posts: 3366
  • 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:
    docs.xsharp.it/doku.php?id=com_module_sample
    docs.xsharp.it/doku.php?id=com_module_sample_vs
    www.riedmann.it/download/SendMailCOM.zip

    Wolfgang
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    Use X# code in VO app 05 Dec 2019 07:58 #12095

    • Jamal
    • Jamal's Avatar


  • Posts: 309
  • 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:
    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:\Windows\Microsoft.NET\Framework\v4.0.30319\regasm.exe "C:\test\XSharpVOClassLibraryCOM\bin\Release\XSharpVOClassLibraryCOM.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:\test\XSharpVOClassLibraryCOM\bin\Release\XSharpVOClassLibraryCOM.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:\test\XSharpVOClassLibraryCOM\bin\Release\XSharpVOClassLibraryCOM.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:
    METHOD XSharpCOM_Call_Button( ) CLASS MyForm
       local t := _Test{} as _Test
       
       t:SayHello()
       
       t := null_object
    RETURN NIL

    Make sure you copy the BIN\Release\ 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

    Please Log in or Create an account to join the conversation.

    Last edit: by Jamal.

    Use X# code in VO app 24 Sep 2021 12:08 #19699

    • frinchis
    • frinchis's Avatar


  • Posts: 3
  • 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:\Windows\Microsoft.NET\Framework\v4.0.30319\Regasm.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.

    Please Log in or Create an account to join the conversation.

    Use X# code in VO app 24 Sep 2021 13:25 #19700

    • wriedmann
    • wriedmann's Avatar


  • Posts: 3366
  • Hi Carlos,
    maybe you can find some informations here:
    docs.xsharp.it/doku.php?id=com_module_sample_vs
    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
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    Use X# code in VO app 24 Sep 2021 13:42 #19702

    • frinchis
    • frinchis's Avatar


  • Posts: 3
  • 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!

    Please Log in or Create an account to join the conversation.

    • Page:
    • 1