c# -25

Interoperability -> 뭔뜻? -> 상호운영성 -> 그래서이게뭔데 ? -> dll이랑 com등 여러 리소스들을 적제적소에 활용하는 ablity를 말하는듯


Calling into Native DLLs -> native dll 부르기 -> Native dll 이뭐임? -> c#에서 기본적으로 제공하는 dll을 말하는거같음 -> winform 에 messagebox 는 "DLL user32.dll"에 정의되있음

이걸 바로쓸라면 

->>
using System; using System.Runtime.InteropServices; 
class MsgBoxTest { [DllImport("user32.dll")] 
 static extern int MessageBox (IntPtr hWnd, string text, string caption, int type); 
 public static void Main() { 
 MessageBox (IntPtr.Zero, "Please do not press this again.", "Attention", 0);
 }

dllimport("dllName")]으로 dll을 바로사용할 수 이음

물론 dllName 은 Path까지 정의된 이름이여야함.

만약 그냥 이름만 쓴다면 debug폴더내에 dll파일이 존재해야함.



Marshaling- > 서로다른 디바이스 어플리케이션간의 데이터 전송이 필요할때
전송할 데이터 에 행해지는 사전작업


-> 디바이스/어플리케이션간 데이터를 주고받을떄 사전작업이 필요한 이유
->little Endian, big Endian 일경우 어떡해 처리할 것인가?



구현 방법은 크게 다르지 않다.
 using System.IO; //직렬화를 위한 MEMORYSTREAM
using System.Runtime.Serialization.Formatters.Binary; //직렬화를 위함
일단 클래스를 직렬화 한다고 할때 [Serializable]이라는 Attribute를 붙여준다.
붙여주지 않고 클래스를 직렬화 하면 에러가 발생한다.
[Serializable]
public class SendDataClass
{
public string header;
public long HardTotalSize;
public long HardAvaliableSize;
}
..중간생략
   
직렬화 과정
SendDataClass sendclass = new SendDataClass();
sendclass.header="MSG:";
sendclass.HardTotalSize = 155;
sendclass.HardAvaliableSize = 222;

MemoryStream MSSendData = new MemoryStream();

BinaryFormatter BFSendData = new BinaryFormatter();
BFSendData.Serialize(MSSendData,sendclass);
//Soap의 경우 포맷터만 바꿔주면 된다. SoapFormatter
   
역직렬화 과정
//역직렬화 시작
MemoryStream MSSendData2 = new MemoryStream(SendDataByte);
BinaryFormatter BFSendData2 = new BinaryFormatter();
SendDataClass receiveclass = (SendDataClass)BFSendData2.Deserialize(MSSendData2);
//역직렬화 끝 



댓글

가장 많이 본 글