青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

為生存而奔跑

   :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
  271 Posts :: 0 Stories :: 58 Comments :: 0 Trackbacks

留言簿(5)

我參與的團(tuán)隊(duì)

搜索

  •  

積分與排名

  • 積分 - 331752
  • 排名 - 74

最新評論

閱讀排行榜

評論排行榜

Implementing APIs in C# is a tough job for beginners. Before implementing API you should know how to implement structure in C#, type conversion, safe/unsafe code, managed/unmanaged code and lots more.

Before implementing complex APIs we will start with simple MessageBox API. To implement code for the MessageBoxAPI open a new C# project and add one button. When button gets clicked the code will display a Message Box.

Since we are using external library, add a namespace:

 Collapse code snippet
using System.Runtime.InteropServices;

Add the following lines to declare the API

 Collapse
[DllImport("User32.dll")]
public static extern int MessageBox(int h, string m, string c, int type);

Here the DllImport attribute is used for calling the method from unmanaged code. "User32.dll" indicates the library name. The DllImport attribute specifies the dll location that contains the implementation of an extern method. Thestatic modifier is used to declare a static member, which belongs to the type itself rather than to a specific object,extern is used to indicate that the method is implemented externally. A method that is decorated with the DllImportattribute must have the extern modifier.

MessageBox is the function name, which returns int and takes 4 parameters as shown in declaration.

Many APIs use structures to pass and retrieve values, as it is less expensive. It also uses constant data type for passing constant data and simple data types for passing built-in data types as seen in the previous declaration of the MessageBox function.

Add following code for button click event:

 Collapse
protected void button1_Click(object sender, System.EventArgs e)
{
	MessageBox (0,"API Message Box","API Demo",0);
}

Compile and run project, after clicking on the button you will see a MessageBox, which you called using API the function!!!

Using Structures

Working with APIs, which use complex structures, or structures inside structures, is somewhat more complex than using simple APIs. But once you understand the implementation then the whole API world is yours.

In next example we will use GetSystemInfo API which returns information about the current system.

The first step is open a new C# form and add one button on it. Go to the code window of the form and add a namespace:

 Collapse
using System.Runtime.InteropServices;

Declare the structure, which is the parameter of GetSystemInfo.

 Collapse
[StructLayout(LayoutKind.Sequential)]
public struct SYSTEM_INFO {
	public uint dwOemId;
	public uint dwPageSize;
	public uint lpMinimumApplicationAddress;
	public uint lpMaximumApplicationAddress;
	public uint dwActiveProcessorMask;
	public uint dwNumberOfProcessors;
	public uint dwProcessorType;
	public uint dwAllocationGranularity;
	public uint dwProcessorLevel;
	public uint dwProcessorRevision;
}

Declare the API function:

 Collapse
[DllImport("kernel32")]
static extern void GetSystemInfo(ref SYSTEM_INFO pSI); 

Where ref is next to the method parameter keyword it causes a method to refer to the same variable that was passed into the method.

Add the following code in the button click event in which we first create a struct object and then pass it to function.

 Collapse
protected void button1_Click (object sender, System.EventArgs e)
{
	try
	{
		SYSTEM_INFO pSI = new SYSTEM_INFO();
		GetSystemInfo(ref pSI);
		//

		//

		//

Once you retrieve the structure, perform operations on the required parameter

e.g.listBox1.InsertItem (0,pSI.dwActiveProcessorMask.ToString());:

 Collapse
		//

		//

		//

	}
	catch(Exception er)
	{
		MessageBox.Show (er.Message);
	}
}
posted on 2009-12-20 14:09 baby-fly 閱讀(311) 評論(0)  編輯 收藏 引用 所屬分類: C#
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            亚洲免费影院| 久久精品亚洲一区| 欧美成人免费网| 香蕉尹人综合在线观看| 一本一本a久久| 一区二区三区欧美视频| 亚洲一品av免费观看| 亚洲伊人第一页| 欧美一区二区三区在线看| 久久成人免费网| 久久精品99久久香蕉国产色戒| 久久久久综合网| 亚洲高清在线| 亚洲美女黄网| 久久国产精品久久精品国产 | 亚洲欧洲精品一区二区三区 | 久久精品国产999大香线蕉| 欧美一级在线播放| 久久综合一区| 一区二区三区精品视频| 香港成人在线视频| 免费国产一区二区| 国产精品乱码一区二区三区| 激情综合久久| 亚洲欧美久久久| 免费欧美电影| 亚洲一区亚洲| 一本色道**综合亚洲精品蜜桃冫 | 在线日韩日本国产亚洲| aaa亚洲精品一二三区| 久久久久成人精品| 日韩一级二级三级| 毛片av中文字幕一区二区| 国产精品素人视频| 一区二区三区欧美激情| 欧美成人久久| 久久久成人网| 国产欧美精品在线观看| 中文日韩电影网站| 欧美激情bt| 久久国产99| 国产亚洲观看| 亚洲免费在线播放| 亚洲免费观看| 欧美日韩成人| 亚洲乱码国产乱码精品精可以看 | 一区二区三区中文在线观看| 亚洲天堂网在线观看| 欧美成人资源| 久久综合狠狠综合久久综青草| 国产一区二区三区免费在线观看 | 久久av资源网站| 一区二区三区 在线观看视频| 欧美电影在线观看完整版| 好吊妞**欧美| 卡通动漫国产精品| 久久精品视频导航| 激情综合色丁香一区二区| 久久久久高清| 久久亚洲精品欧美| 在线视频观看日韩| 亚洲国产高清aⅴ视频| 卡通动漫国产精品| 在线观看三级视频欧美| 免费观看亚洲视频大全| 久久琪琪电影院| 亚洲黄网站在线观看| 亚洲国内精品| 国产精品国产成人国产三级| 欧美一级理论片| 久久久久九九视频| 亚洲国产视频一区| 亚洲美女电影在线| 国产精品网站在线| 久久久久久久欧美精品| 久久久久久久综合狠狠综合| 亚洲第一精品久久忘忧草社区| 免费看的黄色欧美网站| 欧美激情欧美激情在线五月| 国产精品日韩在线| 亚洲国产美女| 蜜桃视频一区| 99re6这里只有精品| 一本久道久久综合婷婷鲸鱼| 国产精品福利片| 久久久精品一区| 欧美风情在线| 欧美亚洲免费在线| 久久久久久噜噜噜久久久精品| 亚洲福利在线观看| 一区二区av| 一区在线视频| 亚洲精品久久久久中文字幕欢迎你| 国产精品theporn| 美腿丝袜亚洲色图| 欧美午夜三级| 美女图片一区二区| 欧美色视频日本高清在线观看| 久久九九全国免费精品观看| 欧美成年人网| 久久久久久97三级| 欧美日韩一卡二卡| 看片网站欧美日韩| 欧美亚韩一区| 亚洲福利精品| 狠狠色伊人亚洲综合网站色| 一本大道久久a久久综合婷婷| 136国产福利精品导航网址| 99国产欧美久久久精品| 亚洲国产精品一区二区www| 亚洲一区国产视频| 日韩视频免费观看| 久久成人免费| 午夜欧美大片免费观看| 免费日韩成人| 久久人人97超碰人人澡爱香蕉| 欧美激情在线播放| 美女露胸一区二区三区| 国产欧美精品| 亚洲一区二区在| 一本在线高清不卡dvd| 久久综合色播五月| 久久亚洲精品一区| 国产亚洲精品bv在线观看| 在线一区二区三区四区| 一区二区国产精品| 欧美成人激情视频| 欧美成人嫩草网站| 狠狠色狠色综合曰曰| 欧美有码视频| 久久久久久久91| 国产一级精品aaaaa看| 欧美一级电影久久| 久久精品国产69国产精品亚洲 | 亚洲精品在线免费观看视频| 亚洲欧洲日本国产| 欧美国产在线观看| 亚洲日本电影| 亚洲视频一区二区在线观看| 欧美日本亚洲| 日韩视频免费观看| 亚洲欧美日本伦理| 国产区日韩欧美| 亚洲国产美女| 久久影院午夜论| 欧美成人资源| 亚洲六月丁香色婷婷综合久久| 久久综合影音| 最新精品在线| 亚洲一区二区在线观看视频| 欧美视频日韩| 欧美一级欧美一级在线播放| 久久久综合精品| 亚洲国产精品一区二区尤物区| 欧美成黄导航| 一区二区三区 在线观看视频| 午夜欧美理论片| 韩国一区电影| 欧美日韩第一区| 亚洲欧美国产不卡| 欧美成人免费va影院高清| 一本一本久久| 狠狠色狠狠色综合日日小说| 欧美大片在线观看| 亚洲色图在线视频| 麻豆精品视频在线观看| 在线中文字幕一区| 国内偷自视频区视频综合| 欧美成人中文字幕| 亚洲综合激情| 亚洲国产日韩欧美在线图片| 亚洲欧美日韩成人| 在线观看91久久久久久| 欧美视频一区在线| 久久综合综合久久综合| 亚洲在线视频网站| 亚洲激情视频在线播放| 欧美一区二区视频观看视频| 亚洲人体1000| 国产综合香蕉五月婷在线| 欧美日韩国产精品一区| 久久av二区| 亚洲一区二区三区涩| 亚洲国产婷婷香蕉久久久久久| 久久精品30| 亚洲欧美大片| 日韩视频免费观看高清完整版| 国语自产精品视频在线看抢先版结局| 欧美日韩国产va另类| 久久精品视频在线播放| 一区二区三区免费在线观看| 亚洲国产福利在线| 奶水喷射视频一区| 久久精品亚洲热| 欧美一级免费视频| 亚洲午夜激情网页| 日韩午夜免费视频| 亚洲国产国产亚洲一二三| 国产精品免费在线| 欧美香蕉视频|