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

為生存而奔跑

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

留言簿(5)

我參與的團隊

搜索

  •  

積分與排名

  • 積分 - 331736
  • 排名 - 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>
            日韩亚洲不卡在线| 国产麻豆精品theporn| 欧美电影在线| 亚洲第一网站| 久久综合中文色婷婷| 久久久999| 久久全球大尺度高清视频| 蜜臀av在线播放一区二区三区| 在线综合亚洲欧美在线视频| aa日韩免费精品视频一| 亚洲视频狠狠| 久久久久久九九九九| 亚洲精品乱码久久久久久| 国产在线观看91精品一区| 国产一区av在线| 99精品国产热久久91蜜凸| 一本不卡影院| 久久久精品国产一区二区三区| 欧美激情精品| 国产日韩欧美中文在线播放| 欧美 日韩 国产在线| 欧美女同视频| 亚洲国产综合在线| 久久久久久日产精品| 久久久精品一品道一区| 欧美高清在线一区二区| 欧美性淫爽ww久久久久无| 亚洲免费激情| 一区二区三区蜜桃网| 久久激五月天综合精品| 一区二区91| 欧美日韩一区在线| 日韩一级成人av| 欧美激情亚洲自拍| 久久色中文字幕| 国产一区二区视频在线观看| 欧美一区二区三区在线| 午夜精品影院| 国产在线观看一区| 美日韩免费视频| 久久亚洲一区| 午夜在线a亚洲v天堂网2018| 欧美色一级片| 欧美亚洲尤物久久| 久久久久久久激情视频| 亚洲三级视频| 亚洲午夜精品| 亚洲国产精品va在线看黑人 | 亚洲国产婷婷香蕉久久久久久| 欧美一区二区三区四区在线观看 | 狂野欧美性猛交xxxx巴西| 国产美女精品| 欧美成人一区二区在线| 欧美黄色免费| 羞羞漫画18久久大片| 久久综合九色综合欧美狠狠| 中日韩午夜理伦电影免费| 久久手机免费观看| 亚洲精品乱码久久久久久按摩观| 一本久道久久综合狠狠爱| 国内揄拍国内精品少妇国语| 亚洲国产一区二区精品专区| 国产精品一区二区三区免费观看| 欧美顶级艳妇交换群宴| 国内自拍亚洲| 午夜亚洲视频| 亚洲一区在线直播| 国产精品日日摸夜夜添夜夜av | 美女主播精品视频一二三四| 国产精品亚洲综合一区在线观看| 亚洲黄色三级| 亚洲人成网站在线观看播放| 欧美一区二区观看视频| 欧美一区三区二区在线观看| 国产精品久久久爽爽爽麻豆色哟哟| 久热爱精品视频线路一| 黑人一区二区| 鲁鲁狠狠狠7777一区二区| 久久视频国产精品免费视频在线| 欧美电影在线观看| 狠狠色丁香婷婷综合影院| 久久av在线| 亚洲黄网站在线观看| 亚洲精品久久久久久久久久久久| 欧美va天堂| 一区二区三区成人精品| 欧美在线视频观看| 亚洲电影免费在线观看| 欧美成人综合| 亚洲欧美福利一区二区| 亚洲高清免费| 亚洲综合精品自拍| 亚洲黄色天堂| 国产精品久久久久毛片软件| 午夜视频一区在线观看| 最新中文字幕一区二区三区| 香蕉乱码成人久久天堂爱免费| 国产一区二区三区久久| 欧美大片在线看| 性欧美暴力猛交69hd| 亚洲激情成人在线| 久久久国产精品一区二区三区| 亚洲风情亚aⅴ在线发布| 国产精品视频1区| 午夜精品一区二区在线观看| 亚洲国产精品999| 国产欧美日韩亚州综合| 欧美日韩综合视频| 国内精品久久久久影院优| 欧美综合77777色婷婷| 怡红院精品视频| 日韩视频在线观看免费| 校园春色综合网| 亚洲精选中文字幕| 美女视频网站黄色亚洲| 久久精品人人| 噜噜爱69成人精品| 亚洲精品美女在线观看| 亚洲东热激情| 亚洲黄色视屏| 在线综合亚洲欧美在线视频| 亚洲乱码久久| 亚洲视频一二区| 亚洲免费在线观看视频| 欧美在线观看视频在线| 久久这里有精品视频| 欧美中文字幕第一页| 久久xxxx精品视频| 欧美激情在线观看| 亚洲欧美国产va在线影院| 开心色5月久久精品| 欧美色网一区二区| 狠狠久久亚洲欧美| 亚洲一区精彩视频| 女女同性精品视频| 中文欧美在线视频| 蜜乳av另类精品一区二区| 国产精品视频免费观看| 在线综合亚洲| 亚洲精品久久久久久久久久久久久 | 国产欧美精品久久| 一区二区在线视频观看| 性伦欧美刺激片在线观看| 一区二区三区久久网| 欧美日韩一二三四五区| 一区二区av在线| 亚洲另类在线一区| 欧美伦理视频网站| 夜夜夜久久久| 中文成人激情娱乐网| 欧美日本成人| 午夜一级在线看亚洲| 久久精品国产77777蜜臀| 狠狠色狠狠色综合日日tαg| 国产精品久久久久久久久久久久| 欧美在线影院在线视频| 一区二区三区 在线观看视频| 国产精品欧美日韩| 久久超碰97中文字幕| 免费观看久久久4p| 亚洲欧美日韩国产中文| 亚洲欧美一区在线| 在线日韩精品视频| 亚洲区欧美区| 国产精品成av人在线视午夜片| 一本大道久久a久久综合婷婷| 日韩视频精品| 好吊成人免视频| 亚洲精品欧美专区| 黄色成人在线网站| 亚洲中无吗在线| 午夜激情亚洲| 欧美日韩免费网站| 欧美r片在线| 国产一区二区三区无遮挡| 亚洲自啪免费| 久久最新视频| 亚洲精品日韩激情在线电影| 欧美精品尤物在线| 亚洲一级一区| 欧美高清视频一区二区三区在线观看| 狠狠色丁香久久婷婷综合_中| 欧美成人精品影院| 日韩午夜在线观看视频| 欧美精品在线一区| 久久久爽爽爽美女图片| 国产精品一区一区| 亚洲免费婷婷| 亚洲一区二区三区高清 | 国产精品区二区三区日本| 欧美主播一区二区三区美女 久久精品人| 新67194成人永久网站| 最新日韩在线| 欧美freesex8一10精品| 亚洲欧美三级在线| 国产精品va在线播放| 免费看亚洲片| 亚洲国产精品久久| 性欧美1819性猛交| 国产精品va在线播放我和闺蜜|