Esempio n. 1
0
        //===================================================================================
        public CONNECT_HEADER PrepareHeader(uint msg_id)
        {
            CONNECT_HEADER Header = new CONNECT_HEADER();

            Header.msg_id     = msg_id;
            Header.ProcessId  = ProcessId;
            Header.tickCount  = Kernel32.GetTickCount();
            Header.RandomId   = random.Next(0, 100000);
            Header.ClientName = StringToByte(ClientName, Global.MAX_CLIENTNAME_LENGTH, Encoding.ASCII);
            Header.ClientName = StringToByte(ClientCompName, Global.MAX_COMPUTERNAME_LENGTH, Encoding.ASCII);
            return(Header);
        }
Esempio n. 2
0
        //===================================================================================
        public bool SendMsg <T>(uint msg_id, T Data)
        {
            bool ret = true;
            int  TransmitMsg_size = 0;

            byte[] TransmitMsg = null;
            int    sizeHeader  = 0;
            int    sizeT       = Marshal.SizeOf(typeof(T));
            IntPtr intptr      = IntPtr.Zero;

            if (mode == ConnectionMode.OTHER_COMPUTER)
            {
                sizeHeader = Marshal.SizeOf(typeof(CONNECT_HEADER));

                TransmitMsg_size = sizeHeader + sizeT;
                TransmitMsg      = new byte[TransmitMsg_size];
                CONNECT_HEADER Header = PrepareHeader(msg_id);
                intptr = Marshal.AllocHGlobal(TransmitMsg_size); // place for (CONNECT_HEADER) header + T data
                Marshal.StructureToPtr(Header, intptr, true);
            }

            else
            {
                sizeHeader = Marshal.SizeOf(typeof(CONNECT_SHORT_HEADER));

                TransmitMsg_size = sizeHeader + sizeT;
                TransmitMsg      = new byte[TransmitMsg_size];
                CONNECT_SHORT_HEADER Header = PrepareShortHeader(msg_id);
                intptr = Marshal.AllocHGlobal(TransmitMsg_size); // place for (CONNECT_SHORT_HEADER) header + T data
                Marshal.StructureToPtr(Header, intptr, true);
            }
            Marshal.StructureToPtr(Data, intptr + sizeHeader, true);
            Marshal.Copy(intptr, TransmitMsg, 0, TransmitMsg_size);
            Marshal.FreeHGlobal(intptr);
            ret = Send(TransmitMsg);
            return(ret);
        }