Use of API in .net

1. First You create class in which You declare appropriate  API funtions
For ex.

using System;


System.Runtime.InteropServices ;




public class APIFunctions


[DllImport("kernel32", CharSet=CharSet.Unicode)]

static extern bool GetComputerName(string name, ref int len);


static extern bool Beep(uint dwFreq, uint dwDuration);

[DllImport("User32.dll", ExactSpelling=true)]

private static extern bool MessageBeep(uint type);


public static extern long PlaySound(String lpszName, long hModule, long dwFlags);

public string API_ComputerName




String computerName="abcdefghijklmnopqrstuvwxyz";

int len = 100;

GetComputerName(computerName, ref len);

string a=computerName;

return (computerName.Substring(0,len));



public void API_BeepSound()




public void API_PlaySound()


long retval;

string fname = "d:\\tada.wav";

retval = PlaySound(fname, 0, 1);



2. You have to create Object of class and use in either in event or in function,

For ex.

APIFunctions Obj=new APIFunctions();

Obj.API_BeepSound ();











Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s