首页 > Windows开发 > 详细

C#调用windows api示例

时间:2016-02-23 18:43:46      阅读:303      评论:0      收藏:0      [点我收藏+]

这是运行结果:

技术分享

 

Api函数是构筑Windws应用程序的基石,每一种Windows应用程序开发工具,它提 
供的底层函数都间接或直接地调用了Windows API函数,同时为了实现功能扩 
展,一般也都提供了调用WindowsAPI函数的接口, 也就是说具备调用动态连接 
库的能力。Visual C#和其它开发工具一样也能够调用动态链接库的API函 
数。.NET框架本身提供了这样一种服务,允许受管辖的代码调用动态链接库中实 
现的非受管辖函数,包括操作系统提供的Windows API函数。它能够定位和调用输 
出函数,根据需要,组织其各个参数(整型、字符串类型、数组、和结构等等)跨 
越互操作边界。 

参考:http://hovertree.com/h/bjaf/tc63n4t2.htm

using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace HoverTreeWinForm
{
    public partial class FormHewenqi : Form
    {
        /// <summary>
        /// http://hovertree.com/h/bjaf/v4y0b2l6.htm
        /// </summary>
        /// <param name="h"></param>
        /// <param name="m"></param>
        /// <param name="c"></param>
        /// <param name="type"></param>
        /// <returns></returns>

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

        private void button_hewenqi_Click(object sender, EventArgs e)
        {
            MessageBox(0, "Hello Win32 API HoverTree", "何问起网", 4);
        }

        private void linkLabel_help_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            System.Diagnostics.Process.Start("http://hovertree.com/h/bjaf/v4y0b2l6.htm");
        }
    }
}

转载自:http://hovertree.com/h/bjaf/psjdasa2.htm

源码下载:http://pan.baidu.com/s/1bnPPgL5

http://roucheng.cnblogs.com/

C#调用windows api示例

原文:http://www.cnblogs.com/roucheng/p/csaip.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!