例:
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);
}
構文:
using System.Runtime.InteropServices;
public class {クラス名} {
//以下プロトタイプ宣言
[DllImport("dllname",{オブジェクトフィールド})]
{public | private | protected} static extern {戻り値形式} {関数名}(正確な引数);
// [DllImport("dllname",{オブジェクトフィールド,[オブジェクトフィールド2],..})]
// {public | private | protected} static extern {戻り値形式} {関数名2}(正確な引数);
// :
// :
// :
//ここまで
void main(){/*定義した関数を実際に利用する*/}
}
オブジェクトフィールドにはEntryPoint="関数名"などが入る。
*ただし、EntryPointは定義する関数名とDLLのエントリ関数名が同じになる場合は省略
できる。
資料: http://ukamen.hp.infoseek.co.jp/Programming/iniFile/
参照: ms-help://MS.VSCC/MS.MSDNVS.1041/cpguide/html/cpconcreatingprototypesinmanagedcode.htm
| .Net Frameworkが提供するネットワーク用のクラス | |
| WebClient | HTTPなどのプロトコルでデータ送受信するクラス。簡単だが非同期処理不可。 |
| WebRequest | HTTPなどでデータを要求するためのクラス |
| WebResponse | 要求に対する応答の結果をあらわすクラス。このクラスを使えばデータを取得できる。 |
| TcpClient | TCP/IPを利用して通信を行うクラス。簡単だが非同期処理不可。 |
| Socket | TCP/IPを利用するための基本クラス。 |
WebClientを使った例:
using System.Net; //WebClient
using System.IO; //Stream,StreamReader
using System.Windows.Forms; //MessageBox
namespace std
{
class c1
{
public static void Main()
{
WebClient client = new WebClient();
Stream strm = client.OpenRead("http://www.ecoop.net/");
StreamReader sr = new StreamReader(strm);
MessageBox.Show(sr.ReadToEnd());
}
}
}