Beispiel #1
0
 private void Initialize()
 {
     try {
         // Initialize the factory
         MTRetCode res = SMTManagerAPIFactory.Initialize(GetMTDllPath());
         if (MTRetCode.MT_RET_OK != res)
         {
             throw new MT5Exception("SMTManagerAPIFactory.Initialize failed", res);
         }
         // Receive the API version
         res = SMTManagerAPIFactory.GetVersion(out uint version);
         if (MTRetCode.MT_RET_OK != res)
         {
             throw new MT5Exception("SMTManagerAPIFactory.GetVersion failed", res);
         }
         // Check API version
         if (version != SMTManagerAPIFactory.ManagerAPIVersion)
         {
             throw new MT5Exception($"Manager API version mismatch - {version}!={SMTManagerAPIFactory.ManagerAPIVersion}");
         }
         // Create new manager
         ManagerAPI = SMTManagerAPIFactory.CreateManager(version, out res);
         if (MTRetCode.MT_RET_OK != res)
         {
             throw new MT5Exception("SMTManagerAPIFactory.CreateManager failed", res);
         }
         if (null == ManagerAPI)
         {
             throw new MT5Exception("SMTManagerAPIFactory.CreateManager returned null");
         }
         //
         res = RegisterSink();
         if (MTRetCode.MT_RET_OK != res)
         {
             throw new MT5Exception("CIMTManagerSink.RegisterSink failed", res);
         }
         // Subscribe for events
         res = ManagerAPI.Subscribe(this);
         if (MTRetCode.MT_RET_OK != res)
         {
             throw new MT5Exception("CIMTManagerAPI.Subscribe failed", res);
         }
     }
     catch {
         ManagerAPI?.Release();
         SMTManagerAPIFactory.Shutdown();
         throw;
     }
 }