Skip to content

Commit

Permalink
New
Browse files Browse the repository at this point in the history
  • Loading branch information
Serialcomms committed Aug 1, 2023
1 parent d26d1a8 commit f8af6e7
Show file tree
Hide file tree
Showing 11 changed files with 637 additions and 64 deletions.
52 changes: 50 additions & 2 deletions AUTO_FUNCTIONS/AUTO_FUNCTIONS.vbproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{6257C360-7481-43AF-9752-31F873D2A904}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>AUTO_FUNCTIONS</RootNamespace>
<RootNamespace>Automation</RootNamespace>
<AssemblyName>AUTO_FUNCTIONS</AssemblyName>
<FileAlignment>512</FileAlignment>
<MyType>Windows</MyType>
Expand All @@ -21,6 +21,7 @@
<OutputPath>bin\Debug\</OutputPath>
<DocumentationFile>AUTO_FUNCTIONS.xml</DocumentationFile>
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
<RegisterForComInterop>false</RegisterForComInterop>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand All @@ -30,6 +31,7 @@
<OutputPath>bin\Release\</OutputPath>
<DocumentationFile>AUTO_FUNCTIONS.xml</DocumentationFile>
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
<RegisterForComInterop>false</RegisterForComInterop>
</PropertyGroup>
<PropertyGroup>
<OptionExplicit>On</OptionExplicit>
Expand All @@ -43,8 +45,35 @@
<PropertyGroup>
<OptionInfer>On</OptionInfer>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<DefineDebug>true</DefineDebug>
<DefineTrace>true</DefineTrace>
<OutputPath>bin\x64\Debug\</OutputPath>
<DocumentationFile>AUTO_FUNCTIONS.xml</DocumentationFile>
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<DefineTrace>true</DefineTrace>
<OutputPath>bin\x64\Release\</OutputPath>
<DocumentationFile>AUTO_FUNCTIONS.xml</DocumentationFile>
<Optimize>true</Optimize>
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<Reference Include="extensibility, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="Microsoft.VisualStudio.Tools.Applications.Runtime, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="Office, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL">
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration.Install" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="System.Core" />
Expand All @@ -64,11 +93,19 @@
<Import Include="System.Threading.Tasks" />
</ItemGroup>
<ItemGroup>
<Compile Include="Class1.vb" />
<Compile Include="Functions.vb" />
<Compile Include="Installer.Designer.vb">
<DependentUpon>Installer.vb</DependentUpon>
</Compile>
<Compile Include="Installer.vb">
<SubType>Component</SubType>
</Compile>
<Compile Include="Interop.vb" />
<Compile Include="My Project\AssemblyInfo.vb" />
<Compile Include="My Project\Application.Designer.vb">
<AutoGen>True</AutoGen>
<DependentUpon>Application.myapp</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<Compile Include="My Project\Resources.Designer.vb">
<AutoGen>True</AutoGen>
Expand Down Expand Up @@ -100,5 +137,16 @@
<LastGenOutput>Settings.Designer.vb</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup>
<COMReference Include="Microsoft.Office.Interop.Excel">
<Guid>{00020813-0000-0000-C000-000000000046}</Guid>
<VersionMajor>1</VersionMajor>
<VersionMinor>9</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>primary</WrapperTool>
<Isolated>False</Isolated>
<EmbedInteropTypes>True</EmbedInteropTypes>
</COMReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
</Project>
3 changes: 0 additions & 3 deletions AUTO_FUNCTIONS/Class1.vb

This file was deleted.

62 changes: 62 additions & 0 deletions AUTO_FUNCTIONS/Functions.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
Option Strict On
Option Explicit On
Option Compare Text
Imports System.Runtime.InteropServices

<ComVisible(True)>
<Guid(Functions.InterfaceId)>
Public Interface ICLASS_FUNCTIONS
Function IFX() As String

Function TIMENOW() As String

End Interface
<ComVisible(True)>
<Guid(Functions.ClassId)>
<ProgId("AUTOMATION.Formulas")>
<ClassInterface(ClassInterfaceType.None)>
<ComDefaultInterface(GetType(ICLASS_FUNCTIONS))>
Public Class Functions
Implements ICLASS_FUNCTIONS

#Region "COM GUIDs"
' These GUIDs provide the COM identity for this class and its COM interfaces.
' If you change them, existing clients will no longer be able to access the class.

Public Const ClassId As String = "df32904d-DEAD-BEEF-9352-5dc0ceafa03e"
Public Const EventsId As String = "ca59b115-DEAD-BEEF-8375-a8f652d3258f"
Public Const InterfaceId As String = "6c409593-DEAD-BEEF-8c16-f3804714e174"
#End Region

' A creatable COM class must have a Public Sub New() with no parameters, otherwise, the
' class will not be registered in the COM registry and cannot be created via CreateObject.
Public Sub New()

MyBase.New()

End Sub

Private Function IFX() As String Implements ICLASS_FUNCTIONS.IFX

Return "AUTO FX OK"

End Function
Private Function TIMENOW() As String Implements ICLASS_FUNCTIONS.TIMENOW

EXCEL.Volatile()

Dim DT As Date

Dim TimeString As String

DT = Now

TimeString = DT.ToLongTimeString.ToString() & "." & DT.Millisecond.ToString("D3")

Return TimeString

End Function

End Class


27 changes: 27 additions & 0 deletions AUTO_FUNCTIONS/Installer.Designer.vb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

157 changes: 157 additions & 0 deletions AUTO_FUNCTIONS/Installer.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
Imports Microsoft.Win32
Imports System.Reflection
Imports System.Runtime.InteropServices
Imports System.Runtime.Remoting.Contexts

<ComVisible(False)>
<ClassInterface(ClassInterfaceType.None)>
Public Class Installer

Public ASSEMBLY_TYPE As Type
Public ASSEMBLY_GUID As String
Public ASSEMBLY_NAME As Assembly
Public ASSEMBLY_KEYNAME As String
Public ASSEMBLY_DISPLAY_NAME As String
Public REGISTRATION_SERVICES As RegistrationServices

Public Sub New()

MyBase.New()

InitializeComponent() 'This call is required by the Component Designer.

'Add initialization code after the call to InitializeComponent

ASSEMBLY_TYPE = GetType(Functions)
ASSEMBLY_GUID = Functions.ClassId.ToUpper
ASSEMBLY_NAME = GetType(Functions).Assembly
ASSEMBLY_KEYNAME = "CLSID\{" & ASSEMBLY_GUID & "}\"
ASSEMBLY_DISPLAY_NAME = ASSEMBLY_NAME.FullName
REGISTRATION_SERVICES = New RegistrationServices

End Sub

Public Overrides Sub Install(stateSaver As IDictionary)

MyBase.Install(stateSaver)

REGISTER_ASSEMBLY()

UPDATE_REGISTRY_KEYS()

End Sub

Public Overrides Sub Commit(savedState As IDictionary)

MyBase.Commit(savedState)

End Sub

Public Overrides Sub Rollback(savedState As IDictionary)

MyBase.Rollback(savedState)

End Sub

Public Overrides Sub Uninstall(savedState As IDictionary)

MyBase.Uninstall(savedState)

REMOVE_REGISTRY_KEY()

UNREGISTER_ASSEMBLY()

End Sub

Public Sub REGISTER_ASSEMBLY()

Try

REGISTRATION_SERVICES.RegisterAssembly(ASSEMBLY_NAME, AssemblyRegistrationFlags.SetCodeBase)

Catch ex As Exception

Dim BOXTEXT As String = Nothing
BOXTEXT &= "Assembly Name = " & ASSEMBLY_DISPLAY_NAME & vbCrLf
BOXTEXT &= "Assembly GUID = " & ASSEMBLY_GUID & vbCrLf
BOXTEXT &= "Message = " & ex.Message

MsgBox(BOXTEXT, vbCritical + vbOKOnly, " Error Registering Assembly")

End Try

End Sub

Public Sub UPDATE_REGISTRY_KEYS()

Dim SetKey As RegistryKey = Nothing

Try

Registry.ClassesRoot.CreateSubKey(ASSEMBLY_KEYNAME & "Programmable")

SetKey = Registry.ClassesRoot.OpenSubKey(ASSEMBLY_KEYNAME & "InprocServer32", True)

SetKey.SetValue("", Environment.SystemDirectory & "\mscoree.dll", RegistryValueKind.String)

' Environment.SystemDirectory = auto 32/64 bit

Registry.ClassesRoot.Close()

Catch ex As Exception

Dim BOXTEXT As String = Nothing
BOXTEXT &= "Assembly Name = " & ASSEMBLY_DISPLAY_NAME & vbCrLf
BOXTEXT &= "Assembly GUID = " & ASSEMBLY_GUID & vbCrLf
BOXTEXT &= "Registry Key = " & SetKey.ToString & vbCrLf
BOXTEXT &= "Message = " & ex.Message

MsgBox(BOXTEXT, vbCritical + vbOKOnly, " Error updating registry")

End Try


End Sub

Public Sub REMOVE_REGISTRY_KEY()

Try

Registry.ClassesRoot.DeleteSubKey(ASSEMBLY_KEYNAME & "Programmable")

Registry.ClassesRoot.Flush()

Catch ex As Exception

Dim BOXTEXT As String = Nothing
BOXTEXT &= "Assembly Name = " & ASSEMBLY_DISPLAY_NAME & vbCrLf
BOXTEXT &= "Assembly GUID = " & ASSEMBLY_GUID & vbCrLf
BOXTEXT &= "Registry SubKey = " & ASSEMBLY_KEYNAME & "Programmable"
BOXTEXT &= "Message = " & ex.Message

MsgBox(BOXTEXT, vbCritical + vbOKOnly, " Error deleting subkey")

End Try

End Sub

Public Sub UNREGISTER_ASSEMBLY()

Try

REGISTRATION_SERVICES.UnregisterAssembly(ASSEMBLY_NAME)

Catch ex As Exception

Dim BOXTEXT As String = Nothing
BOXTEXT &= "Assembly Name = " & ASSEMBLY_DISPLAY_NAME & vbCrLf
BOXTEXT &= "Assembly GUID = " & ASSEMBLY_GUID & vbCrLf
BOXTEXT &= "Message = " & ex.Message

MsgBox(BOXTEXT, vbCritical + vbOKOnly, " Error UnRegistering Assembly")

End Try

End Sub

End Class
Loading

0 comments on commit f8af6e7

Please sign in to comment.