use PINVOKE to use win api in .net program. this uses similar technology as com Interop.but it is used to access static dll entry points instead of com objects.here is an example of c# calling win32 messagebox function
name spaces to be used are: using System; using System.Runtime.InteropServices;
using System; using System.Runtime.InteropServices; //defining class class mainapp {
//accessing static dll entry point [DllImport ("user32.dll",EntryPoint="MessageBox",SetLastError=true,CharSet=CharSet.Auto)] //mehod which is used to call message box method //note:must use static extern public static extern int MessageBox(int hWnd,String strMessage,String strCaption,uint uiType); //strarting point of c# application public static void Main() { //passing message to mesagebox MessageBox(0,"hello ,this is PInvoke in operation!","NET",0); } }
Explanation:
-->Inorder to access windows api we must usePinvoke. -->using dllimport we must import static dll with entry point --->using atatic extern we r in a position to acces the methods in win API -->we can use those methos in .net programs.
|
No responses found. Be the first to respond and make money from revenue sharing program.
|