C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » C# Syntax »

Using winAPI in .NET Program


Posted Date: 30 Oct 2009    Resource Type: Code Snippets    Category: C# Syntax
Author: krishnavenikaladiMember Level: Gold    
Rating: 1 out of 5Points: 5 (Rs 3)



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.



Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Static extern  .  Pinvoke  .  Message box  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Changing Dynamically allocate Title, Meta Keywords and Meta description in to a Page
Previous Resource: Using class libraries in C#
Return to Discussion Resource Index
Post New Resource
Category: C# Syntax


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use