Files
2025-11-11 17:25:35 +01:00

232 lines
11 KiB
VB.net

Imports System.Runtime.InteropServices
Imports System.Security
Public Module EgtInterface
#If DEBUG Then
Const EgtIntDll32 As String = "EgtBasisD32.dll"
Const EgtIntDll64 As String = "EgtBasisD64.dll"
#Else
Const EgtIntDll32 As String = "EgtBasisR32.dll"
Const EgtIntDll64 As String = "EgtBasisR64.dll"
#End If
<DllImport(EgtIntDll32, CharSet:=CharSet.Unicode, EntryPoint:="EgtSetKey"), SuppressUnmanagedCodeSecurity()>
Private Function EgtSetKey_32(sKey As String) As Boolean
End Function
<DllImport(EgtIntDll64, CharSet:=CharSet.Unicode, EntryPoint:="EgtSetKey"), SuppressUnmanagedCodeSecurity()>
Private Function EgtSetKey_64(sKey As String) As Boolean
End Function
Public Function EgtSetKey(sKey As String) As Boolean
If IntPtr.Size = 4 Then
Return EgtSetKey_32(sKey)
Else
Return EgtSetKey_64(sKey)
End If
End Function
<DllImport(EgtIntDll32, CharSet:=CharSet.Unicode, EntryPoint:="EgtGetKeyLevel"), SuppressUnmanagedCodeSecurity()>
Private Function EgtGetKeyLevel_32(nProd As Integer, nVer As Integer, nLev As Integer,
ByRef nKLev As Integer) As Boolean
End Function
<DllImport(EgtIntDll64, CharSet:=CharSet.Unicode, EntryPoint:="EgtGetKeyLevel"), SuppressUnmanagedCodeSecurity()>
Private Function EgtGetKeyLevel_64(nProd As Integer, nVer As Integer, nLev As Integer,
ByRef nKLev As Integer) As Boolean
End Function
Public Function EgtGetKeyLevel(nProd As Integer, nVer As Integer, nLev As Integer,
ByRef nKLev As Integer) As Boolean
If IntPtr.Size = 4 Then
Return EgtGetKeyLevel_32(nProd, nVer, nLev, nKLev)
Else
Return EgtGetKeyLevel_64(nProd, nVer, nLev, nKLev)
End If
End Function
<DllImport(EgtIntDll32, CharSet:=CharSet.Unicode, EntryPoint:="EgtGetKeyOptions"), SuppressUnmanagedCodeSecurity()>
Private Function EgtGetKeyOptions_32(nProd As Integer, nVer As Integer, nLev As Integer,
ByRef nOpt1 As UInteger, ByRef nOpt2 As UInteger) As Boolean
End Function
<DllImport(EgtIntDll64, CharSet:=CharSet.Unicode, EntryPoint:="EgtGetKeyOptions"), SuppressUnmanagedCodeSecurity()>
Private Function EgtGetKeyOptions_64(nProd As Integer, nVer As Integer, nLev As Integer,
ByRef nOpt1 As UInteger, ByRef nOpt2 As UInteger) As Boolean
End Function
Public Function EgtGetKeyOptions(nProd As Integer, nVer As Integer, nLev As Integer,
ByRef nOpt1 As UInteger, ByRef nOpt2 As UInteger) As Boolean
If IntPtr.Size = 4 Then
Return EgtGetKeyOptions_32(nProd, nVer, nLev, nOpt1, nOpt2)
Else
Return EgtGetKeyOptions_64(nProd, nVer, nLev, nOpt1, nOpt2)
End If
End Function
Public Function EgtGetKeyOptions(nProd As Integer, nVer As Integer, nLev As Integer,
ByRef nOpt2 As UInteger) As Boolean
Return EgtGetKeyOptions(nProd, nVer, nLev, nOpt2)
End Function
<DllImport(EgtIntDll32, CharSet:=CharSet.Unicode, EntryPoint:="EgtGetKeyLeftDays"), SuppressUnmanagedCodeSecurity()>
Private Function EgtGetKeyLeftDays_32(ByRef nLeftDays As Integer) As Boolean
End Function
<DllImport(EgtIntDll64, CharSet:=CharSet.Unicode, EntryPoint:="EgtGetKeyLeftDays"), SuppressUnmanagedCodeSecurity()>
Private Function EgtGetKeyLeftDays_64(ByRef nLeftDays As Integer) As Boolean
End Function
Public Function EgtGetKeyLeftDays(ByRef nLeftDays As Integer) As Boolean
If IntPtr.Size = 4 Then
Return EgtGetKeyLeftDays_32(nLeftDays)
Else
Return EgtGetKeyLeftDays_64(nLeftDays)
End If
End Function
<DllImport(EgtIntDll32, CharSet:=CharSet.Unicode, EntryPoint:="EgtGetKeyAssLeftDays"), SuppressUnmanagedCodeSecurity()>
Private Function EgtGetKeyAssLeftDays_32(ByRef nAssLeftDays As Integer) As Boolean
End Function
<DllImport(EgtIntDll64, CharSet:=CharSet.Unicode, EntryPoint:="EgtGetKeyAssLeftDays"), SuppressUnmanagedCodeSecurity()>
Private Function EgtGetKeyAssLeftDays_64(ByRef nAssLeftDays As Integer) As Boolean
End Function
Public Function EgtGetKeyAssLeftDays(ByRef nAssLeftDays As Integer) As Boolean
If IntPtr.Size = 4 Then
Return EgtGetKeyAssLeftDays_32(nAssLeftDays)
Else
Return EgtGetKeyAssLeftDays_64(nAssLeftDays)
End If
End Function
<DllImport(EgtIntDll32, CharSet:=CharSet.Unicode, EntryPoint:="EgtGetKeyOptLeftDays"), SuppressUnmanagedCodeSecurity()>
Private Function EgtGetKeyOptLeftDays_32(ByRef nOptLeftDays As Integer) As Boolean
End Function
<DllImport(EgtIntDll64, CharSet:=CharSet.Unicode, EntryPoint:="EgtGetKeyOptLeftDays"), SuppressUnmanagedCodeSecurity()>
Private Function EgtGetKeyOptLeftDays_64(ByRef nOptLeftDays As Integer) As Boolean
End Function
Public Function EgtGetKeyOptLeftDays(ByRef nOptLeftDays As Integer) As Boolean
If IntPtr.Size = 4 Then
Return EgtGetKeyOptLeftDays_32(nOptLeftDays)
Else
Return EgtGetKeyOptLeftDays_64(nOptLeftDays)
End If
End Function
<DllImport(EgtIntDll32, CharSet:=CharSet.Unicode, EntryPoint:="EgtFreeMemory"), SuppressUnmanagedCodeSecurity()>
Private Function EgtFreeMemory_32(sB As IntPtr) As Boolean
End Function
<DllImport(EgtIntDll64, CharSet:=CharSet.Unicode, EntryPoint:="EgtFreeMemory"), SuppressUnmanagedCodeSecurity()>
Private Function EgtFreeMemory_64(sB As IntPtr) As Boolean
End Function
Public Function EgtFreeMemory(sB As IntPtr) As Boolean
If IntPtr.Size = 4 Then
Return EgtFreeMemory_32(sB)
Else
Return EgtFreeMemory_64(sB)
End If
End Function
<DllImport(EgtIntDll32, CharSet:=CharSet.Unicode, EntryPoint:="EgtLoadMessages"), SuppressUnmanagedCodeSecurity()>
Private Function EgtLoadMessages_32(sMsgFilePath As String) As Boolean
End Function
<DllImport(EgtIntDll64, CharSet:=CharSet.Unicode, EntryPoint:="EgtLoadMessages"), SuppressUnmanagedCodeSecurity()>
Private Function EgtLoadMessages_64(sMsgFilePath As String) As Boolean
End Function
Public Function EgtLoadMessages(sMsgFilePath As String) As Boolean
If IntPtr.Size = 4 Then
Return EgtLoadMessages_32(sMsgFilePath)
Else
Return EgtLoadMessages_64(sMsgFilePath)
End If
End Function
<DllImport(EgtIntDll32, CharSet:=CharSet.Unicode, EntryPoint:="EgtGetMsg"), SuppressUnmanagedCodeSecurity()>
Private Function EgtGetMsg_32(nId As Integer) As IntPtr
End Function
<DllImport(EgtIntDll64, CharSet:=CharSet.Unicode, EntryPoint:="EgtGetMsg"), SuppressUnmanagedCodeSecurity()>
Private Function EgtGetMsg_64(nId As Integer) As IntPtr
End Function
Public Function EgtMsg(nId As Integer) As String
If IntPtr.Size = 4 Then
Return Marshal.PtrToStringUni(EgtGetMsg_32(nId))
Else
Return Marshal.PtrToStringUni(EgtGetMsg_64(nId))
End If
' Non è necessario liberare la memoria nativa perchè usa un buffer statico
End Function
<DllImport(EgtIntDll32, CharSet:=CharSet.Unicode, EntryPoint:="EgtInitLogger"), SuppressUnmanagedCodeSecurity()>
Private Function EgtInitLogger_32(nDebug As Integer, sLogFilePath As String) As Boolean
End Function
<DllImport(EgtIntDll64, CharSet:=CharSet.Unicode, EntryPoint:="EgtInitLogger"), SuppressUnmanagedCodeSecurity()>
Private Function EgtInitLogger_64(nDebug As Integer, sLogFilePath As String) As Boolean
End Function
Public Function EgtInitLogger(nDebug As Integer, sLogFilePath As String) As Boolean
If IntPtr.Size = 4 Then
Return EgtInitLogger_32(nDebug, sLogFilePath)
Else
Return EgtInitLogger_64(nDebug, sLogFilePath)
End If
End Function
<DllImport(EgtIntDll32, CharSet:=CharSet.Unicode, EntryPoint:="EgtOutLog"), SuppressUnmanagedCodeSecurity()>
Private Function EgtOutLog_32(sMsg As String, nDebugLevel As Integer) As Boolean
End Function
<DllImport(EgtIntDll64, CharSet:=CharSet.Unicode, EntryPoint:="EgtOutLog"), SuppressUnmanagedCodeSecurity()>
Private Function EgtOutLog_64(sMsg As String, nDebugLevel As Integer) As Boolean
End Function
Public Function EgtOutLog(sMsg As String, nDebugLevel As Integer) As Boolean
If IntPtr.Size = 4 Then
Return EgtOutLog_32(sMsg, nDebugLevel)
Else
Return EgtOutLog_64(sMsg, nDebugLevel)
End If
End Function
Public Function EgtOutLog(sMsg As String) As Boolean
Return EgtOutLog(sMsg, 0)
End Function
<DllImport(EgtIntDll32, CharSet:=CharSet.Unicode, EntryPoint:="EgtGetStringUtf8FromIni"), SuppressUnmanagedCodeSecurity()>
Private Function EgtGetStringUtf8FromIni_32(sSec As String, sKey As String, sDef As String, ByRef sVal As IntPtr, sIniFile As String) As Boolean
End Function
<DllImport(EgtIntDll64, CharSet:=CharSet.Unicode, EntryPoint:="EgtGetStringUtf8FromIni"), SuppressUnmanagedCodeSecurity()>
Private Function EgtGetStringUtf8FromIni_64(sSec As String, sKey As String, sDef As String, ByRef sVal As IntPtr, sIniFile As String) As Boolean
End Function
Public Function EgtGetStringUtf8FromIni(sSec As String, sKey As String, sDef As String, ByRef sVal As String, sIniFile As String) As Boolean
Dim psVal As IntPtr
Dim bOk As Boolean = False
If IntPtr.Size = 4 Then
bOk = EgtGetStringUtf8FromIni_32(sSec, sKey, sDef, psVal, sIniFile)
Else
bOk = EgtGetStringUtf8FromIni_64(sSec, sKey, sDef, psVal, sIniFile)
End If
If bOk Then
sVal = Marshal.PtrToStringUni(psVal)
EgtFreeMemory(psVal)
Else
sVal = String.Empty
End If
Return bOk
End Function
<DllImport(EgtIntDll32, CharSet:=CharSet.Unicode, EntryPoint:="EgtWriteStringUtf8ToIni"), SuppressUnmanagedCodeSecurity()>
Public Function EgtWriteStringUtf8toIni_32(sSec As String, sKey As String, sVal As String, sIniFile As String) As Boolean
End Function
<DllImport(EgtIntDll64, CharSet:=CharSet.Unicode, EntryPoint:="EgtWriteStringUtf8ToIni"), SuppressUnmanagedCodeSecurity()>
Public Function EgtWriteStringUtf8toIni_64(sSec As String, sKey As String, sVal As String, sIniFile As String) As Boolean
End Function
Public Function EgtWriteStringUtf8toIni(sSec As String, sKey As String, sVal As String, sIniFile As String) As Boolean
If IntPtr.Size = 4 Then
Return EgtWriteStringUtf8toIni_32(sSec, sKey, sVal, sIniFile)
Else
Return EgtWriteStringUtf8toIni_64(sSec, sKey, sVal, sIniFile)
End If
End Function
Public Function EgtInit(nDebug As Integer, sLogFile As String, Optional sLogMsg As String = "") As Boolean
Dim MyDll As System.Reflection.AssemblyName = System.Reflection.Assembly.GetExecutingAssembly().GetName()
sLogMsg &= vbLf & "EgtUILib.dll ver. " &
MyDll.Version.Major.ToString() & "." &
MyDll.Version.Minor.ToString() &
(ChrW(97 - 1 + MyDll.Version.Build)).ToString() &
MyDll.Version.Revision.ToString()
Dim bOk As Boolean = EgtInitLogger(nDebug, sLogFile)
If bOk Then EgtOutLog(sLogMsg)
Return bOk
End Function
End Module