fbpx
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

  • hsc's Avatar

  • hsc

  • Topic Author


  • Posts: 126
  • 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's Avatar

  • wriedmann


  • Posts: 2300
  • 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's Avatar

  • Jamal


  • Posts: 203
  • 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.
    • Page:
    • 1