base implementation
This commit is contained in:
62
QuickPrintBridge/QuickPrintBridge.cs
Normal file
62
QuickPrintBridge/QuickPrintBridge.cs
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using Kompas6API5;
|
||||||
|
using Microsoft.Win32;
|
||||||
|
|
||||||
|
namespace QuickPrintBridge;
|
||||||
|
|
||||||
|
[ClassInterface(ClassInterfaceType.AutoDual)]
|
||||||
|
public sealed class QuickPrintBridge
|
||||||
|
{
|
||||||
|
[return: MarshalAs(UnmanagedType.BStr)]
|
||||||
|
public string GetLibraryName() => nameof(QuickPrintBridge);
|
||||||
|
|
||||||
|
// Головная функция библиотеки
|
||||||
|
public void ExternalRunCommand([In] short command, [In] short mode,
|
||||||
|
[In, MarshalAs(UnmanagedType.IDispatch)]
|
||||||
|
object kompas_)
|
||||||
|
{
|
||||||
|
KompasObject kompas = (KompasObject)kompas_;
|
||||||
|
kompas.ksMessage("Привет!");
|
||||||
|
}
|
||||||
|
|
||||||
|
public short GetProtectNumber()
|
||||||
|
{
|
||||||
|
return 111;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Эта функция выполняется при регистрации класса для COM
|
||||||
|
// Она добавляет в ветку реестра компонента раздел Kompas_Library,
|
||||||
|
// который сигнализирует о том, что класс является приложением Компас,
|
||||||
|
// а также заменяет имя InprocServer32 на полное, с указанием пути.
|
||||||
|
// Все это делается для того, чтобы иметь возможность подключить
|
||||||
|
// библиотеку на вкладке ActiveX.
|
||||||
|
[ComRegisterFunction]
|
||||||
|
public static void RegisterKompasLib(Type t)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
RegistryKey? regKey = Registry.LocalMachine;
|
||||||
|
string keyName = @"SOFTWARE\Classes\CLSID\{" + t.GUID.ToString() + "}";
|
||||||
|
regKey = regKey.OpenSubKey(keyName, true);
|
||||||
|
regKey.CreateSubKey("Kompas_Library");
|
||||||
|
regKey = regKey.OpenSubKey("InprocServer32", true);
|
||||||
|
regKey.SetValue(null, System.Environment.GetFolderPath(Environment.SpecialFolder.System) + @"\mscoree.dll");
|
||||||
|
regKey.Close();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
//MessageBox.Show(string.Format("При регистрации класса для COM-Interop произошла ошибка:\n{0}", ex));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Эта функция удаляет раздел Kompas_Library из реестра
|
||||||
|
[ComUnregisterFunction]
|
||||||
|
public static void UnregisterKompasLib(Type t)
|
||||||
|
{
|
||||||
|
RegistryKey regKey = Registry.LocalMachine;
|
||||||
|
string keyName = @"SOFTWARE\Classes\CLSID\{" + t.GUID.ToString() + "}";
|
||||||
|
RegistryKey subKey = regKey.OpenSubKey(keyName, true);
|
||||||
|
subKey.DeleteSubKey("Kompas_Library");
|
||||||
|
subKey.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net8.0</TargetFramework>
|
<TargetFramework>net8.0-windows</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<EnableDynamicLoading>true</EnableDynamicLoading>
|
<EnableDynamicLoading>true</EnableDynamicLoading>
|
||||||
|
|||||||
Reference in New Issue
Block a user