Read/Write Global Variables from C#/VB

Questions about MultiCharts and user contributed studies.
a2trader
Posts: 1
Joined: 10 Aug 2012

Read/Write Global Variables from C#/VB

Postby a2trader » 18 Aug 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:

Code: Select all

PowerLanguage.Function._GVLibWrap_.InitializeGV()
LegacyGlobalVariables.GV_SetNamedString("A", "123")
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?

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

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Read/Write Global Variables from C#/VB

Postby Henry MultiСharts » 21 Aug 2013

Hello a2trader,

With PowerLanguage please use the following GV documentation and sample codes:
viewtopic.php?t=2483
https://www.multicharts.com/trading-sof ... _Variables

Extension Software Development Kit (SDK) provides users with the ability to write code in a programming language that allows for the creation of DLLs (for example, C++, Pascal, Delphi, or Visual Basic) and call that code from within an EasyLanguage analysis technique:
http://developer.TS.com/docum ... on_SDK.pdf


Return to “MultiCharts”