日期:2014-05-19  浏览次数:20716 次

关于C#调用API
关于课程需要而用到API的函数,但是我找了一天都不知道应该从哪里入手API,网上都找不到比较入门的教程。希望大家指点一下,哪里有C#调用API的教程,如果在msdn有,可的话,指个路径给我看看。感激不尽!

------解决方案--------------------
可以参考.net基类对api的调用,在System.Windows.Forms.NativeMethods和System.Windows.Forms.UnsafeNativeMethods类中
------解决方案--------------------
http://msdn2.microsoft.com/zh-cn/library/ksk40b62(VS.80).aspx
------解决方案--------------------
给你看个我在网上下载的例子,我也想找这方面的东西,可是不多
这个函数能发出系统缺省的警告声.

using System.Runtime.InteropServices;
[DllImport( "user32.dll ")]
public static extern int MessageBeep(uint n);

private void button1_Click(object sender, System.EventArgs e)
{

MessageBeep(0xFFFFFFFF);
}




----===============================================

using System;
using System.Runtime.InteropServices;

namespace PlaySound
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class Class1
{
//导入 Windows Beep() API 函数
[DllImport( "kernel32.dll ")]
private static extern bool Beep(int freq, int dur);

// 定义PlaySound()要使用的常数
public const int SND_FILENAME = 0x00020000;
public const int SND_ASYNC = 0x0001;

// 导入 Windows PlaySound() 函数
[DllImport( "winmm.dll ")]
public static extern bool PlaySound(string pszSound,
int hmod,
int fdwSound);

[STAThread]
static void Main(string[] args)
{
// 使用Ctrl+g发出蜂鸣声
Console.Write( "\a ");
Console.WriteLine( "使用Ctrl+g发出蜂鸣声... ");
Console.ReadLine();

// 使用 Windows API 发出蜂鸣声
Beep(800, 200);
Console.WriteLine( "使用 Windows API 发出蜂鸣声... ");
Console.ReadLine();

// 播放bells.wav文件
PlaySound( "bells.wav ",
0,
SND_FILENAME | SND_ASYNC);
Console.WriteLine( "播放bells.wav文件... ");
Console.ReadLine();
}
}
}