Click here to Skip to main content
15,890,579 members
Home / Discussions / C#
   

C#

 
QuestionHow to pass a variable inside Try{} to outside of it? Pin
Alex Dunlop30-Jul-21 23:05
Alex Dunlop30-Jul-21 23:05 
AnswerRe: How to pass a variable inside Try{} to outside of it? Pin
OriginalGriff30-Jul-21 23:27
mveOriginalGriff30-Jul-21 23:27 
AnswerRe: How to pass a variable inside Try{} to outside of it? Pin
Victor Nijegorodov30-Jul-21 23:28
Victor Nijegorodov30-Jul-21 23:28 
QuestionitextSharp with C# Pin
Ismael Oliveira 202129-Jul-21 6:08
Ismael Oliveira 202129-Jul-21 6:08 
AnswerRe: itextSharp with C# Pin
Dave Kreskowiak29-Jul-21 6:33
mveDave Kreskowiak29-Jul-21 6:33 
GeneralRe: itextSharp with C# Pin
Ismael Oliveira 202131-Jul-21 14:50
Ismael Oliveira 202131-Jul-21 14:50 
GeneralRe: itextSharp with C# Pin
Dave Kreskowiak31-Jul-21 15:05
mveDave Kreskowiak31-Jul-21 15:05 
QuestionHow to create filtering for DataTable based on toggle switches? Pin
Alex Dunlop27-Jul-21 21:46
Alex Dunlop27-Jul-21 21:46 
AnswerRe: How to create filtering for DataTable based on toggle switches? Pin
OriginalGriff27-Jul-21 21:53
mveOriginalGriff27-Jul-21 21:53 
GeneralRe: How to create filtering for DataTable based on toggle switches? Pin
Alex Dunlop27-Jul-21 22:03
Alex Dunlop27-Jul-21 22:03 
GeneralRe: How to create filtering for DataTable based on toggle switches? Pin
OriginalGriff27-Jul-21 22:13
mveOriginalGriff27-Jul-21 22:13 
GeneralRe: How to create filtering for DataTable based on toggle switches? Pin
Alex Dunlop27-Jul-21 23:35
Alex Dunlop27-Jul-21 23:35 
GeneralRe: How to create filtering for DataTable based on toggle switches? Pin
OriginalGriff28-Jul-21 0:47
mveOriginalGriff28-Jul-21 0:47 
GeneralRe: How to create filtering for DataTable based on toggle switches? Pin
Alex Dunlop28-Jul-21 20:11
Alex Dunlop28-Jul-21 20:11 
GeneralRe: How to create filtering for DataTable based on toggle switches? Pin
OriginalGriff28-Jul-21 22:00
mveOriginalGriff28-Jul-21 22:00 
AnswerRe: How to create filtering for DataTable based on toggle switches? Pin
jsc4227-Jul-21 23:35
professionaljsc4227-Jul-21 23:35 
QuestionHow to copy DataTable contents into SQLite table? Pin
Alex Dunlop26-Jul-21 20:37
Alex Dunlop26-Jul-21 20:37 
AnswerRe: How to copy DataTable contents into SQLite table? Pin
OriginalGriff26-Jul-21 21:06
mveOriginalGriff26-Jul-21 21:06 
GeneralRe: How to copy DataTable contents into SQLite table? Pin
Alex Dunlop26-Jul-21 21:16
Alex Dunlop26-Jul-21 21:16 
GeneralRe: How to copy DataTable contents into SQLite table? Pin
Alex Dunlop26-Jul-21 22:58
Alex Dunlop26-Jul-21 22:58 
GeneralRe: How to copy DataTable contents into SQLite table? Pin
OriginalGriff26-Jul-21 23:09
mveOriginalGriff26-Jul-21 23:09 
GeneralRe: How to copy DataTable contents into SQLite table? Pin
Alex Dunlop27-Jul-21 0:39
Alex Dunlop27-Jul-21 0:39 
AnswerRe: How to copy DataTable contents into SQLite table? Pin
Richard Andrew x6428-Jul-21 2:36
professionalRichard Andrew x6428-Jul-21 2:36 
QuestionRTD communication error (COM) / .ConnectData(Int32 topicId, Object[]& parameters, Boolean& newValue) Pin
Juliano Zucatti26-Jul-21 10:14
Juliano Zucatti26-Jul-21 10:14 
I created a client to communicate with RTD server, my knowledge is small in C# I have greater in JAVA, but I didn't find anything likely to be used in JAVA, I'm using this example of a C# client


C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Threading;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
namespace DotNet2
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            chamaMetodo("RTDTrading.RTDServer");
        }

        private static void chamaMetodo(string v)
        {
                       
            RtdClient rtd = new RtdClient(v);
            Console.WriteLine("rtd:"+rtd);
            
            object[] param = new Object[2];
            param[0] = "DOLFUT_F_0";
            param[1] = "HOR";
            Object ret = rtd.GetValue(param);
            Console.WriteLine("ret:"+ret);
        }
    }

}


Class Interface que monta a comunicação:


C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Threading;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;

namespace DotNet2
{
    public interface IRtdClient
    {
        object GetValue(params object[] args);
    }

    public class RtdClient : IRtdClient
    {
        readonly string _rtdProgId;
        static IRtdServer _rtdServer;
        

        public RtdClient(string rtdProgId)
        {
            _rtdProgId = rtdProgId;
        }

        public object GetValue(params object[] args)
        {
            
            const int topicCount = 1;
            var rnd = new Random();
            var topicId = rnd.Next(int.MaxValue);
            var rtdServer = GetRtdServer();
            Console.WriteLine("TopicID "+topicId+" args:"+args[0]+" args2:"+args[1]);
            
            rtdServer.ConnectData(topicId, args, true);

            object val = null;
            while (val == null)
            {
                var alive = rtdServer.Heartbeat();
                
                if (alive != 1)
                    GetRtdServer();
                else
                {
                    //var refresh = new object[0,0];
                    var refresh = rtdServer.RefreshData(topicCount);
                    if (refresh.Length <= 0) continue;

                    if (refresh[0, 0].ToString() == topicId.ToString())
                    {
                        val = refresh[1, 0];
                    }
                }
            }

            rtdServer.DisconnectData(topicId);

            return val;
        }

        IRtdServer GetRtdServer()
        {
            if (_rtdServer == null)
            {
                Type rtd = Type.GetTypeFromProgID(_rtdProgId);
                _rtdServer = (IRtdServer)Activator.CreateInstance(rtd);
            }
            return _rtdServer;
        }
    }

    [ComImport,
        TypeLibType((short)0x1040),
        Guid("EC0E6191-DB51-11D3-8F3E-00C04F3651B8")]
    public interface IRtdServer
    {
        [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(10)]
        int ServerStart([In, MarshalAs(UnmanagedType.Interface)] IRTDUpdateEvent callback);

        [return: MarshalAs(UnmanagedType.Struct)]
        [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(11)]
        object ConnectData([In] int topicId, [In, MarshalAs(UnmanagedType.SafeArray,
                                                SafeArraySubType = VarEnum.VT_VARIANT)] ref object[] parameters, [In, Out] ref bool newValue);

        [return: MarshalAs(UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_VARIANT)]
        [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(12)]
        object[,] RefreshData([In, Out] ref int topicCount);

        [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(13)]
        void DisconnectData([In] int topicId);

        [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(14)]
        int Heartbeat();

        [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(15)]
        void ServerTerminate();
    }

    [ComImport,
        TypeLibType((short)0x1040),
        Guid("A43788C1-D91B-11D3-8F39-00C04F3651B8")]
    public interface IRTDUpdateEvent
    {
        [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(10),
            PreserveSig]
        void UpdateNotify();

        [DispId(11)]
        int HeartbeatInterval
        {
            [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(11)]
            get; [param: In]
            [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(11)]
            set;
        }

        [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(12)]
        void Disconnect();
    }

}


But I'm getting this error, in the method call:rtdServer.ConnectData(topicId, args, true);

C#
Unhandled exception. System.Runtime.InteropServices.COMException (0x8000FFFF): Falha catastrófica (0x8000FFFF (E_UNEXPECTED))
at DotNet2.IRtdServer.ConnectData(Int32 topicId, Object[]& parameters, Boolean& newValue)



Is anyone aware of the error?


modified 26-Jul-21 18:00pm.

QuestionHow to shuffle an array VS Windows Form Application? Pin
Sofi081326-Jul-21 0:26
Sofi081326-Jul-21 0:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.