NET Platform 에서 기존의 WIn32에 있는 함수등을 사용하는 Platform Invoke는 metadata에서 수행할 수 있다.
의 네임스페이스를 정의해주고..
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern int MessageBox(int hWnd, String text, string caption, uint type);
라고 해주면된다...
static 동적 함수이므로... 클래스생성을 않해줘도 사용이 가능하다.
-------------------------------------------------------------------------------
가끔 C++ DLL 을 불러올때.. 인자값이 Char* 인경우~
위와같이 DllImport에 DLL이름만 정의해주면 된다.
using System;
using System.Runtime.InteropServices;
public class Win32
{
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern int MessageBox(int hWnd, String text, string caption, uint type);
}
public class HelloWorld
{
public static void Main()
{
Win32.MessageBox(0, "Hello World", "Platform Invoke Sample", 0);
}
}
의 네임스페이스를 정의해주고..
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern int MessageBox(int hWnd, String text, string caption, uint type);
라고 해주면된다...
static 동적 함수이므로... 클래스생성을 않해줘도 사용이 가능하다.
-------------------------------------------------------------------------------
가끔 C++ DLL 을 불러올때.. 인자값이 Char* 인경우~
[DllImport("HCITTS.dll")]
public static extern int PlayTTS(String lpszText, int enSpeechType, int enMode);
위와같이 DllImport에 DLL이름만 정의해주면 된다.
'SoftWare > Visual C#' 카테고리의 다른 글
| C# 윈도우메세지 WM_USER MESSAGE 받기 (0) | 2009.03.06 |
|---|---|
| C# 대리자 Invoke (0) | 2009.03.06 |
| C# 의 Handle hWND (0) | 2009.03.06 |
| C# 형변환 (0) | 2009.03.06 |
| C# ControlArray 사용하기 (0) | 2009.03.06 |
댓글