C# 2006/12/08 12:42

C#에서 dll을 링크 2

앞의 예제는 콘솔 프로그램으로 dll을 사용해 봤고 지금것은 WinForm을 사용하였다. 그래서 dll로 MessageBox함수를 수행하는 dll을 만들었다.


extern "C" __declspec(dllexport)int MsgBox(HWND hWnd,LPCTSTR lpTest,LPCTSTR lpCaption,int uType)
{
    return MessageBox(hWnd,lpTest,lpCaption,(UINT)uType);
}
 



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace DllTest
{
   public partial class Form1 : Form
   {
       [DllImport("MyDll.dll", CharSet = CharSet.Ansi)]
       public static extern int MsgBox(IntPtr hWnd,string lpTest,string lpCaption,int uType);
       public Form1()
       {
           InitializeComponent();
       }
       private void button1_Click(object sender, EventArgs e)
       {
           MsgBox(this.Handle, "메세지", "타이틀", 0);
       }
   }
}
 


User inserted image


위의 메세지 박스는 dll을 사용하였다.

Trackback url :: http://hahakbs.dothost.co.kr/trackback/40

댓글을 달아 주세요


div>