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