Read/Write Global Variables from C#/VB
Posted: Aug 18 2013
I need to read/write PowerLanguage global variables from C#/VB. I've tried the examples at:
viewtopic.php?f=19&t=11315 (see below) Neither of these forms work:
I get "Unable to find an entry point named..." or the functions return an error condition. Is there a complete C#/VB example of how do this?
viewtopic.php?f=19&t=11315 (see below) Neither of these forms work:
Code: Select all
PowerLanguage.Function._GVLibWrap_.InitializeGV()
LegacyGlobalVariables.GV_SetNamedString("A", "123")
Code: Select all
Public NotInheritable Class LegacyGlobalVariables
Const WildGvDllFilePath As String = "C:\C:\Program Files\TS Support\MultiCharts64\GlobalVariable.dll"
' your global variable path
<System.Runtime.InteropServices.DllImport(WildGvDllFilePath, SetLastError:=False)> _
Public Shared Function GV_SetInteger(ByVal iLocation As Integer, ByVal iVal As Integer) As Integer
End Function
<System.Runtime.InteropServices.DllImport(WildGvDllFilePath, SetLastError:=False)> _
Public Shared Function GV_GetInteger(ByVal iLocation As Integer) As Integer
End Function
<System.Runtime.InteropServices.DllImport(WildGvDllFilePath, SetLastError:=False)> _
Public Shared Function GV_SetNamedInt(ByVal sIntVarName As String, ByVal iVal As Integer) As Integer
End Function
<System.Runtime.InteropServices.DllImport(WildGvDllFilePath, SetLastError:=False)> _
Public Shared Function GV_GetNamedInt(ByVal sIntVarName As String, ByVal iErrorCode As Integer) As Integer
End Function
<System.Runtime.InteropServices.DllImport(WildGvDllFilePath, SetLastError:=False)> _
Public Shared Function GV_SetFloat(ByVal iLocation As Integer, ByVal fVal As Single) As Integer
End Function
<System.Runtime.InteropServices.DllImport(WildGvDllFilePath, SetLastError:=False)> _
Public Shared Function GV_GetFloat(ByVal iLocation As Integer) As Single
End Function
<System.Runtime.InteropServices.DllImport(WildGvDllFilePath, SetLastError:=False)> _
Public Shared Function GV_SetNamedFloat(ByVal sFloatVarName As String, ByVal fVal As Single) As Integer
End Function
<System.Runtime.InteropServices.DllImport(WildGvDllFilePath, SetLastError:=False)> _
Public Shared Function GV_GetNamedFloat(ByVal sFloatVarName As String, ByVal fErrorCode As Single) As Single
End Function
<System.Runtime.InteropServices.DllImport(WildGvDllFilePath, SetLastError:=False)> _
Public Shared Function GV_SetDouble(ByVal iLocation As Integer, ByVal dVal As Double) As Integer
End Function
<System.Runtime.InteropServices.DllImport(WildGvDllFilePath, SetLastError:=False)> _
Public Shared Function GV_GetDouble(ByVal iLocation As Integer) As Double
End Function
<System.Runtime.InteropServices.DllImport(WildGvDllFilePath, SetLastError:=False)> _
Public Shared Function GV_SetSecsBack(ByVal iArrayId As Integer, ByVal iLocation As Integer, ByVal dVal As Double) As Integer
End Function
<System.Runtime.InteropServices.DllImport(WildGvDllFilePath, SetLastError:=False)> _
Public Shared Function GV_GetSecsBack(ByVal iArrayId As Integer, ByVal iLocation As Integer) As Double
End Function
<System.Runtime.InteropServices.DllImport(WildGvDllFilePath, SetLastError:=False)> _
Public Shared Function GV_SetMinsBack(ByVal iArrayId As Integer, ByVal iLocation As Integer, ByVal dVal As Double) As Integer
End Function
<System.Runtime.InteropServices.DllImport(WildGvDllFilePath, SetLastError:=False)> _
Public Shared Function GV_GetMinsBack(ByVal iArrayId As Integer, ByVal iLocation As Integer) As Double
End Function
<System.Runtime.InteropServices.DllImport(WildGvDllFilePath, SetLastError:=False)> _
Public Shared Function GV_SetNamedDouble(ByVal sDoubleVarName As String, ByVal dVal As Double) As Integer
End Function
<System.Runtime.InteropServices.DllImport(WildGvDllFilePath, SetLastError:=False)> _
Public Shared Function GV_GetNamedDouble(ByVal sDoubleVarName As String, ByVal dErrorCode As Double) As Double
End Function
<System.Runtime.InteropServices.DllImport(WildGvDllFilePath, SetLastError:=False)> _
Public Shared Function GV_SetString(ByVal iLocation As Integer, ByVal sVal As String) As Integer
End Function
<System.Runtime.InteropServices.DllImport(WildGvDllFilePath, SetLastError:=False)> _
Public Shared Function GV_SetNamedString(ByVal sStringVarName As String, ByVal sVal As String) As Integer
End Function
<System.Runtime.InteropServices.DllImport(WildGvDllFilePath, SetLastError:=False)> _
Private Shared Function GetNamedString(ByVal sStringVarName As String, ByVal sErrorCode As String) As IntPtr
End Function
<System.Runtime.InteropServices.DllImport(WildGvDllFilePath, SetLastError:=False)> _
Private Shared Function GetString(ByVal iLocation As Integer) As IntPtr
End Function
Public Shared Function GV_GetString(ByVal iLocation As Integer) As String
Dim ptr As IntPtr = GetString(iLocation)
Return Marshal.PtrToStringAuto(ptr)
End Function
Public Shared Function GV_GetNamedString(ByVal sStringVarName As String, ByVal sErrorCode As String) As String
Dim ptr As IntPtr = GetNamedString(sStringVarName, sErrorCode)
Return Marshal.PtrToStringAnsi(ptr)
End Function
End Class
Code: Select all
Namespace PowerLanguage
Namespace [Function]
Public NotInheritable Class _GVLibWrap_
Const PathToWrapper As String = "C:\Program Files\TS Support\MultiCharts64\GlobalVariable.dll"
<DllImport(PathToWrapper)> _
Public Shared Function InitializeGV() As Boolean
End Function
<DllImport(PathToWrapper)> _
Public Shared Sub UninitializeGV()
End Sub
<DllImport(PathToWrapper)> _
Public Shared Function SetDataInt(ByVal _s As [String], ByVal _v As Integer) As Boolean
End Function
<DllImport(PathToWrapper)> _
Public Shared Function GetDataInt(ByVal _s As [String]) As Integer
End Function
<DllImport(PathToWrapper, CharSet:=CharSet.Unicode)> _
Public Shared Function SetDataLong(ByVal _s As [String], ByVal _v As Long) As Boolean
End Function
<DllImport(PathToWrapper, CharSet:=CharSet.Unicode)> _
Public Shared Function GetDataLong(ByVal _s As [String]) As Long
End Function
<DllImport(PathToWrapper, CharSet:=CharSet.Unicode)> _
Public Shared Function SetDataFloat(ByVal _s As [String], ByVal _v As Single) As Boolean
End Function
<DllImport(PathToWrapper, CharSet:=CharSet.Unicode)> _
Public Shared Function GetDataFloat(ByVal _s As [String]) As Single
End Function
<DllImport(PathToWrapper, CharSet:=CharSet.Unicode)> _
Public Shared Function SetDataDouble(ByVal _s As [String], ByVal _v As Double) As Boolean
End Function
<DllImport(PathToWrapper, CharSet:=CharSet.Unicode)> _
Public Shared Function GetDataDouble(ByVal _s As [String]) As Double
End Function
<DllImport(PathToWrapper)> _
Public Shared Function SetDataString(ByVal _s As [String], ByVal _v As [String]) As Boolean
End Function
<DllImport(PathToWrapper)> _
Public Shared Function GetDataString(ByVal _s As [String]) As [String]
End Function
End Class
End Namespace