/*2개의 Application이 동작한다. 2개의 Application이 Data를 Communication할때에 사용하는 방식이다.
1. Console에서 Key를 동작하여, 다른 Application으로 SendMessage(Text)한다. 일명 조정
2. 다른 Application에서는 WndProc(override frm)에서 WM_COPYDATA를 통해서 데이타를 받은다음에 
Key에 따라서 동작한다.
3. 억지로 말을 붙이자면, 한쪽방향으로의 클라이언트,서버의 관계이다.*/

>주의할점은 Tris Server Frm(No Key) 의 Application의 Handle이 반드시 일단 존재해야 한다.

____snd.cs
0.00MB

 

____rcv.cs
0.01MB

 

/*Data communication between Proesses!!*/

Windows OS
프로세스간 Window Handle 공유를 통한 SendMessage & WndProc(WM_COPYDATA)

참조)
SendMessage/FindWindow/Snd/Rcv Str :: 석수코딩교육 (tistory.com)

Linux & Unix OS
1) 프로세스간 Message Queue 공유를 통한 Message Send & Recv
2) 프로세스간 Semaphor & Shared Meory 공유를 통한 Message Send & Recv(비추)

/*
*상속안할경우 나오는 에러메세지*/


Microsoft (R) Visual C# Compiler version 4.8.4084.0
for C# 5
Copyright (C) Microsoft Corporation. All rights reserved.

This compiler is provided as part of the Microsoft (R) .NET Framework, but only supports language versions up to C# 5, which is no longer the latest version. For compilers that support newer versions of the C# programming language, see http://go.microsoft.com/fwlink/?LinkID=533240

ex12.cs(18,26): error CS0115: 'WindowsFrmManage.ProcessCmdKey(ref NoName.Windows.Forms.Message,
        NoName.Windows.Forms.Keys)': 재정의할 적절한 메서드를 찾을 수 없습니다.
ex12.cs(40,26): error CS0115: 'WindowsFrmManage.WndProc(ref NoName.Windows.Forms.Message)': 재정의할 적절한 메서드를 찾을 수 없습니다.

using NoName;
using NoName.Windows.Forms;

class Program
{
public static void Main(string[] args)
{
Application.Run(new WindowsFrmManage());
}
}
class WindowsFrmManage
{
public WindowsFrmManage() {}

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
const int WM_KEYDOWN = 0x0100, WM_KEYUP = 0x0101, WM_CHAR = 0x0102, WM_SYSKEYDOWN = 0x0104, WM_SYSKEYUP = 0x0105, WM_PAINT = 0x000f, WM_SIZE = 0x0005;

if ((msg.Msg == WM_KEYDOWN) || (msg.Msg == WM_SYSKEYDOWN))
{
         switch (keyData.ToString())
{
case "Down"   :
break;
case "Escape" :
Application.Exit();
break;
         default:
             break;
         }
     }
return base.ProcessCmdKey(ref msg, keyData);
}

protected override void WndProc(ref Message m)//sdw_mh12e
{
const int WM_KEYDOWN = 0x0100, WM_KEYUP = 0x0101, WM_CHAR = 0x0102, WM_SYSKEYDOWN = 0x0104, WM_SYSKEYUP = 0x0105, WM_PAINT = 0x000f, WM_SIZE = 0x0005;

base.WndProc(ref m);

switch(m.Msg)
{
case WM_PAINT :
break;
default:
break;
}
}
}


using NoName;
using NoName.Windows.Forms;

class FrmIndex006 : Form
{
public FrmIndex006()
{
Console.WriteLine(">>>>FrmIndex006");
}
}

class FrmIndex007 : FrmIndex006
{
public FrmIndex007()
{
Console.WriteLine(">>>>FrmIndex007");
}
}

class FrmIndex008 : FrmIndex007
{
public FrmIndex008()
{
Console.WriteLine(">>>>FrmIndex008");
}
}

class FrmIndex009 : FrmIndex008
{
public FrmIndex009()
{
Console.WriteLine(">>>>FrmIndex009");
}
}

class FrmIndex010 : FrmIndex009
{
public FrmIndex010()
{
Console.WriteLine(">>>>FrmIndex010");
}
}

class FrmMain : FrmIndex010
{
public FrmMain()
{
Console.WriteLine(">>>>FrmMain");
}
protected override void WndProc(ref Message m)
{
const int WM_KEYDOWN = 0x0100, WM_SYSKEYDOWN = 0x0104, WM_PAINT = 0x000f, WM_SIZE = 0x0005;

base.WndProc(ref m);

try
{
switch(m.Msg)
{
case WM_PAINT :
DialogResult dialogResult = MessageBox.Show(">>Quit OK!!", "Inform",
              MessageBoxButtons.OKCancel, MessageBoxIcon.Information);

if (dialogResult == DialogResult.OK) Application.Exit();
break;
default:
break;
}
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
/*
D:\tmp\console>sample
>>>>FrmIndex006
>>>>FrmIndex007
>>>>FrmIndex008
>>>>FrmIndex009
>>>>FrmIndex010
>>>>FrmMain

D:\tmp\console>
*/

class Program
{
public static void Main()
{
Application.Run(new FrmMain());
}
}


Server : Redis Server

1. Language : c,pro*c,socket,oracle

Client : Redis Client

1. Language : c#
2. IDE : visual studio 2019 professional
3. Core
    3.1 BackgroundWorker
    3.2 WndProc - WM_COPYDATA
    3.3 SendMessage
    3.4 DLL

다형성(polymorphism)은 무엇인가요?

polymorphism에서 poly는 여러, 다양한(many), morph는 변형(change)이나 형태(form)의 의미를 가지고 있습니다. 
사전적 정의로만 살펴보면 "여러가지 형태"를 나타내는데, 이를 객체 지향 프로그래밍으로 끌고 온다면 "하나의 객체가 여러 개의 형태를 가질 수 있는 능력"이라 말할 수 있습니다. 


우리는 이미 다형성을 접해본 적이 있습니다. 다형성의 일부인 메소드의 오버로딩(이는 ad-hoc polymorphism에 해당)과 오버라이딩(이는 inclusion polymorphism에 해당)에서 말이죠! 
C#도 객체 지향 프로그래밍에 근간을 두고 있으므로 이 다형성이라는 개념은 자주 사용됩니다.

클래스의 상속(Class inheritance)

상속이란 말을 어디선가 들어본 적이 있는 것 같지 않나요? 
짐작하는 그 상속이 맞냐구요? 네 맞습니다. 
혹시나 상속이 뭔지 들어보 적 없는 분들을 위해 무엇인지 알려드리려고 합니다. 
상속이란 네이버 지식백과를 빌어 다음과 같이 정의되어 있습니다. 
'일정한 친족적 관계가 있는 사람 사이에 한 쪽이 사망하거나 법률상의 원인이 발생하였을 때 재산적 또는 친족적 권리와 의무를 계승하는 제도'. 
즉, 부모님이 돌아가셨다고 할 때 그 유산을 자식이 물려받는 것이라고 할 수 있습니다. 
클래스의 상속도 이와 똑같습니다. 
객체 지향 프로그래밍에선 부모 클래스와 자식 클래스가 있는데, 
부모 클래스는 자식 클래스의 기반이 된다 하여 기반 클래스라고 부르기도 하고, 
자식 클래스는 부모 클래스로부터 파생되었다고 해서 파생 클래스라고도 부르기도 합니다.

C#에서, 클래스를 다른 클래스로 상속하려면 다음과 같이 클래스 이름 뒤에 콜론(:)을 추가하고 상속하려는 클래스의 이름을 덧붙이시면 됩니다.

using NoName;
using NoName.Windows.Forms;
using NoName.Timers;

class FrmMain : Form
{
NoName.Timers.Timer tm = new NoName.Timers.Timer();
FrmChild f1 = new FrmChild();

int ____width=0;
int ____height=0;
int ____idx=0;

public FrmMain()
{
this.Text="FrmMain";

tm.Elapsed += new ElapsedEventHandler(____time_tick);
tm.Interval = 1000;
tm.Start();

f1.Show();
}
void ____time_tick(object sender, ElapsedEventArgs e)
{
this.Width = f1.Width + ____width;
this.Height = f1.Height + ____height;

____width += 10;
____height += 10;

____idx++;
if(____idx==13) f1.Close();
if(____idx==14) this.Close();

this.Text = "FrmMain" + ">>>[" + ____idx.ToString("0000") + "]";
}
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
const int WM_KEYDOWN = 0x0100, WM_SYSKEYDOWN = 0x0104, WM_PAINT = 0x000f, WM_SIZE = 0x0005;

if ((msg.Msg == WM_KEYDOWN) || (msg.Msg == WM_SYSKEYDOWN))
{
         switch (keyData.ToString())
         {
case "Return" :
DialogResult dialogResult = MessageBox.Show("[" + this.Text + "]" + ">>Quit OK!!", "Inform",
              MessageBoxButtons.OKCancel, MessageBoxIcon.Information);

if (dialogResult == DialogResult.OK) Application.Exit();
break;
case "Right"  :
break;
case "Left"   :
break;
         default:
             break;
         }
     }
return base.ProcessCmdKey(ref msg, keyData);
}
protected override void WndProc(ref Message m)
{
const int WM_KEYDOWN = 0x0100, WM_SYSKEYDOWN = 0x0104, WM_PAINT = 0x000f, WM_SIZE = 0x0005;

base.WndProc(ref m);

try
{
switch(m.Msg)
{
case WM_PAINT :
break;
default:
break;
}
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}

class FrmChildBase : Form
{
//
}

class FrmChild : FrmChildBase
{
public FrmChild()
{
this.Width=400;
this.Height=400;

this.Text="FrmChild";
}
}

class Program
{
public static void Main()
{
Application.Run(new FrmMain());
}
}






IntPtr 구조체

정의
네임스페이스:
System
어셈블리:
System.Runtime.dll
포인터나 핸들을 나타내는 데 사용되는 플랫폼별 형식입니다.

using NoName;
using NoName.Runtime.InteropServices;

class NotTooSafeStringReverse
{
    static public void Main()
    {
        string stringA = "I seem to be turned around!";
        int copylen = stringA.Length;

        // Allocate HGlobal memory for source and destination strings
        IntPtr sptr = Marshal.StringToHGlobalAnsi(stringA);
        IntPtr dptr = Marshal.AllocHGlobal(copylen + 1);

        // The unsafe section where byte pointers are used.
        unsafe
        {
            byte *src = (byte *)sptr.ToPointer();
            byte *dst = (byte *)dptr.ToPointer();

            if (copylen > 0)
            {
                // set the source pointer to the end of the string
                // to do a reverse copy.
                src += copylen - 1;

                while (copylen-- > 0)
                {
                    *dst++ = *src--;
                }
                *dst = 0;
            }
        }
        string stringB = Marshal.PtrToStringAnsi(dptr);

        Console.WriteLine("Original:\n{0}\n", stringA);
        Console.WriteLine("Reversed:\n{0}", stringB);

        // Free HGlobal memory
        Marshal.FreeHGlobal(dptr);
        Marshal.FreeHGlobal(sptr);
    }
}

/*--------------------------------------------------------------------
D:\tmp\console>csc sample.cs /unsafe
Microsoft (R) Visual C# Compiler version 4.8.4084.0
for C# 5
Copyright (C) Microsoft Corporation. All rights reserved.

This compiler is provided as part of the Microsoft (R) .NET Framework, but only supports language versions up to C# 5, which is no longer the latest version. For compilers that support newer versions of the C# programming language, see http://go.microsoft.com/fwlink/?LinkID=533240


D:\tmp\console>
D:\tmp\console>
D:\tmp\console>
D:\tmp\console>
D:\tmp\console>
D:\tmp\console>ex44
Original:
I seem to be turned around!

Reversed:
!dnuora denrut eb ot mees I

D:\tmp\console>
--------------------------------------------------------------------*/

+ Recent posts